All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ValuesBuffer.hpp
Go to the documentation of this file.
1 /*
2 
3  This file is part of OpenFLUID software
4  Copyright(c) 2007, INRA - Montpellier SupAgro
5 
6 
7  == GNU General Public License Usage ==
8 
9  OpenFLUID is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  OpenFLUID is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with OpenFLUID. If not, see <http://www.gnu.org/licenses/>.
21 
22 
23  == Other Usage ==
24 
25  Other Usage means a use of OpenFLUID that is inconsistent with the GPL
26  license, and requires a written agreement between You and INRA.
27  Licensees for Other Usage of OpenFLUID may use this file in accordance
28  with the terms contained in the written agreement between You and INRA.
29 
30 */
31 
32 /**
33  @file
34 
35  @author Jean-Christophe FABRE <fabrejc@supagro.inra.fr>
36  */
37 
38 #ifndef __VALUESBUFFER_HPP__
39 #define __VALUESBUFFER_HPP__
40 
41 #include <openfluid/dllexport.hpp>
43 #include <openfluid/core/Value.hpp>
46 #include <boost/circular_buffer.hpp>
47 
48 #include <boost/shared_ptr.hpp>
49 
50 #include <iostream>
51 #include <list>
52 
53 namespace openfluid {
54 namespace core {
55 
56 
58 {
59  friend class ValuesBuffer;
60 
61  private:
62 
63  TimeIndex_t m_Index;
64 
65  boost::shared_ptr<Value> m_Value;
66 
67 
68  public:
69 
70  /**
71  Default constructor
72  */
74  m_Index(0),m_Value(boost::shared_ptr<Value>(new NullValue())) {};
75 
76  /**
77  Constructor from a time index and a value
78  */
79  IndexedValue(const TimeIndex_t& Ind, const Value& Val):
80  m_Index(Ind),m_Value(boost::shared_ptr<Value>(Val.clone())) {};
81 
82  /**
83  Copy constructor
84  */
85  IndexedValue(const IndexedValue& IndValue):
86  m_Index(IndValue.m_Index),m_Value(boost::shared_ptr<Value>(IndValue.m_Value.get()->clone())) {};
87 
88  /**
89  Returns the time index of the indexed value
90  @return the time index
91  */
92  inline TimeIndex_t getIndex() const { return m_Index; };
93 
94  /**
95  Returns a pointer to the value of the indexed value
96  @return a pointer to the value
97  */
98  inline Value* getValue() const { return m_Value.get(); };
99 
100  /**
101  Returns a pointer to the value of the indexed value
102  @return a pointer to the value
103  */
104  inline Value* getValue() { return m_Value.get(); };
105 
106  /**
107  Clears the content of the indexed value. The time index is set to 0,
108  and the value is set to an openfluid::core::NullValue.
109  */
110  inline void clear() { m_Index = 0; m_Value.reset(new NullValue()); };
111 
112 };
113 
114 
115 /**
116  Indexed value list, ordered from oldest (front) to more recent (back)
117 */
118 typedef std::list<IndexedValue> IndexedValueList;
119 
120 
121 // =====================================================================
122 // =====================================================================
123 
124 
126 {
127 
128  public:
129 
130  typedef boost::circular_buffer<IndexedValue> DataContainer_t;
131 
132 
133  private:
134 
135  DataContainer_t m_Data;
136 
137  DataContainer_t::iterator findAtIndex(const TimeIndex_t& anIndex);
138 
139  DataContainer_t::const_iterator findAtIndex(const TimeIndex_t& anIndex) const;
140 
141  public:
142 
143  ValuesBuffer();
144 
145  ~ValuesBuffer();
146 
147  bool getValue(const TimeIndex_t& anIndex, Value* aValue) const;
148 
149  Value* getValue(const TimeIndex_t& anIndex) const;
150 
151  Value* getCurrentValue() const;
152 
153  TimeIndex_t getCurrentIndex() const;
154 
155  bool isValueExist(const TimeIndex_t& anIndex) const
156  {
157  return (!m_Data.empty() && findAtIndex(anIndex) != m_Data.end());
158  }
159 
160 
161  bool getCurrentValue(Value* aValue) const;
162 
163  bool getLatestIndexedValue(IndexedValue& IndValue) const;
164 
165  bool getLatestIndexedValues(const TimeIndex_t& anIndex, IndexedValueList& IndValueList) const;
166 
167  bool getIndexedValues(const TimeIndex_t& aBeginIndex, const TimeIndex_t& anEndIndex,
168  IndexedValueList& IndValueList) const;
169 
170  bool modifyValue(const TimeIndex_t& anIndex, const Value& aValue);
171 
172  bool modifyCurrentValue(const Value& aValue);
173 
174  bool appendValue(const TimeIndex_t& anIndex, const Value& aValue);
175 
176  unsigned int getValuesCount() const
177  {
178  return m_Data.size();
179  }
180 
181  void displayStatus(std::ostream& OStream) const;
182 
183  void displayContent(std::ostream& OStream) const;
184 
185 
186 };
187 
188 }
189 } // namespaces
190 
191 
192 #endif /* __VALUESBUFFER_HPP__ */
unsigned long long TimeIndex_t
Definition: DateTime.hpp:62
std::list< IndexedValue > IndexedValueList
Definition: ValuesBuffer.hpp:118
Header of ...
void clear()
Definition: ValuesBuffer.hpp:110
IndexedValue()
Definition: ValuesBuffer.hpp:73
bool isValueExist(const TimeIndex_t &anIndex) const
Definition: ValuesBuffer.hpp:155
TimeIndex_t getIndex() const
Definition: ValuesBuffer.hpp:92
Definition: ValuesBuffer.hpp:125
Definition: ValuesBufferProperties.hpp:48
Header of ...
Definition: NullValue.hpp:59
Value * getValue()
Definition: ValuesBuffer.hpp:104
boost::circular_buffer< IndexedValue > DataContainer_t
Definition: ValuesBuffer.hpp:130
unsigned int getValuesCount() const
Definition: ValuesBuffer.hpp:176
Definition: Value.hpp:64
IndexedValue(const TimeIndex_t &Ind, const Value &Val)
Definition: ValuesBuffer.hpp:79
Definition: ValuesBuffer.hpp:57
IndexedValue(const IndexedValue &IndValue)
Definition: ValuesBuffer.hpp:85
Value * getValue() const
Definition: ValuesBuffer.hpp:98
#define DLLEXPORT
Definition: dllexport.hpp:51