|
||||
File indexing completed on 2025-01-18 09:54:34
0001 // -*- C++ -*- 0002 // $Id: CutBase.hh,v 1.2 2003/09/06 14:04:13 boudreau Exp $ 0003 // --------------------CutBase--------------------------------// 0004 // // 0005 // CutBase, by Joe Boudreau // 0006 // // 0007 // // 0008 // CutBase: set of classes for doing boolean operations on // 0009 // cuts. These classes function a little like STL // 0010 // predicates, but they extend functionality by permitting // 0011 // Boolean operations. They are sitting here in Generic // 0012 // Functions package because they are quite similar to the // 0013 // generic functions, except that instead of obeying a // 0014 // Function algebra, these objects obey a Boolean algebra. // 0015 // // 0016 // IF YOU INHERIT YOUR PREDICATE FROM Cut<Type>, you will // 0017 // for free get all the boolean operations on the predicate. // 0018 // Here is an example where the type is an integer: // 0019 // // 0020 // // 0021 // class IsPrime:public Cut<int> { // 0022 // // Implies you will implement operator () (int) const, // 0023 // // And clone() const // 0024 // } // 0025 // // 0026 // class IsInRange:public Cut<int> { // 0027 // // Implies you will implement operator () (int) const, // 0028 // // And clone() const // 0029 // } // 0030 // // 0031 // // 0032 // Then the following example should work, note the use of // 0033 // Boolean operations: // 0034 // // 0035 // const int N=100; // 0036 // int array[N]; // 0037 // for (int i=0;i<N;i++) array[i]=i; // 0038 // std::ostream_iterator<int> dest(std::cout,"\n"); // 0039 // // 0040 // const Cut<int>::Predicate cut = IsPrime() && IsInRange(3,9); 0041 // std::remove_copy_if(array, array+N, dest, !cut); // 0042 // // 0043 // // 0044 // // 0045 // // 0046 // -----------------------------------------------------------// 0047 0048 #ifndef _CutBase_h_ 0049 #define _CutBase_h_ 0050 0051 #include <functional> 0052 0053 /** 0054 * @author 0055 * @ingroup genfun 0056 */ 0057 template<class Type> 0058 class Cut { 0059 public: 0060 0061 //-----------Boolean operations-----------------------------// 0062 // // 0063 //...For OR'ing the cuts. // 0064 // // 0065 class OR; // 0066 OR operator ||( const Cut<Type> & A ) const; // 0067 // // 0068 //...For AND'ing the cuts. // 0069 // // 0070 class AND; // 0071 AND operator &&( const Cut<Type> & A ) const; // 0072 // // 0073 //...For negating the cuts: // 0074 // // 0075 class NOT; // 0076 NOT operator ! ( void ) const; // 0077 // // 0078 //----------------------------------------------------------// 0079 0080 //-----------Constructors & cetera--------------------------// 0081 Cut(); // 0082 Cut(const Cut & right); // 0083 virtual ~Cut(); // 0084 virtual Cut * clone() const = 0; // 0085 //----------------------------------------------------------// 0086 0087 //-----------Concrete class holding any cut:----------------// 0088 // // 0089 class Predicate; // 0090 // // 0091 //----------------------------------------------------------// 0092 0093 //----------------------------------------------------------// 0094 // Evaluate predicate // 0095 // // 0096 virtual bool operator ()( const Type & t ) const = 0; // 0097 // // 0098 //----------------------------------------------------------// 0099 0100 }; 0101 0102 //-------------------------------------------------------------------------- 0103 // Common standard Cut classes 0104 //-------------------------------------------------------------------------- 0105 template<class Type> 0106 class Cut<Type>::AND : public Cut<Type> { 0107 0108 public: 0109 AND( const AND & right ); 0110 AND( const Cut & A, const Cut & B ); 0111 virtual ~AND(); 0112 virtual AND * clone( void ) const; 0113 virtual bool operator ()( const Type & t ) const; 0114 private: 0115 const AND & operator=( const AND & right ); 0116 Cut * _pA; 0117 Cut * _pB; 0118 }; 0119 0120 template<class Type> 0121 class Cut<Type>::OR : public Cut<Type> 0122 { 0123 public: 0124 OR( const OR & right ); 0125 OR( const Cut & A, const Cut & B ); 0126 virtual ~OR(); 0127 virtual OR * clone( void ) const; 0128 virtual bool operator ()( const Type & t ) const; 0129 private: 0130 const OR & operator=( const OR & right ); 0131 Cut * _pA; 0132 Cut * _pB; 0133 }; 0134 0135 template<class Type> 0136 class Cut<Type>::NOT : public Cut<Type> 0137 { 0138 public: 0139 NOT( const NOT & right ); 0140 NOT( const Cut & A ); 0141 virtual ~NOT(); 0142 virtual NOT * clone( void ) const; 0143 virtual bool operator ()( const Type & t ) const; 0144 private: 0145 const NOT & operator=( const NOT & right ); 0146 Cut * _pA ; 0147 }; 0148 0149 0150 template<class Type> 0151 class Cut<Type>::Predicate : public Cut<Type> 0152 { 0153 public: 0154 Predicate( const Predicate & right ); 0155 Predicate( const Cut & A ); 0156 virtual ~Predicate(); 0157 virtual Predicate * clone( void ) const; 0158 virtual bool operator ()( const Type & t ) const; 0159 private: 0160 const Predicate & operator=( const Predicate & right ); 0161 Cut * _pA ; 0162 }; 0163 0164 0165 #include "CLHEP/GenericFunctions/CutBase.icc" 0166 0167 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |