Documentation for OpenFLUID 2.2.0
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  @file Event.hpp
35 
36  @author Jean-Christophe FABRE <jean-christophe.fabre@inra.fr>
37 */
38 
39 
40 #ifndef __OPENFLUID_CORE_EVENT_HPP__
41 #define __OPENFLUID_CORE_EVENT_HPP__
42 
43 
44 #include <openfluid/dllexport.hpp>
45 #include <openfluid/core/TypeDefs.hpp>
47 
48 
49 namespace openfluid { namespace core {
50 
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 
59  @cond OpenFLUID:completion
60  {
61  "contexts" : ["ANYWARE"],
62  "menupath" : ["Types", "Events"],
63  "title" : "Event",
64  "text" : "openfluid::core::Event %%SEL_START%%Ev%%SEL_END%%"
65  }
66  @endcond
67 */
69 {
70  public:
71 
72  typedef std::map<std::string, openfluid::core::StringValue> EventInfosMap_t;
73 
74 
75  private:
76 
77  DateTime m_Date;
78 
79  EventInfosMap_t m_Infos;
80 
81 
82  public:
83 
84  /**
85  Default constructor
86  */
87  Event();
88 
89  /**
90  Constructor with date
91  @param[in] Date the date and time of the event
92  */
93  Event(const DateTime& Date);
94 
95  /**
96  Copy constructor
97  */
98  Event(const Event&) = default;
99 
100  /**
101  Move constructor
102  */
103  Event(Event&&) = default;
104 
105  Event& operator=(const Event&) = default;
106 
107  Event& operator=(Event&&) = default;
108 
109  /**
110  Destructor
111  */
112  ~Event() = default;
113 
114  /**
115  Returns true if the information exists
116  @param[in] Key the requested information key
117  */
118  bool isInfoExist(const std::string& Key) const;
119 
120  /**
121  Returns true if the information exists and equals the given string value
122  @param[in] Key the requested information key
123  @param[in] Value the requested value
124  */
125  bool isInfoEqual(const std::string& Key, const std::string& Value) const;
126 
127  /**
128  Returns true if the information exists and equals the given long value
129  @param[in] Key the requested information key
130  @param[in] Value the requested value
131  */
132  bool isInfoEqual(const std::string& Key, long Value) const;
133 
134  /**
135  Returns true if the information exists and equals the given double value
136  @param[in] Key the requested information key
137  @param[in] Value the requested value
138  */
139  bool isInfoEqual(const std::string& Key, const double Value) const;
140 
141  /**
142  Returns true if the information exists and equals the given double value
143  @param[in] Key the requested information key
144  @param[in] Info the requested value
145  @deprecated Since version 1.7.1. Use openfluid::core::Event::isInfoEqual(const std::string&,const double) const
146  */
147  [[deprecated]] bool isInfoEqual(const std::string& Key, const double* Info) const;
148 
149  /**
150  Returns true if the information exists and equals the given DoubleValue value
151  @param[in] Key the requested information key
152  @param[in] Info the requested value
153  */
154  bool isInfoEqual(const std::string& Key, const DoubleValue& Info) const;
155 
156  /**
157  Returns the number of information
158  */
159  inline int getInfosCount() const
160  {
161  return m_Infos.size();
162  }
163 
164  /**
165  Returns all the informations as an EventInfosMap
166  */
167  inline EventInfosMap_t getInfos() const
168  {
169  return m_Infos;
170  }
171 
172  /**
173  Returns the date and time of the event
174  */
175  inline DateTime getDateTime() const
176  {
177  return m_Date;
178  }
179 
180  /**
181  Gets an information as a string
182  @param[in] Key the requested information key
183  @param[out] Info the value corresponding to the requested key
184  @return true if the key exists and the conversion to the requested type is correct
185  @deprecated Since version 1.7.1.
186  Use openfluid::core::Event::getInfoAsString(const std::string&,std::string&) const instead
187  */
188  [[deprecated]] bool getInfoAsString(const std::string& Key, std::string* Info) const;
189 
190  /**
191  Gets an information as a string
192  @param[in] Key the requested information key
193  @param[out] Info the value corresponding to the requested key
194  @return true if the key exists and the conversion to the requested type is correct
195  */
196  bool getInfoAsString(const std::string& Key, std::string& Info) const;
197 
198  /**
199  Gets an information as a long integer
200  @param[in] Key the requested information key
201  @param[out] Info the value corresponding to the requested key
202  @return true if the key exists and the conversion to the requested type is correct
203  @deprecated Since version 1.7.1. Use openfluid::core::Event::getInfoAsLong(const std::string&,long&) const instead
204  */
205  [[deprecated]] bool getInfoAsLong(const std::string& Key, long *Info) const;
206 
207  /**
208  Gets an information as a long integer
209  @param[in] Key the requested information key
210  @param[out] Info the value corresponding to the requested key
211  @return true if the key exists and the conversion to the requested type is correct
212  */
213  bool getInfoAsLong(const std::string& Key, long& Info) const;
214 
215  /**
216  Gets an information as a double
217  @param[in] Key the requested information key
218  @param[out] Info the value corresponding to the requested key
219  @return true if the key exists and the conversion to the requested type is correct
220  @deprecated Since version 1.7.1.
221  Use openfluid::core::Event::getInfoAsDouble(const std::string&,double&) const instead
222  */
223  [[deprecated]] bool getInfoAsDouble(const std::string& Key, double* Info) const;
224 
225  /**
226  Gets an information as a double
227  @param[in] Key the requested information key
228  @param[out] Info the value corresponding to the requested key
229  @return true if the key exists and the conversion to the requested type is correct
230  */
231  bool getInfoAsDouble(const std::string& Key, double& Info) const;
232 
233  /**
234  Gets an information as a DoubleValue
235  @param[in] Key the requested information key
236  @param[out] Info the value corresponding to the requested key
237  @return true if the key exists and the conversion to the requested type is correct
238  */
239  bool getInfoAsDoubleValue(const std::string& Key, DoubleValue& Info) const;
240 
241  /**
242  Adds an information to the event
243  @param[in] Key the key of the added information
244  @param[in] Info the value of the added information
245  @return true if the adding is correct (key does not already exists)
246  */
247  bool addInfo(const std::string& Key, const std::string& Info);
248 
249  /**
250  Prints the content of the event to stdout
251  */
252  void println() const;
253 
254 };
255 
256 } } // namespace openfluid::core
257 
258 #endif /* __OPENFLUID_CORE_EVENT_HPP__ */
Class for management of date and time information.
Definition: DateTime.hpp:88
Definition: DoubleValue.hpp:81
Definition: Event.hpp:69
bool getInfoAsDouble(const std::string &Key, double *Info) const
bool isInfoEqual(const std::string &Key, long Value) const
bool getInfoAsString(const std::string &Key, std::string *Info) const
std::map< std::string, openfluid::core::StringValue > EventInfosMap_t
Definition: Event.hpp:72
DateTime getDateTime() const
Definition: Event.hpp:175
bool getInfoAsDoubleValue(const std::string &Key, DoubleValue &Info) const
Event(const DateTime &Date)
bool isInfoEqual(const std::string &Key, const DoubleValue &Info) const
bool isInfoEqual(const std::string &Key, const double *Info) const
bool addInfo(const std::string &Key, const std::string &Info)
bool getInfoAsString(const std::string &Key, std::string &Info) const
EventInfosMap_t getInfos() const
Definition: Event.hpp:167
Event(Event &&)=default
bool isInfoExist(const std::string &Key) const
Event & operator=(const Event &)=default
bool getInfoAsLong(const std::string &Key, long *Info) const
bool getInfoAsLong(const std::string &Key, long &Info) const
bool isInfoEqual(const std::string &Key, const std::string &Value) const
Event(const Event &)=default
Event & operator=(Event &&)=default
bool getInfoAsDouble(const std::string &Key, double &Info) const
int getInfosCount() const
Definition: Event.hpp:159
bool isInfoEqual(const std::string &Key, const double Value) const
Definition: Value.hpp:63
#define OPENFLUID_API
Definition: dllexport.hpp:86
Definition: ApplicationException.hpp:47