FloatArrayTool.h
Go to the documentation of this file.
1 // FloatArrayTool.h
2 //
3 // David Adams
4 // January 2019
5 //
6 // Interface for a tool providing access to an array
7 // of floating values. It also holds an offset, i.e.
8 // the index of the first value, and a label.
9 
10 #ifndef FloatArrayTool_H
11 #define FloatArrayTool_H
12 
13 #include <vector>
14 
16 
17 public:
18 
19  using Index = unsigned int;
20  using FloatVector = std::vector<float>;
21 
22  virtual ~FloatArrayTool() =default;
23 
24  // Return the offset.
25  virtual Index offset() const { return 0; }
26 
27  // Return the label.
28  virtual std::string label() const { return ""; }
29 
30  // Return the units for the values.
31  virtual std::string unit() const { return ""; }
32 
33  // Return the values without offset.
34  virtual const FloatVector& values() const =0;
35 
36  // Return the number of values.
37  virtual Index size() const { return values().size(); }
38 
39  // Return the default value, i.e. the value returned when
40  // a caller requests a value that is out of range.
41  virtual float defaultValue() const { return 0.0; }
42 
43  // Return if an index is in range.
44  virtual bool inRange(Index ival) const {
45  if ( ival < offset() ) return false;
46  if ( ival + offset() >= size() ) return false;
47  return true;
48  }
49 
50  // Return the value for an (offset) index.
51  virtual float value(Index ival) const {
52  if ( ! inRange(ival) ) return defaultValue();
53  return values()[ival + offset()];
54  }
55  virtual float value(Index ival, float defval) const {
56  if ( ! inRange(ival) ) return defval;
57  return values()[ival + offset()];
58  }
59 
60  // Insert the values into a supplied vector.
61  // Values are place at the offset position.
62  // If needed, the size of the input vector is increased.
63  // Existing values may be overwritten.
64  // New values below the offset are set to valdef.
65  // Returns 0 for success.
66  virtual int fill(FloatVector& vals, float valdef) const {
67  Index len = offset() + size();
68  if ( len > vals.size() ) vals.resize(len, valdef);
69  std::copy(values().begin(), values().end(), vals.begin() + offset());
70  return 0;
71  }
72 
73 };
74 
75 #endif
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
virtual std::string unit() const
std::string string
Definition: nybbler.cc:12
virtual std::string label() const
virtual float value(Index ival, float defval) const
std::vector< float > FloatVector
virtual float defaultValue() const
virtual int fill(FloatVector &vals, float valdef) const
virtual Index offset() const
virtual Index size() const
T copy(T const &v)
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:72
virtual float value(Index ival) const
virtual bool inRange(Index ival) const
unsigned int Index
virtual const FloatVector & values() const =0
virtual ~FloatArrayTool()=default