CLHEP 2.4.6.4
C++ Class Library for High Energy Physics
Loading...
Searching...
No Matches
CutBase.hh
Go to the documentation of this file.
1// -*- C++ -*-
2// $Id: CutBase.hh,v 1.2 2003/09/06 14:04:13 boudreau Exp $
3// --------------------CutBase--------------------------------//
4// //
5// CutBase, by Joe Boudreau //
6// //
7// //
8// CutBase: set of classes for doing boolean operations on //
9// cuts. These classes function a little like STL //
10// predicates, but they extend functionality by permitting //
11// Boolean operations. They are sitting here in Generic //
12// Functions package because they are quite similar to the //
13// generic functions, except that instead of obeying a //
14// Function algebra, these objects obey a Boolean algebra. //
15// //
16// IF YOU INHERIT YOUR PREDICATE FROM Cut<Type>, you will //
17// for free get all the boolean operations on the predicate. //
18// Here is an example where the type is an integer: //
19// //
20// //
21// class IsPrime:public Cut<int> { //
22// // Implies you will implement operator () (int) const, //
23// // And clone() const //
24// } //
25// //
26// class IsInRange:public Cut<int> { //
27// // Implies you will implement operator () (int) const, //
28// // And clone() const //
29// } //
30// //
31// //
32// Then the following example should work, note the use of //
33// Boolean operations: //
34// //
35// const int N=100; //
36// int array[N]; //
37// for (int i=0;i<N;i++) array[i]=i; //
38// std::ostream_iterator<int> dest(std::cout,"\n"); //
39// //
40// const Cut<int>::Predicate cut = IsPrime() && IsInRange(3,9);
41// std::remove_copy_if(array, array+N, dest, !cut); //
42// //
43// //
44// //
45// //
46// -----------------------------------------------------------//
47
48#ifndef _CutBase_h_
49#define _CutBase_h_
50
51#include <functional>
52
53/**
54 * @author
55 * @ingroup genfun
56 */
57template<class Type>
58class Cut {
59public:
60
61 //-----------Boolean operations-----------------------------//
62 // //
63 //...For OR'ing the cuts. //
64 // //
65 class OR; //
66 OR operator ||( const Cut<Type> & A ) const; //
67 // //
68 //...For AND'ing the cuts. //
69 // //
70 class AND; //
71 AND operator &&( const Cut<Type> & A ) const; //
72 // //
73 //...For negating the cuts: //
74 // //
75 class NOT; //
76 NOT operator ! ( void ) const; //
77 // //
78 //----------------------------------------------------------//
79
80 //-----------Constructors & cetera--------------------------//
81 Cut(); //
82 Cut(const Cut & right); //
83 virtual ~Cut(); //
84 virtual Cut * clone() const = 0; //
85 //----------------------------------------------------------//
86
87 //-----------Concrete class holding any cut:----------------//
88 // //
89 class Predicate; //
90 // //
91 //----------------------------------------------------------//
92
93 //----------------------------------------------------------//
94 // Evaluate predicate //
95 // //
96 virtual bool operator ()( const Type & t ) const = 0; //
97 // //
98 //----------------------------------------------------------//
99
100};
101
102//--------------------------------------------------------------------------
103// Common standard Cut classes
104//--------------------------------------------------------------------------
105template<class Type>
106class Cut<Type>::AND : public Cut<Type> {
107
108public:
109 AND( const AND & right );
110 AND( const Cut & A, const Cut & B );
111 virtual ~AND();
112 virtual AND * clone( void ) const;
113 virtual bool operator ()( const Type & t ) const;
114private:
115 const AND & operator=( const AND & right );
116 Cut * _pA;
117 Cut * _pB;
118};
119
120template<class Type>
121class Cut<Type>::OR : public Cut<Type>
122{
123public:
124 OR( const OR & right );
125 OR( const Cut & A, const Cut & B );
126 virtual ~OR();
127 virtual OR * clone( void ) const;
128 virtual bool operator ()( const Type & t ) const;
129private:
130 const OR & operator=( const OR & right );
131 Cut * _pA;
132 Cut * _pB;
133};
134
135template<class Type>
136class Cut<Type>::NOT : public Cut<Type>
137{
138public:
139 NOT( const NOT & right );
140 NOT( const Cut & A );
141 virtual ~NOT();
142 virtual NOT * clone( void ) const;
143 virtual bool operator ()( const Type & t ) const;
144private:
145 const NOT & operator=( const NOT & right );
146 Cut * _pA ;
147};
148
149
150template<class Type>
151class Cut<Type>::Predicate : public Cut<Type>
152{
153public:
154 Predicate( const Predicate & right );
155 Predicate( const Cut & A );
156 virtual ~Predicate();
157 virtual Predicate * clone( void ) const;
158 virtual bool operator ()( const Type & t ) const;
159private:
160 const Predicate & operator=( const Predicate & right );
161 Cut * _pA ;
162};
163
164
165#include "CLHEP/GenericFunctions/CutBase.icc"
166
167#endif
virtual ~AND()
AND(const Cut &A, const Cut &B)
AND(const AND &right)
virtual AND * clone(void) const
virtual ~NOT()
virtual NOT * clone(void) const
NOT(const Cut &A)
NOT(const NOT &right)
virtual ~OR()
OR(const OR &right)
OR(const Cut &A, const Cut &B)
virtual OR * clone(void) const
Predicate(const Predicate &right)
virtual ~Predicate()
virtual Predicate * clone(void) const
Predicate(const Cut &A)
Definition: CutBase.hh:58
NOT operator!(void) const
virtual Cut * clone() const =0
Cut(const Cut &right)
AND operator&&(const Cut< Type > &A) const
OR operator||(const Cut< Type > &A) const
virtual bool operator()(const Type &t) const =0
virtual ~Cut()
Definition: excDblThrow.cc:8