npstat is hosted by Hepforge, IPPP Durham
NPStat  5.10.0
ArrayRange.hh
Go to the documentation of this file.
1 #ifndef NPSTAT_ARRAYRANGE_HH_
2 #define NPSTAT_ARRAYRANGE_HH_
3 
4 /*!
5 // \file ArrayRange.hh
6 //
7 // \brief Multidimensional range of array indices
8 //
9 // Author: I. Volobouev
10 //
11 // October 2009
12 */
13 
14 #include "geners/ClassId.hh"
15 
16 #include "npstat/nm/ArrayShape.hh"
17 #include "npstat/nm/BoxND.hh"
18 
19 namespace npstat {
20  /**
21  // Utility class for use in certain array iterations
22  */
23  struct ArrayRange : public BoxND<unsigned>
24  {
25  inline ArrayRange() {}
26 
27  /** Constructor from a given number of dimensions */
28  inline explicit ArrayRange(unsigned dim) : BoxND<unsigned>(dim) {}
29 
30  /** The given interval is repeated for every dimension */
31  inline ArrayRange(unsigned dim, const Interval<unsigned>& r1)
32  : BoxND<unsigned>(dim, r1) {}
33 
34  //@{
35  /**
36  // Constructor which creates a range out of a shape
37  // which is used to represent the upper limit. The
38  // lower limit in each dimension is set to 0.
39  */
40  inline explicit ArrayRange(const ArrayShape& shape)
41  : BoxND<unsigned>(shape) {}
42  ArrayRange(const unsigned* shape, unsigned shapeLen);
43  //@}
44 
45  /**
46  // The shape which corresponds to this range
47  // (i.e., max - min in all dimensions)
48  */
49  ArrayShape shape() const;
50 
51  //@{
52  /** Check for compatibility with a shape */
53  bool isCompatible(const ArrayShape& shape) const;
54  bool isCompatible(const unsigned* shape, unsigned shapeLen) const;
55  //@}
56 
57  /** How many elements will be iterated over? */
58  unsigned long rangeSize() const;
59 
60  /** Operator for use with maps */
61  bool operator<(const ArrayRange&) const;
62 
63  /**
64  // This method changes the range of this object so that
65  // for each dimension the minimum becomes larger by 1 and the
66  // maximum smaller by 1.
67  */
69 
70  /**
71  // Get the lower range limits into an array. The length of
72  // the limit array should be at least equal to the dimensionality.
73  */
74  void lowerLimits(unsigned* limits, unsigned limitsLen) const;
75 
76  /** Get the upper range limits into an array */
77  void upperLimits(unsigned* limits, unsigned limitsLen) const;
78 
79  /** Get the range into an array */
80  void rangeLength(unsigned* range, unsigned rangeLen) const;
81 
82  // Methods needed for I/O
83  inline gs::ClassId classId() const {return gs::ClassId(*this);}
84  bool write(std::ostream& of) const;
85 
86  static inline const char* classname() {return "npstat::ArrayRange";}
87  static inline unsigned version() {return 1;}
88  static void restore(const gs::ClassId& id, std::istream& in,
89  ArrayRange* box);
90  };
91 }
92 
93 #endif // NPSTAT_ARRAYRANGE_HH_
Utilities for defining shapes of multidimensional arrays.
Template to represent rectangles, boxes, and hyperboxes.
Definition: Interval.hh:29
Definition: AbsArrayProjector.hh:14
std::vector< unsigned > ArrayShape
Definition: ArrayShape.hh:21
Definition: ArrayRange.hh:24
ArrayShape shape() const
bool operator<(const ArrayRange &) const
ArrayRange(unsigned dim)
Definition: ArrayRange.hh:28
ArrayRange(const ArrayShape &shape)
Definition: ArrayRange.hh:40
ArrayRange & stripOuterLayer()
void rangeLength(unsigned *range, unsigned rangeLen) const
void lowerLimits(unsigned *limits, unsigned limitsLen) const
unsigned long rangeSize() const
void upperLimits(unsigned *limits, unsigned limitsLen) const
bool isCompatible(const ArrayShape &shape) const
ArrayRange(unsigned dim, const Interval< unsigned > &r1)
Definition: ArrayRange.hh:31
Definition: BoxND.hh:25
unsigned long dim() const
Definition: BoxND.hh:59