CLHEP VERSION Reference Documentation
CLHEP Home Page
CLHEP Documentation
CLHEP Bug Reports
Main Page
Namespaces
Classes
Files
File List
File Members
GenericFunctions
GenericFunctions
GenericFunctions/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
57
template
<
class
Type>
58
class
Cut
{
59
public
:
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
//--------------------------------------------------------------------------
105
template
<
class
Type>
106
class
Cut
<Type>::
AND
:
public
Cut
<Type> {
107
108
public
:
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
;
114
private
:
115
const
AND
& operator=(
const
AND
& right );
116
Cut
* _pA;
117
Cut
* _pB;
118
};
119
120
template
<
class
Type>
121
class
Cut
<Type>::
OR
:
public
Cut
<Type>
122
{
123
public
:
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
;
129
private
:
130
const
OR
& operator=(
const
OR
& right );
131
Cut
* _pA;
132
Cut
* _pB;
133
};
134
135
template
<
class
Type>
136
class
Cut
<Type>::NOT :
public
Cut
<Type>
137
{
138
public
:
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
;
144
private
:
145
const
NOT & operator=(
const
NOT & right );
146
Cut
* _pA ;
147
};
148
149
150
template
<
class
Type>
151
class
Cut
<Type>::Predicate :
public
Cut
<Type>
152
{
153
public
:
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
;
159
private
:
160
const
Predicate & operator=(
const
Predicate & right );
161
Cut
* _pA ;
162
};
163
164
165
#include "CLHEP/GenericFunctions/CutBase.icc"
166
167
#endif
Generated on Sun Jun 17 2012 08:08:26 for CLHEP by
1.8.1.1