Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef __VALUESBUFFER_HPP__
00039 #define __VALUESBUFFER_HPP__
00040
00041 #include <openfluid/dllexport.hpp>
00042 #include <openfluid/core/ValuesBufferProperties.hpp>
00043 #include <openfluid/core/Value.hpp>
00044 #include <openfluid/core/NullValue.hpp>
00045 #include <openfluid/core/DateTime.hpp>
00046 #include <boost/circular_buffer.hpp>
00047
00048 #include <boost/shared_ptr.hpp>
00049
00050 #include <iostream>
00051 #include <list>
00052
00053 namespace openfluid {
00054 namespace core {
00055
00056
00057 class IndexedValue
00058 {
00059 friend class ValuesBuffer;
00060
00061 private:
00062
00063 TimeIndex_t m_Index;
00064
00065 boost::shared_ptr<Value> m_Value;
00066
00067
00068 public:
00069
00070
00071
00072
00073 IndexedValue():
00074 m_Index(0),m_Value(boost::shared_ptr<Value>(new NullValue())) {};
00075
00076
00077
00078
00079 IndexedValue(const TimeIndex_t& Ind, const Value& Val):
00080 m_Index(Ind),m_Value(boost::shared_ptr<Value>(Val.clone())) {};
00081
00082
00083
00084
00085 IndexedValue(const IndexedValue& IndValue):
00086 m_Index(IndValue.m_Index),m_Value(boost::shared_ptr<Value>(IndValue.m_Value.get()->clone())) {};
00087
00088
00089
00090
00091
00092 inline TimeIndex_t getIndex() const { return m_Index; };
00093
00094
00095
00096
00097
00098 inline Value* getValue() const { return m_Value.get(); };
00099
00100
00101
00102
00103
00104 inline Value* getValue() { return m_Value.get(); };
00105
00106
00107
00108
00109
00110 inline void clear() { m_Index = 0; m_Value.reset(new NullValue()); };
00111
00112 };
00113
00114
00115
00116
00117
00118 typedef std::list<IndexedValue> IndexedValueList;
00119
00120
00121
00122
00123
00124
00125 class DLLEXPORT ValuesBuffer: public ValuesBufferProperties
00126 {
00127
00128 public:
00129
00130 typedef boost::circular_buffer<IndexedValue> DataContainer_t;
00131
00132
00133 private:
00134
00135 DataContainer_t m_Data;
00136
00137 DataContainer_t::iterator findAtIndex(const TimeIndex_t& anIndex);
00138
00139 DataContainer_t::const_iterator findAtIndex(const TimeIndex_t& anIndex) const;
00140
00141 public:
00142
00143 ValuesBuffer();
00144
00145 ~ValuesBuffer();
00146
00147 bool getValue(const TimeIndex_t& anIndex, Value* aValue) const;
00148
00149 Value* getValue(const TimeIndex_t& anIndex) const;
00150
00151 Value* getCurrentValue() const;
00152
00153 TimeIndex_t getCurrentIndex() const;
00154
00155 bool isValueExist(const TimeIndex_t& anIndex) const
00156 {
00157 return (!m_Data.empty() && findAtIndex(anIndex) != m_Data.end());
00158 }
00159
00160
00161 bool getCurrentValue(Value* aValue) const;
00162
00163 bool getLatestIndexedValue(IndexedValue& IndValue) const;
00164
00165 bool getLatestIndexedValues(const TimeIndex_t& anIndex, IndexedValueList& IndValueList) const;
00166
00167 bool getIndexedValues(const TimeIndex_t& aBeginIndex, const TimeIndex_t& anEndIndex,
00168 IndexedValueList& IndValueList) const;
00169
00170 bool modifyValue(const TimeIndex_t& anIndex, const Value& aValue);
00171
00172 bool modifyCurrentValue(const Value& aValue);
00173
00174 bool appendValue(const TimeIndex_t& anIndex, const Value& aValue);
00175
00176 unsigned int getValuesCount() const
00177 {
00178 return m_Data.size();
00179 }
00180
00181 void displayStatus(std::ostream& OStream) const;
00182
00183 void displayContent(std::ostream& OStream) const;
00184
00185
00186 };
00187
00188 }
00189 }
00190
00191
00192 #endif