Main Page | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members | Related Pages

BaseCut.h

Go to the documentation of this file.
00001 
00023 #ifndef __BASECUT_H
00024 #define __BASECUT_H
00025 
00026 #include "jbltools/sfh/BaseCutBase.h"
00027 #include "jbltools/sfh/FillIteratorPoR.h"    // needed for default argument 
00028 #include "jbltools/sfh/BaseCutPoR.h"         // needed for automagic conversion 
00029 #include "jbltools/sfh/ROListPoR.h"         // needed for automagic conversion 
00030 
00031 class IntFun;
00032 class FloatFun;
00033 
00034 // Class ConstBaseCut
00036 class ConstBaseCut : public BaseCut {
00037   public: 
00039     explicit ConstBaseCut (bool c_,                 
00040                            const char *name_ = 0    
00041                           )
00042       : BaseCut (name_ ? name_ : str(c_).c_str(), str(c_)), 
00043         c(c_) 
00044       {}
00046     explicit ConstBaseCut (bool c_,                 
00047                            const std::string& name_         
00048                       )
00049       : BaseCut (name_, str(c_)), 
00050         c(c_) 
00051       {}      
00053     virtual bool operator() () const { return c; };
00054   protected:
00055     const bool c;                   
00056 
00057     virtual ~ConstBaseCut() {}; 
00058 };
00059 
00060 <<<<<<< BaseCut.h
00061 // Class FloatBaseCut:
00062 //  Helper class to create a FloatFun out of a BaseCut
00063 class FloatBaseCut: public FloatFun {
00064   public:
00066     FloatBaseCut (const BaseCut& theBaseCut_   
00067                 );
00069     virtual float operator() () const { return theBaseCut();} 
00071     virtual const FillIterator *getIterator() const { 
00072       return theBaseCut.getIterator(); 
00073     }
00075     virtual const char *getName() const { return name; }
00076     
00077   protected:  
00079     virtual ~FloatBaseCut() {
00080       delete[] name;
00081       name = 0;
00082     }
00083     const BaseCut& theBaseCut;                
00084     char *name;
00085     
00086   private:
00088     FloatBaseCut (const FloatBaseCut& rhs);
00090     FloatBaseCut& operator= (const FloatBaseCut& rhs);
00091 };
00092 
00093 // Class IntBaseCut:
00094 //  Helper class to create a IntFun out of a BaseCut
00095 class IntBaseCut: public IntFun {
00096   public:
00098     IntBaseCut (const BaseCut& theBaseCut_   
00099                 );
00101     virtual int operator() () const { return theBaseCut();} 
00103     virtual const FillIterator *getIterator() const { 
00104       return theBaseCut.getIterator(); 
00105     }
00107     virtual const char *getName() const { return name; }
00108     
00109   protected:  
00111     virtual ~IntBaseCut() {
00112       delete[] name;
00113       name = 0;
00114     }
00115     const BaseCut& theBaseCut;                
00116     char *name;
00117     
00118   private:
00120     IntBaseCut (const IntBaseCut& rhs);
00122     IntBaseCut& operator= (const IntBaseCut& rhs);
00123 };
00124 
00125 //  Class TwoCutCompound:
00126 //  Helper class for binary logical operations between BaseCut objects
00127 /* 
00128  * This cut holds pointers to two other cuts.
00129  * The derived classes AndOfTwoCuts and OrOfTwoCuts implement
00130  * operator().
00131  */
00132 class TwoCutCompound : public BaseCut {
00133   public:
00135     TwoCutCompound (const BaseCut& lhs_,    
00136                     const BaseCut& rhs_,    
00137                     const char *format="TwoCutCompound(%s,%s)"
00138                     );
00139     
00140     virtual const FillIterator *getIterator() const;
00141     
00143     virtual const char *getName() const { return name; }
00144     
00145   protected:
00147     virtual ~TwoCutCompound() {
00148       delete[] name;
00149       name = 0;
00150     } 
00151     const BaseCut& lhs;                     
00152     const BaseCut& rhs;                     
00153     char *name;
00154     
00155   private:
00157     TwoCutCompound (const TwoCutCompound& rhs);
00159     TwoCutCompound& operator= (const TwoCutCompound& rhs);
00160 };
00161 
00162 //  Class AndOfTwoCuts:
00163 //  Helper class for the implementation of BaseCut && BaseCut
00164 /* 
00165  * Returns the AND of two cuts.
00166  * If the value of the first cut is false, the second cut is
00167  * not evaluated.
00168  */
00169 class AndOfTwoCuts : public TwoCutCompound {
00170   public:
00171     AndOfTwoCuts (const BaseCut& lhs_,    
00172                   const BaseCut& rhs_     
00173                   )
00174     : TwoCutCompound (lhs_, rhs_, "(%s)&&(%s)") {};
00176     virtual bool operator() () const {
00177       return lhs() && rhs();
00178     };
00179     
00180   protected:
00182     virtual ~AndOfTwoCuts() {}; 
00183 };
00184 
00185 //  Class OrOfTwoCuts:
00186 //  Helper class for the implementation of BaseCut || BaseCut
00187 /* 
00188  * Returns the OR of two cuts.
00189  * If the value of the first cut is true, the second cut is
00190  * not evaluated.
00191  */
00192 class OrOfTwoCuts : public TwoCutCompound {
00193   public:
00194     OrOfTwoCuts (const BaseCut& lhs_,    
00195                  const BaseCut& rhs_     
00196                  )
00197     : TwoCutCompound (lhs_, rhs_, "(%s)||(%s)") {};
00199     virtual bool operator() () const {
00200       return lhs() || rhs();
00201     }
00202   protected:
00204     virtual ~OrOfTwoCuts() {}; 
00205 };
00206 
00207 
00208 //  Class OneCutCompound:
00209 //  Helper class for unary logical operations on BaseCut objects
00210 /* 
00211  * This cut holds a pointer to one other cut.
00212  * The derived class NotOfACut implements operator().
00213  */ 
00214 class OneCutCompound : public BaseCut {
00215   public:
00216     OneCutCompound (const BaseCut& arg_, 
00217                     const char *format="OneCutCompound(%s)"
00218                    );
00219     
00220     virtual const FillIterator *getIterator() const {  
00221       return arg.getIterator(); 
00222     }
00223     
00225     virtual const char *getName() const { return name; }
00226     
00227   protected:
00229     virtual ~OneCutCompound() {
00230       delete[] name;
00231       name = 0;
00232     } 
00233 
00234     const BaseCut& arg;                  
00235     char *name;
00236     
00237   private:
00239     OneCutCompound (const OneCutCompound& rhs);
00241     OneCutCompound& operator= (const OneCutCompound& rhs);
00242 };
00243 
00244 //  Class NotOfACut:
00245 //  Helper class  for ! BaseCut
00246 /* 
00247  * Returns NOT of a cut.
00248  */
00249 class NotOfACut : public OneCutCompound {
00250   public:
00251     NotOfACut (const BaseCut& arg_        
00252               )
00253     : OneCutCompound (arg_, "!(%s)"){}
00255     virtual bool operator() () const {
00256       return !arg();
00257     }
00258   protected:
00260     virtual ~NotOfACut() {}; 
00261 };
00262 
00263 
00264 class CachedBaseCut: public BaseCut, public CachedO {
00265   public:
00267     CachedBaseCut (const ROListPoR& rol,  
00268                     const BaseCut&  arg_  
00269                    );
00270     
00272     virtual bool operator() () const;
00273     
00275     virtual void invalidateCache() { cacheValid = false; }
00276     
00278     virtual const char *getName() const { return name; }
00279     
00280   protected:
00282     virtual ~CachedBaseCut() {
00283       delete[] name;
00284       name = 0;
00285     }
00286     
00287     // Data members
00288     const   BaseCut& arg;         
00289     mutable bool cacheValid;       
00290     mutable bool cachedValue;     
00291     char *name;                              
00292     
00293   private:
00295     CachedBaseCut (const CachedBaseCut& rhs);
00297     CachedBaseCut& operator= (const CachedBaseCut& rhs);
00298 };
00299 
00300 class CachedBaseCutIt: public BaseCut, public CachedO {
00301   public:
00303     CachedBaseCutIt (const ROListPoR&     rol,  
00304                       const BaseCut&      arg_, 
00305                       const FillIterator&  iter_ 
00306                      );
00307     
00309     virtual bool operator() () const;
00310     
00312     virtual const FillIterator *getIterator() const { 
00313       return &iter; 
00314     }
00315     
00317     virtual void invalidateCache() {   
00318       cacheValid.resize(0);
00319       cachedValues.resize(0);
00320     }
00321     
00323     virtual const char *getName() const { return CachedBaseCutIt::name; }
00324     
00325   protected:
00327     void growCache (unsigned int s) const;
00328   
00330     virtual ~CachedBaseCutIt() {
00331       delete[] name;
00332       name = 0;
00333     }
00334     
00335     // Data members
00336     const   BaseCut& arg;                      
00337     const   FillIterator&  iter;                  
00338     mutable std::vector<bool>  cacheValid;      
00339     mutable std::vector<bool> cachedValues;    
00340     char *name;                              
00341     
00342   private:
00344     CachedBaseCutIt (const CachedBaseCutIt& rhs);
00346     CachedBaseCutIt& operator= (const CachedBaseCutIt& rhs);
00347 };
00348 
00349 
00350 =======
00351 >>>>>>> 1.16
00352 // External functions that implement logical operators between
00353 // BaseCut objects, so that we can write e.g. "cuta && (cutb || !cutc)"
00354 
00359 BaseCut& operator&& (const BaseCut& lhs_, const BaseCut& rhs_);
00360 
00365 BaseCut& operator|| (const BaseCut& lhs_, const BaseCut& rhs_);
00366 
00371 BaseCut& operator! (const BaseCut& rhs_);
00372 
00377 FloatFun& Float (const BaseCut& arg);
00378 
00383 IntFun& Int (const BaseCut& arg);
00384 
00389 BaseCut& cached (const ROListPoR&   rol,        
00390                   const BaseCutPoR& cut,        
00391                   const FillIteratorPoR& iter=0  
00392                  );
00393 
00394 
00395 #endif /* #ifndef __BASECUT_H */
00396 
00397 
00398 
00399 
00400 
00401 

Generated on Thu Oct 26 12:52:55 2006 for SFH by doxygen 1.3.2