Noise Modeler Library  0.1
Library for procedurally generating noise-based terrains and other content
 All Classes Files Functions Variables Enumerations Enumerator Groups Pages
signalvalue.hpp
1 #ifndef NM_SIGNALVALUE_HPP
2 #define NM_SIGNALVALUE_HPP
3 
4 #include <nmlib/model/signaltype.hpp>
5 
6 #include <vector>
7 #include <cassert>
8 
9 namespace nm {
10 
16 {
17 public:
18  SignalValue(float value):
19  SignalValue(std::vector<float>{value})
20  {}
21  SignalValue(std::vector<float> values):
22  m_signalType(SignalType{static_cast<int>(values.size())}),
23  m_values(values)
24  {}
25  SignalValue(SignalType signalType):
26  m_signalType(signalType),
27  m_values(static_cast<unsigned int>(signalType.dimensionality))
28  {}
29  SignalValue(const SignalValue &other):
30  m_signalType(other.m_signalType),
31  m_values(other.m_values)
32  {}
33  SignalValue& operator=(const SignalValue &rhs){
34  assert(rhs.m_signalType.isConvertibleTo(m_signalType));
35  m_values = rhs.m_values;
36  return *this;
37  }
38  //TODO move constructor
39 
40  float &operator [](unsigned int i) {
41  return m_values[i];
42  }
43  float operator[](unsigned int i) const {
44  return m_values[i];
45  }
46  SignalType getSignalType() const { return m_signalType; }
47 
48 private:
49  const SignalType m_signalType;
50  std::vector<float> m_values;
51 };
52 
53 } // namespace nm
54 
55 #endif // NM_SIGNALVALUE_HPP
Describes a the dimensionality of a signal Can be extended to include other type information such as ...
Definition: signaltype.hpp:13
bool isConvertibleTo(const SignalType &rhs) const
Checks if this SignalType can be converted to another.
Definition: signaltype.cpp:19
A vector of floats that can be set as the unlinked value of InputLinks.
Definition: signalvalue.hpp:15