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 IndexedValue():
00071 m_Index(0),m_Value(boost::shared_ptr<Value>(new NullValue())) {};
00072
00073 IndexedValue(const TimeIndex_t& Ind, const Value& Val):
00074 m_Index(Ind),m_Value(boost::shared_ptr<Value>(Val.clone())) {};
00075
00076 IndexedValue(const IndexedValue& IndValue):
00077 m_Index(IndValue.m_Index),m_Value(boost::shared_ptr<Value>(IndValue.m_Value.get()->clone())) {};
00078
00079 inline TimeIndex_t getIndex() const { return m_Index; };
00080
00081 inline Value* getValue() const { return m_Value.get(); };
00082
00083 inline Value* getValue() { return m_Value.get(); };
00084
00085 inline void clear() { m_Index = 0; m_Value.reset(new NullValue()); };
00086
00087 };
00088
00089
00090
00091
00092
00093 typedef std::list<IndexedValue> IndexedValueList;
00094
00095
00096
00097
00098
00099
00100 class DLLEXPORT ValuesBuffer: public ValuesBufferProperties
00101 {
00102
00103 public:
00104
00105 typedef boost::circular_buffer<IndexedValue> DataContainer_t;
00106
00107
00108 private:
00109
00110 DataContainer_t m_Data;
00111
00112 DataContainer_t::iterator findAtIndex(const TimeIndex_t& anIndex);
00113
00114 DataContainer_t::const_iterator findAtIndex(const TimeIndex_t& anIndex) const;
00115
00116 public:
00117
00118 ValuesBuffer();
00119
00120 ~ValuesBuffer();
00121
00122 bool getValue(const TimeIndex_t& anIndex, Value* aValue) const;
00123
00124 Value* getValue(const TimeIndex_t& anIndex) const;
00125
00126 Value* getCurrentValue() const;
00127
00128 TimeIndex_t getCurrentIndex() const;
00129
00130 bool isValueExist(const TimeIndex_t& anIndex) const
00131 {
00132 return (!m_Data.empty() && findAtIndex(anIndex) != m_Data.end());
00133 }
00134
00135
00136 bool getCurrentValue(Value* aValue) const;
00137
00138 bool getLatestIndexedValue(IndexedValue& IndValue) const;
00139
00140 bool getLatestIndexedValues(const TimeIndex_t& anIndex, IndexedValueList& IndValueList) const;
00141
00142 bool getIndexedValues(const TimeIndex_t& aBeginIndex, const TimeIndex_t& anEndIndex,
00143 IndexedValueList& IndValueList) const;
00144
00145 bool modifyValue(const TimeIndex_t& anIndex, const Value& aValue);
00146
00147 bool modifyCurrentValue(const Value& aValue);
00148
00149 bool appendValue(const TimeIndex_t& anIndex, const Value& aValue);
00150
00151 unsigned int getValuesCount() const
00152 {
00153 return m_Data.size();
00154 }
00155
00156 void displayStatus(std::ostream& OStream) const;
00157
00158 void displayContent(std::ostream& OStream) const;
00159
00160
00161 };
00162
00163 }
00164 }
00165
00166
00167 #endif