Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:19:17

0001 #ifndef NPSTAT_ABSVISITOR_HH_
0002 #define NPSTAT_ABSVISITOR_HH_
0003 
0004 /*!
0005 // \file AbsVisitor.h
0006 //
0007 // \brief Interface for piecemeal processing of a data collection
0008 //
0009 // Author: I. Volobouev
0010 //
0011 // March 2010
0012 */
0013 
0014 namespace npstat {
0015   /**
0016     // Interface class for piecemeal processing of a data collection
0017     */
0018   template <typename Input, typename Result>
0019   struct AbsVisitor {
0020     inline virtual ~AbsVisitor() {}
0021 
0022     /** Clear all accumulated results */
0023     virtual void clear() = 0;
0024 
0025     /** Process one array point */
0026     virtual void process(const Input& value) = 0;
0027 
0028     /** Return the result at the end of array processing */
0029     virtual Result result() = 0;
0030   };
0031 
0032   /**
0033     // Simple counter of visits is needed often, so it makes sense
0034     // to put it together with AbsVisitor in the same header. Do not
0035     // derive from this class, its destructor is not virtual.
0036     */
0037   template <typename Input>
0038   class VisitCounter : public AbsVisitor<Input, unsigned long> {
0039   public:
0040     inline VisitCounter() : counter_(0UL) {}
0041     inline virtual ~VisitCounter() {}
0042 
0043     inline void clear() { counter_ = 0UL; }
0044     inline void process(const Input&) { ++counter_; }
0045     inline unsigned long result() { return counter_; }
0046 
0047   private:
0048     unsigned long counter_;
0049   };
0050 }  // namespace npstat
0051 
0052 #endif  // ABSVISITOR_HH_