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