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" : ["Compute code", "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
91  @param[in] Date the date and time of the event
92  */
93  Event(const DateTime& Date);
94 
95  /**
96  Destructor
97  */
98  ~Event();
99 
100  /**
101  Returns true if the information exists
102  @param[in] Key the requested information key
103  */
104  bool isInfoExist(const std::string& Key) const;
105 
106  /**
107  Returns true if the information exists and equals the given string value
108  @param[in] Key the requested information key
109  @param[in] Value the requested value
110  */
111  bool isInfoEqual(const std::string& Key, const std::string& Value) const;
112 
113  /**
114  Returns true if the information exists and equals the given long value
115  @param[in] Key the requested information key
116  @param[in] Value the requested value
117  */
118  bool isInfoEqual(const std::string& Key, long Value) const;
119 
120  /**
121  Returns true if the information exists and equals the given double 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 double Value) const;
126 
127  /**
128  Returns true if the information exists and equals the given double value
129  @param[in] Key the requested information key
130  @param[in] Info the requested value
131  @deprecated Since version 1.7.1. Use openfluid::core::Event::isInfoEqual(const std::string&,const double) const
132  */
133  [[deprecated]] bool isInfoEqual(const std::string& Key, const double* Info) const;
134 
135  /**
136  Returns true if the information exists and equals the given DoubleValue value
137  @param[in] Key the requested information key
138  @param[in] Info the requested value
139  */
140  bool isInfoEqual(const std::string& Key, const DoubleValue& Info) const;
141 
142  /**
143  Returns the number of information
144  */
145  inline int getInfosCount() const
146  {
147  return m_Infos.size();
148  }
149 
150  /**
151  Returns all the informations as an EventInfosMap
152  */
153  inline EventInfosMap_t getInfos() const
154  {
155  return m_Infos;
156  }
157 
158  /**
159  Returns the date and time of the event
160  */
161  inline DateTime getDateTime() const
162  {
163  return m_Date;
164  }
165 
166  /**
167  Gets an information as a string
168  @param[in] Key the requested information key
169  @param[out] Info the value corresponding to the requested key
170  @return true if the key exists and the conversion to the requested type is correct
171  @deprecated Since version 1.7.1.
172  Use openfluid::core::Event::getInfoAsString(const std::string&,std::string&) const instead
173  */
174  [[deprecated]] bool getInfoAsString(const std::string& Key, std::string *Info) const;
175 
176  /**
177  Gets an information as a string
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 getInfoAsString(const std::string& Key, std::string& Info) const;
183 
184  /**
185  Gets an information as a long integer
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. Use openfluid::core::Event::getInfoAsLong(const std::string&,long&) const instead
190  */
191  [[deprecated]] bool getInfoAsLong(const std::string& Key, long *Info) const;
192 
193  /**
194  Gets an information as a long integer
195  @param[in] Key the requested information key
196  @param[out] Info the value corresponding to the requested key
197  @return true if the key exists and the conversion to the requested type is correct
198  */
199  bool getInfoAsLong(const std::string& Key, long& Info) const;
200 
201  /**
202  Gets an information as a double
203  @param[in] Key the requested information key
204  @param[out] Info the value corresponding to the requested key
205  @return true if the key exists and the conversion to the requested type is correct
206  @deprecated Since version 1.7.1.
207  Use openfluid::core::Event::getInfoAsDouble(const std::string&,double&) const instead
208  */
209  [[deprecated]] bool getInfoAsDouble(const std::string& Key, double *Info) const;
210 
211  /**
212  Gets an information as a double
213  @param[in] Key the requested information key
214  @param[out] Info the value corresponding to the requested key
215  @return true if the key exists and the conversion to the requested type is correct
216  */
217  bool getInfoAsDouble(const std::string& Key, double& Info) const;
218 
219  /**
220  Gets an information as a DoubleValue
221  @param[in] Key the requested information key
222  @param[out] Info the value corresponding to the requested key
223  @return true if the key exists and the conversion to the requested type is correct
224  */
225  bool getInfoAsDoubleValue(const std::string& Key, DoubleValue& Info) const;
226 
227  /**
228  Adds an information to the event
229  @param[in] Key the key of the added information
230  @param[in] Info the value of the added information
231  @return true if the adding is correct (key does not already exists)
232  */
233  bool addInfo(const std::string& Key, const std::string& Info);
234 
235  /**
236  Prints the content of the event to stdout
237  */
238  void println() const;
239 
240 };
241 
242 } } // namespace openfluid::core
243 
244 #endif /* __OPENFLUID_CORE_EVENT_HPP__ */
EventInfosMap_t getInfos() const
Definition: Event.hpp:153
Class for management of date and time information.
Definition: DateTime.hpp:87
Definition: Value.hpp:64
std::map< std::string, openfluid::core::StringValue > EventInfosMap_t
Definition: Event.hpp:72
DateTime getDateTime() const
Definition: Event.hpp:161
Definition: Event.hpp:68
Definition: DoubleValue.hpp:80
Definition: ApplicationException.hpp:47
#define OPENFLUID_API
Definition: dllexport.hpp:86
int getInfosCount() const
Definition: Event.hpp:145