Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

gel_filt.H

Go to the documentation of this file.
00001 #ifndef __GEL_FILTER_H__
00002 #define __GEL_FILTER_H__
00003 
00004 #include "gel.H"
00005 
00006 /*****************************************************************
00007  * Virtual base class for accepting or rejecting a GEL based
00008  * on some condition.
00009  *****************************************************************/
00010 class GELFILT {
00011  public:
00012    //******** MANAGERS ********
00013    virtual ~GELFILT() {}
00014 
00015    //******** RUN-TIME TYPE ID ********
00016    // XXX -
00017    //   rarely handled in GELFILT derived types
00018    virtual STAT_STR_RET class_name () const { return static_name();}
00019    static  STAT_STR_RET static_name();
00020 
00021    //******** VIRTUAL METHOD ********
00022    // Returns true if the GEL is accepted
00023    virtual bool accept(CGELptr &gel) = 0; 
00024 };
00025 
00026 /*****************************************************************
00027  *  This rejects any GEL found in a specified list of GELs
00028  *****************************************************************/
00029 class GELFILTothers : public GELFILT {
00030  public:
00031    //******** MANAGERS ********
00032    GELFILTothers(CGELlist &gels) : _gels(gels) {}
00033    virtual ~GELFILTothers() {}
00034 
00035    //******** VIRTUAL METHOD ********
00036    virtual bool accept(CGELptr &gel) { return !_gels.contains(gel); }
00037 
00038  protected:
00039    CGELlist _gels;      // GELS to be rejected
00040 };
00041 
00042 /*****************************************************************
00043  * Accepts GELs from a given list of class names.
00044  *
00045  * NOTE:
00046  *    The GEL is only accepted if its exact class name
00047  *    appears in the list. To accept a GEL that is DERIVED
00048  *    from one of the named classes, use GELFILTclass_desc,
00049  *    below.
00050  *****************************************************************/
00051 class GELFILTclass_name : public GELFILT {
00052  public:
00053    //******** MANAGERS ********
00054    GELFILTclass_name(Cstr_ptr  &cn  ) { _cn.add(cn); }
00055    GELFILTclass_name(Cstr_list &list) : _cn(list) { }
00056 
00057    void add(Cstr_ptr &cn)            { _cn.add(cn); }
00058 
00059    //******** VIRTUAL METHOD ********
00060    virtual bool  accept(CGELptr &g) { return _cn.contains(g->class_name()); }
00061 
00062  protected:
00063    str_list _cn;        // acceptable class names
00064 };
00065 
00066 /*****************************************************************
00067  * Similar to GELFIILTclass_name, but also accepts a GEL that
00068  * is DERIVED from any class named in the list.
00069  *****************************************************************/
00070 class GELFILTclass_desc : public GELFILTclass_name {
00071  public:
00072    //******** MANAGERS ********
00073    GELFILTclass_desc(Cstr_ptr& cn)    : GELFILTclass_name(cn)  {}
00074    GELFILTclass_desc(Cstr_list& list) : GELFILTclass_name(list){}
00075 
00076    //******** VIRTUAL METHOD ********
00077    virtual bool accept(CGELptr &g) {
00078       for (int i=0; i<_cn.num(); i++)
00079          if (g->is_of_type(_cn[i]))
00080             return 1;
00081       return 0;
00082    }
00083 };
00084 
00085 /*****************************************************************
00086  * Opposite of GELFILTclass:
00087  *   Rejects any GEL whose exact class name is in a given list.
00088  *****************************************************************/
00089 class GELFILTclass_name_excl : public GELFILTclass_name {
00090  public:
00091    //******** MANAGERS ********
00092    GELFILTclass_name_excl(Cstr_ptr  &cn)   : GELFILTclass_name(cn)   {}
00093    GELFILTclass_name_excl(Cstr_list &list) : GELFILTclass_name(list) {}
00094 
00095    //******** VIRTUAL METHOD ********
00096    virtual bool accept(CGELptr &g) { return !GELFILTclass_name::accept(g); }
00097 };
00098 
00099 /*****************************************************************
00100  * Opposite of GELFILTclass_desc:
00101  *    Rejects any GEL that derives from a given set of classes.
00102  *****************************************************************/
00103 class GELFILTclass_desc_excl : public GELFILTclass_desc {
00104  public:
00105    //******** MANAGERS ********
00106    GELFILTclass_desc_excl(Cstr_ptr  &cn  ) : GELFILTclass_desc(cn)  {}
00107    GELFILTclass_desc_excl(Cstr_list &list) : GELFILTclass_desc(list){}
00108 
00109    //******** VIRTUAL METHOD ********
00110    virtual bool accept(CGELptr &g) { return !GELFILTclass_desc::accept(g); }
00111 };
00112 
00113 /*****************************************************************
00114  *  This rejects GELS that aren't pickable
00115  *****************************************************************/
00116 class GELFILTpickable : public GELFILT {
00117  public:
00118    //******** MANAGERS ********
00119    GELFILTpickable(bool pick_all) : _all(pick_all) {}
00120 
00121    //******** RUN-TIME TYPE ID ********
00122    virtual STAT_STR_RET class_name () const { return static_name();}
00123    static  STAT_STR_RET static_name()       { RET_STAT_STR("GELFILTpickable");}
00124 
00125    //******** VIRTUAL METHOD ********
00126    virtual bool accept(CGELptr &g) { return _all ? 1 : PICKABLE.get(g) != 0; }
00127 
00128  protected:
00129    bool _all;  // whether all objects should be pickable 
00130 };
00131 
00132 /*****************************************************************
00133  * This will reject any GEL that has field's value set to
00134  * the given value
00135  *****************************************************************/
00136 template <class T>
00137 class GELFILTtdi : public GELFILT {
00138  public:
00139    //******** MANAGERS ********
00140    GELFILTtdi(hashvar<T> &field, T val) : _field(field), _val(val) {}
00141 
00142    //******** VIRTUAL METHOD ********
00143    virtual bool accept(CGELptr &g) { return _field.get(g) != _val; }
00144 
00145  protected:
00146    hashvar<T> &_field;
00147    T           _val;
00148 };
00149 
00150 extern hashvar<int> WIDGET_3D;
00151 /*****************************************************************
00152  * This rejects all GELs tagged as WIDGET_3Ds
00153  *****************************************************************/
00154 class GELFILTwidget3d : public GELFILTtdi<int> {
00155  public:
00156    //******** MANAGERS ********
00157    GELFILTwidget3d() : GELFILTtdi<int>(WIDGET_3D, 1) {}
00158 };
00159 
00160 /*****************************************************************
00161  * A list of filters.  The GEL must be accepted by all filters
00162  *****************************************************************/
00163 class GELFILTlist : public GELFILT, public ARRAY<GELFILT*> {
00164  public:
00165    //******** MANAGERS ********
00166    GELFILTlist(int num=16)           : ARRAY<GELFILT *>(num) {}
00167    GELFILTlist(const GELFILTlist &l) : ARRAY<GELFILT *>(l)   {}
00168    GELFILTlist(GELFILT *filt) { *this += filt;}
00169 
00170    //******** VIRTUAL METHOD ********
00171    virtual bool accept(CGELptr &gel) {
00172       for (int i=0; i<_num; i++)
00173          if (!_array[i]->accept(gel))
00174             return 0;
00175       return true;
00176    }
00177 };
00178 
00179 #endif // __GEL_FILTER_H__
00180 
00181 /* end of file gel_filt.H */

Generated on Mon Sep 18 11:39:29 2006 for jot by  doxygen 1.4.4