CLHEP VERSION Reference Documentation
CLHEP Home Page CLHEP Documentation CLHEP Bug Reports |
00001 // -*- C++ -*- 00002 // $Id: CutBase.hh,v 1.2 2003/09/06 14:04:13 boudreau Exp $ 00003 // --------------------CutBase--------------------------------// 00004 // // 00005 // CutBase, by Joe Boudreau // 00006 // // 00007 // // 00008 // CutBase: set of classes for doing boolean operations on // 00009 // cuts. These classes function a little like STL // 00010 // predicates, but they extend functionality by permitting // 00011 // Boolean operations. They are sitting here in Generic // 00012 // Functions package because they are quite similar to the // 00013 // generic functions, except that instead of obeying a // 00014 // Function algebra, these objects obey a Boolean algebra. // 00015 // // 00016 // IF YOU INHERIT YOUR PREDICATE FROM Cut<Type>, you will // 00017 // for free get all the boolean operations on the predicate. // 00018 // Here is an example where the type is an integer: // 00019 // // 00020 // // 00021 // class IsPrime:public Cut<int> { // 00022 // // Implies you will implement operator () (int) const, // 00023 // // And clone() const // 00024 // } // 00025 // // 00026 // class IsInRange:public Cut<int> { // 00027 // // Implies you will implement operator () (int) const, // 00028 // // And clone() const // 00029 // } // 00030 // // 00031 // // 00032 // Then the following example should work, note the use of // 00033 // Boolean operations: // 00034 // // 00035 // const int N=100; // 00036 // int array[N]; // 00037 // for (int i=0;i<N;i++) array[i]=i; // 00038 // std::ostream_iterator<int> dest(std::cout,"\n"); // 00039 // // 00040 // const Cut<int>::Predicate cut = IsPrime() && IsInRange(3,9); 00041 // std::remove_copy_if(array, array+N, dest, !cut); // 00042 // // 00043 // // 00044 // // 00045 // // 00046 // -----------------------------------------------------------// 00047 00048 #ifndef _CutBase_h_ 00049 #define _CutBase_h_ 00050 00051 #include <functional> 00052 00057 template<class Type> 00058 class Cut { 00059 public: 00060 00061 //-----------Boolean operations-----------------------------// 00062 // // 00063 //...For OR'ing the cuts. // 00064 // // 00065 class OR; // 00066 OR operator ||( const Cut<Type> & A ) const; // 00067 // // 00068 //...For AND'ing the cuts. // 00069 // // 00070 class AND; // 00071 AND operator &&( const Cut<Type> & A ) const; // 00072 // // 00073 //...For negating the cuts: // 00074 // // 00075 class NOT; // 00076 NOT operator ! ( void ) const; // 00077 // // 00078 //----------------------------------------------------------// 00079 00080 //-----------Constructors & cetera--------------------------// 00081 Cut(); // 00082 Cut(const Cut & right); // 00083 virtual ~Cut(); // 00084 virtual Cut * clone() const = 0; // 00085 //----------------------------------------------------------// 00086 00087 //-----------Concrete class holding any cut:----------------// 00088 // // 00089 class Predicate; // 00090 // // 00091 //----------------------------------------------------------// 00092 00093 //----------------------------------------------------------// 00094 // Evaluate predicate // 00095 // // 00096 virtual bool operator ()( const Type & t ) const = 0; // 00097 // // 00098 //----------------------------------------------------------// 00099 00100 }; 00101 00102 //-------------------------------------------------------------------------- 00103 // Common standard Cut classes 00104 //-------------------------------------------------------------------------- 00105 template<class Type> 00106 class Cut<Type>::AND : public Cut<Type> { 00107 00108 public: 00109 AND( const AND & right ); 00110 AND( const Cut & A, const Cut & B ); 00111 virtual ~AND(); 00112 virtual AND * clone( void ) const; 00113 virtual bool operator ()( const Type & t ) const; 00114 private: 00115 const AND & operator=( const AND & right ); 00116 Cut * _pA; 00117 Cut * _pB; 00118 }; 00119 00120 template<class Type> 00121 class Cut<Type>::OR : public Cut<Type> 00122 { 00123 public: 00124 OR( const OR & right ); 00125 OR( const Cut & A, const Cut & B ); 00126 virtual ~OR(); 00127 virtual OR * clone( void ) const; 00128 virtual bool operator ()( const Type & t ) const; 00129 private: 00130 const OR & operator=( const OR & right ); 00131 Cut * _pA; 00132 Cut * _pB; 00133 }; 00134 00135 template<class Type> 00136 class Cut<Type>::NOT : public Cut<Type> 00137 { 00138 public: 00139 NOT( const NOT & right ); 00140 NOT( const Cut & A ); 00141 virtual ~NOT(); 00142 virtual NOT * clone( void ) const; 00143 virtual bool operator ()( const Type & t ) const; 00144 private: 00145 const NOT & operator=( const NOT & right ); 00146 Cut * _pA ; 00147 }; 00148 00149 00150 template<class Type> 00151 class Cut<Type>::Predicate : public Cut<Type> 00152 { 00153 public: 00154 Predicate( const Predicate & right ); 00155 Predicate( const Cut & A ); 00156 virtual ~Predicate(); 00157 virtual Predicate * clone( void ) const; 00158 virtual bool operator ()( const Type & t ) const; 00159 private: 00160 const Predicate & operator=( const Predicate & right ); 00161 Cut * _pA ; 00162 }; 00163 00164 00165 #include "CLHEP/GenericFunctions/CutBase.icc" 00166 00167 #endif