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