CMS 3D CMS Logo

ArrayNDScanner.h
Go to the documentation of this file.
1 #ifndef NPSTAT_ARRAYNDSCANNER_HH_
2 #define NPSTAT_ARRAYNDSCANNER_HH_
3 
14 #include <vector>
15 #include <climits>
16 
17 namespace npstat {
37  {
38  public:
40 
41  inline ArrayNDScanner(const unsigned* shape, const unsigned lenShape)
42  {initialize(shape, lenShape);}
43 
44  inline explicit ArrayNDScanner(const std::vector<unsigned>& shape)
45  {initialize(shape.empty() ? static_cast<unsigned*>(0) :
46  &shape[0], shape.size());}
48 
50  inline unsigned dim() const {return dim_;}
51 
53  inline unsigned long state() const {return state_;}
54 
56  inline unsigned long maxState() const {return maxState_;}
57 
59  inline bool isValid() const {return state_ < maxState_;}
60 
62  void getIndex(unsigned* index, unsigned indexBufferLen) const;
63 
65  inline void reset() {state_ = 0UL;}
66 
69  {if (state_ < maxState_) ++state_; return *this;}
70 
72  inline void operator++(int) {if (state_ < maxState_) ++state_;}
73 
75  inline void setState(const unsigned long state)
76  {state_ = state <= maxState_ ? state : maxState_;}
77 
78  private:
80 
81  void initialize(const unsigned* shape, unsigned lenShape);
82 
83  unsigned long strides_[CHAR_BIT*sizeof(unsigned long)];
84  unsigned long state_;
85  unsigned long maxState_;
86  unsigned dim_;
87  };
88 }
89 
90 #endif // NPSTAT_ARRAYSCANNER_HH_
91 
unsigned long maxState() const
ArrayNDScanner(const unsigned *shape, const unsigned lenShape)
void setState(const unsigned long state)
ArrayNDScanner & operator++()
void initialize(const unsigned *shape, unsigned lenShape)
unsigned long maxState_
ArrayNDScanner(const std::vector< unsigned > &shape)
unsigned long strides_[CHAR_BIT *sizeof(unsigned long)]
void getIndex(unsigned *index, unsigned indexBufferLen) const
unsigned long state() const
unsigned dim() const