21 #ifndef DYNAMICSTATE_HPP_
22 #define DYNAMICSTATE_HPP_
25 #include <boost/shared_ptr.hpp>
26 #include <boost/date_time.hpp>
71 const T&
at(
size_t index)
const {
72 if (index >= m_timeMap->size())
73 throw std::range_error(
"Index value is out range.");
75 if (index >= m_data.size())
76 return m_currentValue;
78 return m_data.at(index);
87 T
get(
size_t index)
const {
88 if (index >= m_timeMap->size())
89 throw std::range_error(
"Index value is out range.");
91 if (index >= m_data.size())
92 return m_currentValue;
100 if (m_initialValue != initialValue) {
102 m_initialValue = initialValue;
103 if (m_initialRange > 0) {
104 for (index = 0; index < m_initialRange; index++)
105 m_data[index] = m_initialValue;
107 m_currentValue = initialValue;
113 return m_data.size();
122 bool change = (value != m_currentValue);
123 if (index >= (m_timeMap->size()))
124 throw std::range_error(
"Index value is out range.");
126 if (m_data.size() > 0) {
127 if (index < (m_data.size() - 1))
128 throw std::invalid_argument(
"Elements must be added in weakly increasing order");
132 size_t currentSize = m_data.size();
133 if (currentSize <= index) {
134 for (
size_t i = currentSize; i <= index; i++)
135 m_data.push_back( m_currentValue );
139 m_data[index] = value;
140 m_currentValue = value;
141 if (m_initialRange == 0)
142 m_initialRange = index;
151 void init(T initialValue) {
153 m_currentValue = initialValue;
154 m_initialValue = initialValue;
159 std::vector<T> m_data;
163 size_t m_initialRange;
DynamicState(const TimeMapConstPtr timeMap, T initialValue)
Definition: DynamicState.hpp:60
std::shared_ptr< const TimeMap > TimeMapConstPtr
Definition: TimeMap.hpp:77
const T & at(size_t index) const
Definition: DynamicState.hpp:71
Definition: DynamicState.hpp:56
size_t size() const
Definition: DynamicState.hpp:112
bool update(size_t index, T value)
Definition: DynamicState.hpp:121
const T & operator[](size_t index) const
Definition: DynamicState.hpp:82
void globalReset(T newValue)
Definition: DynamicState.hpp:65
void updateInitial(T initialValue)
Definition: DynamicState.hpp:99