CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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  public:
39 
40  inline ArrayNDScanner(const unsigned* shape, const unsigned lenShape) { initialize(shape, lenShape); }
41 
42  inline explicit ArrayNDScanner(const std::vector<unsigned>& shape) {
43  initialize(shape.empty() ? static_cast<unsigned*>(nullptr) : &shape[0], shape.size());
44  }
45 
46  ArrayNDScanner() = delete;
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_)
70  ++state_;
71  return *this;
72  }
73 
75  inline void operator++(int) {
76  if (state_ < maxState_)
77  ++state_;
78  }
79 
81  inline void setState(const unsigned long state) { state_ = state <= maxState_ ? state : maxState_; }
82 
83  private:
84  void initialize(const unsigned* shape, unsigned lenShape);
85 
86  unsigned long strides_[CHAR_BIT * sizeof(unsigned long)];
87  unsigned long state_;
88  unsigned long maxState_;
89  unsigned dim_;
90  };
91 } // namespace npstat
92 
93 #endif // NPSTAT_ARRAYSCANNER_HH_
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