OpenWareLaboratory
SimpleValue.h
Go to the documentation of this file.
1 #ifndef __SimpleValue_h__
2 #define __SimpleValue_h__
3 
11 template <typename T>
12 class SimpleValue {
13 protected:
14  T value;
15 public:
16  SimpleValue() : value(0) {}
18  SimpleValue(const SimpleValue<T>& other) : value(other.value) {}
19  T get(){
20  return value;
21  }
22  void reset(T x){
23  value = x;
24  }
25  void update(T x){
26  value = x;
27  }
28  SimpleValue<T>& operator=(const T& other){
29  update(other);
30  return *this;
31  }
32  SimpleValue<T>& operator+=(const T& other){
33  update(value + other);
34  return *this;
35  }
36  SimpleValue<T>& operator-=(const T& other){
37  update(value - other);
38  return *this;
39  }
40  SimpleValue<T>& operator*=(const T& other){
41  update(value * other);
42  return *this;
43  }
44  SimpleValue<T>& operator/=(const T& other){
45  update(value / other);
46  return *this;
47  }
48  operator T(){
49  return get();
50  }
51  static const T DEFAULT_LAMBDA;
52  static const T DEFAULT_DELTA;
53  static const T DEFAULT_EXP_C;
54  static const T DEFAULT_EXP_K;
55  static const T DEFAULT_LOG_C;
56  static const T DEFAULT_LOG_K;
57 };
58 
59 // prevent -Wundefined-var-template warnings
60 template<> const float SimpleValue<float>::DEFAULT_LAMBDA;
61 template<> const float SimpleValue<float>::DEFAULT_DELTA;
62 template<> const float SimpleValue<float>::DEFAULT_EXP_C;
63 template<> const float SimpleValue<float>::DEFAULT_EXP_K;
64 template<> const float SimpleValue<float>::DEFAULT_LOG_C;
65 template<> const float SimpleValue<float>::DEFAULT_LOG_K;
66 template<> const int SimpleValue<int>::DEFAULT_LAMBDA;
67 template<> const int SimpleValue<int>::DEFAULT_DELTA;
68 template<> const int SimpleValue<int>::DEFAULT_EXP_C;
69 template<> const int SimpleValue<int>::DEFAULT_EXP_K;
70 template<> const int SimpleValue<int>::DEFAULT_LOG_C;
71 template<> const int SimpleValue<int>::DEFAULT_LOG_K;
72 
73 #endif /* __SimpleValue_h__ */
Base class for a value that can be set, updated and retrieved (get).
Definition: SimpleValue.h:12
void update(T x)
Definition: SimpleValue.h:25
static const T DEFAULT_EXP_K
Definition: SimpleValue.h:54
SimpleValue(T value)
Definition: SimpleValue.h:17
SimpleValue(const SimpleValue< T > &other)
Definition: SimpleValue.h:18
void reset(T x)
Definition: SimpleValue.h:22
SimpleValue< T > & operator=(const T &other)
Definition: SimpleValue.h:28
SimpleValue< T > & operator-=(const T &other)
Definition: SimpleValue.h:36
SimpleValue< T > & operator*=(const T &other)
Definition: SimpleValue.h:40
static const T DEFAULT_EXP_C
Definition: SimpleValue.h:53
SimpleValue< T > & operator/=(const T &other)
Definition: SimpleValue.h:44
SimpleValue< T > & operator+=(const T &other)
Definition: SimpleValue.h:32
static const T DEFAULT_LAMBDA
Definition: SimpleValue.h:51
static const T DEFAULT_LOG_C
Definition: SimpleValue.h:55
static const T DEFAULT_DELTA
Definition: SimpleValue.h:52
static const T DEFAULT_LOG_K
Definition: SimpleValue.h:56