All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Event.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 
34 /**
35  @file Event.hpp
36 
37  @author Jean-Christophe FABRE <jean-christophe.fabre@supagro.inra.fr>
38 */
39 
40 #ifndef __OPENFLUID_CORE_EVENT_HPP__
41 #define __OPENFLUID_CORE_EVENT_HPP__
42 
43 
44 #include <openfluid/dllexport.hpp>
46 #include <openfluid/core/TypeDefs.hpp>
48 
49 
50 namespace openfluid { namespace core {
51 
52 /**
53  Class defining a discrete event, including attached information
54 
55  Each event attached information is represented by a Key-Value couple :
56  @li Key is the name given to the information
57  @li Value is the value of the information and can be numeric or text information
58 */
60 {
61  public:
62  typedef std::map<std::string, openfluid::core::StringValue> EventInfosMap_t;
63 
64  private:
65 
66  DateTime m_Date;
67 
68  EventInfosMap_t m_Infos;
69 
70 
71  public:
72 
73  /**
74  Default constructor
75  */
76  Event();
77 
78  /**
79  Constructor
80  @param[in] Date the date and time of the event
81  */
82  Event(const DateTime& Date);
83 
84  /**
85  Destructor
86  */
87  ~Event();
88 
89  /**
90  Returns true if the information exists
91  @param[in] Key the requested information key
92  */
93  bool isInfoExist(const std::string& Key) const;
94 
95  /**
96  Returns true if the information exists and equals the given string value
97  @param[in] Key the requested information key
98  @param[in] Value the requested value
99  */
100  bool isInfoEqual(const std::string& Key, const std::string& Value) const;
101 
102  /**
103  Returns true if the information exists and equals the given long value
104  @param[in] Key the requested information key
105  @param[in] Value the requested value
106  */
107  bool isInfoEqual(const std::string& Key, long Value) const;
108 
109  /**
110  Returns true if the information exists and equals the given double value
111  @param[in] Key the requested information key
112  @param[in] Value the requested value
113  */
114  bool isInfoEqual(const std::string& Key, const double Value) const;
115 
116  /**
117  Returns true if the information exists and equals the given double value
118  @param[in] Key the requested information key
119  @param[in] Info the requested value
120  @deprecated Since version 1.7.1. Use openfluid::core::Event::isInfoEqual(const std::string&,const double) const
121  */
122  bool isInfoEqual(const std::string& Key, const double* Info) const OPENFLUID_DEPRECATED;
123 
124  /**
125  Returns true if the information exists and equals the given DoubleValue value
126  @param[in] Key the requested information key
127  @param[in] Info the requested value
128  */
129  bool isInfoEqual(const std::string& Key, const DoubleValue& Info) const;
130 
131  /**
132  Returns the number of information
133  */
134  inline int getInfosCount() const
135  { return m_Infos.size(); }
136 
137  /**
138  Returns all the informations as an EventInfosMap
139  */
140  inline EventInfosMap_t getInfos() const
141  { return m_Infos; }
142 
143  /**
144  Returns the date and time of the event
145  */
146  inline DateTime getDateTime() const
147  { return m_Date; }
148 
149  /**
150  Gets an information as a string
151  @param[in] Key the requested information key
152  @param[out] Info the value corresponding to the requested key
153  @return true if the key exists and the conversion to the requested type is correct
154  @deprecated Since version 1.7.1.
155  Use openfluid::core::Event::getInfoAsString(const std::string&,std::string&) const instead
156  */
157  bool getInfoAsString(const std::string& Key, std::string *Info) const OPENFLUID_DEPRECATED;
158 
159  /**
160  Gets an information as a string
161  @param[in] Key the requested information key
162  @param[out] Info the value corresponding to the requested key
163  @return true if the key exists and the conversion to the requested type is correct
164  */
165  bool getInfoAsString(const std::string& Key, std::string& Info) const;
166 
167  /**
168  Gets an information as a long integer
169  @param[in] Key the requested information key
170  @param[out] Info the value corresponding to the requested key
171  @return true if the key exists and the conversion to the requested type is correct
172  @deprecated Since version 1.7.1. Use openfluid::core::Event::getInfoAsLong(const std::string&,long&) const instead
173  */
174  bool getInfoAsLong(const std::string& Key, long *Info) const OPENFLUID_DEPRECATED;
175 
176  /**
177  Gets an information as a long integer
178  @param[in] Key the requested information key
179  @param[out] Info the value corresponding to the requested key
180  @return true if the key exists and the conversion to the requested type is correct
181  */
182  bool getInfoAsLong(const std::string& Key, long& Info) const;
183 
184  /**
185  Gets an information as a double
186  @param[in] Key the requested information key
187  @param[out] Info the value corresponding to the requested key
188  @return true if the key exists and the conversion to the requested type is correct
189  @deprecated Since version 1.7.1.
190  Use openfluid::core::Event::getInfoAsDouble(const std::string&,double&) const instead
191  */
192  bool getInfoAsDouble(const std::string& Key, double *Info) const OPENFLUID_DEPRECATED;
193 
194  /**
195  Gets an information as a double
196  @param[in] Key the requested information key
197  @param[out] Info the value corresponding to the requested key
198  @return true if the key exists and the conversion to the requested type is correct
199  */
200  bool getInfoAsDouble(const std::string& Key, double& Info) const;
201 
202  /**
203  Gets an information as a DoubleValue
204  @param[in] Key the requested information key
205  @param[out] Info the value corresponding to the requested key
206  @return true if the key exists and the conversion to the requested type is correct
207  */
208  bool getInfoAsDoubleValue(const std::string& Key, DoubleValue& Info) const;
209 
210  /**
211  Adds an information to the event
212  @param[in] Key the key of the added information
213  @param[in] Info the value of the added information
214  @return true if the adding is correct (key does not already exists)
215  */
216  bool addInfo(const std::string& Key, const std::string& Info);
217 
218  /**
219  Prints the content of the event to stdout
220  */
221  void println() const;
222 
223 };
224 
225 } } // namespace openfluid::core
226 
227 #endif /* __OPENFLUID_CORE_EVENT_HPP__ */
Class for management of date and time information.
Definition: DateTime.hpp:132
EventInfosMap_t getInfos() const
Definition: Event.hpp:140
SpatialUnit Unit OPENFLUID_DEPRECATED
Definition: SpatialUnit.hpp:287
Definition: Event.hpp:59
Definition: Value.hpp:64
Definition: DoubleValue.hpp:102
DateTime getDateTime() const
Definition: Event.hpp:146
std::map< std::string, openfluid::core::StringValue > EventInfosMap_t
Definition: Event.hpp:62
#define OPENFLUID_API
Definition: dllexport.hpp:87
int getInfosCount() const
Definition: Event.hpp:134