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  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  }
46 
48  inline unsigned dim() const { return dim_; }
49 
51  inline unsigned long state() const { return state_; }
52 
54  inline unsigned long maxState() const { return maxState_; }
55 
57  inline bool isValid() const { return state_ < maxState_; }
58 
60  void getIndex(unsigned* index, unsigned indexBufferLen) const;
61 
63  inline void reset() { state_ = 0UL; }
64 
67  if (state_ < maxState_)
68  ++state_;
69  return *this;
70  }
71 
73  inline void operator++(int) {
74  if (state_ < maxState_)
75  ++state_;
76  }
77 
79  inline void setState(const unsigned long state) { state_ = state <= maxState_ ? state : maxState_; }
80 
81  private:
82  ArrayNDScanner() = delete;
83 
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