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
36 
37  @author Jean-Christophe FABRE <fabrejc@supagro.inra.fr>
38 */
39 
40 #ifndef __EVENT_HPP__
41 #define __EVENT_HPP__
42 
43 
44 #include <openfluid/dllexport.hpp>
48 
49 
50 namespace openfluid { namespace core {
51 
52 
53 
54 /**
55  @brief Class defining a discrete event, including attached information
56 
57  Each event attached information is represented by a Key-Value couple :
58  @li Key is the name given to the information
59  @li Value is the value of the information and can be numeric or text information
60 */
62 {
63  public:
64  typedef std::map<std::string, openfluid::core::StringValue> EventInfosMap_t;
65 
66  private:
67  DateTime m_Date;
68 
69  EventInfosMap_t m_Infos;
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(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
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 { return m_Infos.size(); }
135 
136  /**
137  Returns all the informations as an EventInfosMap
138  */
139  inline EventInfosMap_t getInfos() const { return m_Infos; }
140 
141  /**
142  Returns the date and time of the event
143  */
144  inline DateTime getDateTime() const { return m_Date; }
145 
146  /**
147  Gets an information as a string
148  @param[in] Key the requested information key
149  @param[out] Info the value corresponding to the requested key
150  @return true if the key exists and the conversion to the requested type is correct
151  @deprecated
152  */
153  bool getInfoAsString(const std::string Key, std::string *Info) const OPENFLUID_DEPRECATED;
154 
155  /**
156  Gets an information as a string
157  @param[in] Key the requested information key
158  @param[out] Info the value corresponding to the requested key
159  @return true if the key exists and the conversion to the requested type is correct
160  */
161  bool getInfoAsString(const std::string Key, std::string& Info) const;
162 
163  /**
164  Gets an information as a long integer
165  @param[in] Key the requested information key
166  @param[out] Info the value corresponding to the requested key
167  @return true if the key exists and the conversion to the requested type is correct
168  @deprecated
169  */
170  bool getInfoAsLong(const std::string Key, long *Info) const OPENFLUID_DEPRECATED;
171 
172  /**
173  Gets an information as a long integer
174  @param[in] Key the requested information key
175  @param[out] Info the value corresponding to the requested key
176  @return true if the key exists and the conversion to the requested type is correct
177  */
178  bool getInfoAsLong(const std::string Key, long& Info) const;
179 
180  /**
181  Gets an information as a double
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
186  */
187  bool getInfoAsDouble(const std::string Key, double *Info) const OPENFLUID_DEPRECATED;
188 
189  /**
190  Gets an information as a double
191  @param[in] Key the requested information key
192  @param[out] Info the value corresponding to the requested key
193  @return true if the key exists and the conversion to the requested type is correct
194  */
195  bool getInfoAsDouble(const std::string Key, double& Info) const;
196 
197  /**
198  Gets an information as a DoubleValue
199  @param[in] Key the requested information key
200  @param[out] Info the value corresponding to the requested key
201  @return true if the key exists and the conversion to the requested type is correct
202  */
203  bool getInfoAsDoubleValue(const std::string Key, DoubleValue& Info) const;
204 
205  /**
206  Adds an information to the event
207  @param[in] Key the key of the added information
208  @param[in] Info the value of the added information
209  @return true if the adding is correct (key does not already exists)
210  */
211  bool addInfo(const std::string Key, const std::string Info);
212 
213  /**
214  Prints the content of the event to stdout
215  */
216  void println() const;
217 
218 };
219 
220 } } // namespace openfluid::core
221 
222 #endif /* __EVENT_HPP__ */
Class for management of date and time information.
Definition: DateTime.hpp:131
Definition: DoubleValue.hpp:103
Header of ...
EventInfosMap_t getInfos() const
Definition: Event.hpp:139
std::map< std::string, openfluid::core::StringValue > EventInfosMap_t
Definition: Event.hpp:64
Definition: Value.hpp:64
Class defining a discrete event, including attached information.
Definition: Event.hpp:61
DateTime getDateTime() const
Definition: Event.hpp:144
#define OPENFLUID_DEPRECATED
Definition: deprecation.hpp:55
class DLLEXPORT Event
Definition: EventsColl.hpp:52
int getInfosCount() const
Definition: Event.hpp:134
#define DLLEXPORT
Definition: dllexport.hpp:51