npstat is hosted by Hepforge, IPPP Durham
NPStat  5.10.0
AbsVisitor.hh
Go to the documentation of this file.
1 #ifndef NPSTAT_ABSVISITOR_HH_
2 #define NPSTAT_ABSVISITOR_HH_
3 
4 /*!
5 // \file AbsVisitor.hh
6 //
7 // \brief Interface for piecemeal processing of a data collection
8 //
9 // Author: I. Volobouev
10 //
11 // March 2010
12 */
13 
14 namespace npstat {
15  /**
16  // Interface class for piecemeal processing of a data collection
17  */
18  template <typename Input, typename Result>
19  struct AbsVisitor
20  {
21  inline virtual ~AbsVisitor() {}
22 
23  /** Clear all accumulated results */
24  virtual void clear() = 0;
25 
26  /** Process one array point */
27  virtual void process(const Input& value) = 0;
28 
29  /** Return the result at the end of array processing */
30  virtual Result result() = 0;
31  };
32 
33  /**
34  // Simple counter of visits is needed often, so it makes sense
35  // to put it together with AbsVisitor in the same header. Do not
36  // derive from this class, its destructor is not virtual.
37  */
38  template <typename Input>
39  class VisitCounter : public AbsVisitor<Input,unsigned long>
40  {
41  public:
42  inline VisitCounter() : counter_(0UL) {}
43  inline virtual ~VisitCounter() {}
44 
45  inline void clear() {counter_ = 0UL;}
46  inline void process(const Input&) {++counter_;}
47  inline unsigned long result() {return counter_;}
48 
49  private:
50  unsigned long counter_;
51  };
52 }
53 
54 #endif // ABSVISITOR_HH_
Definition: AbsVisitor.hh:40
unsigned long result()
Definition: AbsVisitor.hh:47
void clear()
Definition: AbsVisitor.hh:45
void process(const Input &)
Definition: AbsVisitor.hh:46
Definition: AbsArrayProjector.hh:14
Definition: AbsVisitor.hh:20
virtual Result result()=0
virtual void clear()=0
virtual void process(const Input &value)=0