All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AdvancedDomainDescriptor.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  \file AdvancedDomainDescriptor.hpp
34  \brief Header of ...
35 
36  \author Aline LIBRES <aline.libres@gmail.com>
37  */
38 
39 #ifndef ADVANCEDDOMAINDESCRIPTOR_HPP_
40 #define ADVANCEDDOMAINDESCRIPTOR_HPP_
41 
43 #include <openfluid/dllexport.hpp>
45 
46 #include <map>
47 #include <set>
48 
49 namespace openfluid {
50 
51 namespace core {
52 class Event;
53 }
54 
55 namespace fluidx {
56 
57 class DomainDescriptor;
58 class UnitDescriptor;
59 class AttributesDescriptor;
60 
61 
62 // =====================================================================
63 // =====================================================================
64 
65 
67 {
68 
69  public:
70 
72 
73  std::map<openfluid::core::AttributeName_t, std::string*> Attributes;
74 
75  std::list<openfluid::fluidx::EventDescriptor*> EventsDescriptors;
76 
78  UnitDescriptor(&UnitDesc)
79  {
80  }
81 
82 };
83 
84 
85 // =====================================================================
86 // =====================================================================
87 
88 
90 {
91  public:
92 
93  typedef std::map<std::string, std::map<int, AdvancedUnitDescriptor> > UnitsByIdByClass_t;
94 
95  private:
96 
98 
99  /**
100  * Units by ID by ClassName
101  */
102  std::map<std::string, std::map<int, AdvancedUnitDescriptor> > m_Units;
103 
104  std::map<std::string, std::set<openfluid::core::AttributeName_t> > m_AttrsNames;
105 
106  void dispatchUnits();
107 
108  void dispatchAttributes();
109 
110  void checkUnitRelations() const;
111 
112  void checkUnitRelations(openfluid::fluidx::UnitDescriptor& Unit) const;
113 
114  void checkAttributesConsistency() const;
115 
116  void dispatchEvents();
117 
118 
119  public:
120 
122 
124 
125  bool isUnitExist(const std::string& ClassName, int ID) const;
126 
127  /**
128  *
129  * @return May return an empty map. Never throws.
130  */
131  const std::map<std::string, std::map<int, AdvancedUnitDescriptor> >& getUnitsByIdByClass() const;
132 
133  /**
134  * @throw openfluid::base::OFException if Unit doesn't exist
135  * @param ClassName
136  * @param ID
137  * @return
138  */
139  const AdvancedUnitDescriptor& getUnit(const std::string& ClassName, int ID) const;
140 
141  /**
142  * @throw openfluid::base::OFException if Unit doesn't exist
143  * @param ClassName
144  * @param ID
145  * @return
146  */
147  const openfluid::fluidx::UnitDescriptor& getUnitDescriptor(
148  const std::string& ClassName, int ID) const;
149 
150  /**
151  *
152  * @param ClassName
153  * @return An empty set if ClassName doesn't exist. Never throws.
154  */
155  std::set<int> getIDsOfClass(const std::string& ClassName) const;
156 
157  bool isClassNameExists(const std::string& ClassName) const;
158 
159  /**
160  *
161  * @return May return an empty set. Never throws.
162  */
163  std::set<std::string> getClassNames() const;
164 
165  unsigned int getUnitsCount() const;
166 
167  /**
168  * @details Add this UnitDesc ID to the descriptor for all attributes of this UnitDesc class,
169  * with a default value of "-"
170  * @warning Invalidate UnitDesc
171  * @throw openfluid::base::OFException if Unit already exists or if Unit has a relation with a non-existent Unit
172  * @param UnitDesc
173  */
174  void addUnit(openfluid::fluidx::UnitDescriptor* UnitDesc);
175 
176  /**
177  * Does nothing if Unit doesn't exist
178  *
179  * @param ClassName
180  * @param ID
181  */
182  void deleteUnit(const std::string& ClassName, int ID);
183 
184  /**
185  * @throw openfluid::base::OFException if Unit or DataName doesn't exist
186  * @param ClassName
187  * @param ID
188  * @param AttrName
189  * @return
190  */
191  std::string& getAttribute(const std::string& ClassName, int ID,
192  const std::string& AttrName);
193 
194  /**
195  *
196  * @param ClassName
197  * @return An empty set if ClassName doesn't exist or has no attribute. Never throws.
198  */
199  std::set<std::string> getAttributesNames(const std::string& ClassName) const;
200 
201  /**
202  * @throw openfluid::base::OFException if ClassName doesn't exist
203  * or if AttrName already exists for class ClassName
204  * @param ClassName
205  * @param AttrName
206  * @param DefaultValue
207  */
208  void addAttribute(const std::string& ClassName, const std::string& AttrName,
209  const std::string& DefaultValue);
210 
211  /**
212  * @throw openfluid::base::OFException if ClassName doesn't exist
213  * or if AttrName doesn't exist for class ClassName
214  * @param ClassName
215  * @param AttrName
216  */
217  void deleteAttribute(const std::string& ClassName, const std::string& AttrName);
218 
219  /**
220  * Does nothing if NewDataName is the same as OldDataName
221  * @throw openfluid::base::OFException if ClassName doesn't exist
222  * or if OldDataName doesn't exist for the class ClassName
223  * @param ClassName
224  * @param OldAttrName
225  * @param NewAttrName
226  */
227  void renameAttribute(const std::string& ClassName, const std::string& OldAttrName,
228  const std::string& NewAttrName);
229 
230  /**
231  Adds an event
232  @param[in] UnitsClass The units class of the event
233  @param[in] UnitID The unit ID of the event
234  @param[in] Event The event definition
235  */
236  void addEvent(const openfluid::core::UnitClass_t& UnitsClass, const openfluid::core::UnitID_t& UnitID,
238 
239  /**
240  Deletes an event
241  @param[in] UnitsClass The units class of the event
242  @param[in] UnitID The unit ID of the event
243  @param[in] EventID The ID of the event to delete
244  */
245  void deleteEvent(const openfluid::core::UnitClass_t& UnitsClass, const openfluid::core::UnitID_t& UnitID,
246  const openfluid::fluidx::EventID_t& EventID);
247 
248  /**
249  Modify an event
250  @param[in] EventID The ID of the event to modify
251  @param[in] Event The new content of the event
252  */
253  void modifyEvent(const openfluid::fluidx::EventID_t& EventID,
255 
256  /**
257  Returns a pointer to the event descriptor corresponding to the event ID
258  @param[in] ID The ID of the event to delete
259  */
261 
262 
263  const std::list<openfluid::core::UnitClassID_t>& getUnitsToOf(const openfluid::core::UnitClassID_t Unit) const;
264 
265  const std::list<openfluid::core::UnitClassID_t>& getUnitsParentsOf(const openfluid::core::UnitClassID_t Unit) const;
266 
267  std::list<openfluid::core::UnitClassID_t> getUnitsFromOf(const openfluid::core::UnitClassID_t Unit) const;
268 
269  std::list<openfluid::core::UnitClassID_t> getUnitsChildrenOf(const openfluid::core::UnitClassID_t Unit) const;
270 
271  /**
272  * @brief Add ToUnit to the list of "Tos" of FromUnit
273  * @details Does nothing if the relation already exists
274  * @throw openfluid::base::OFException if FromUnit or ToUnit doesn't exist
275  */
276  void addFromToRelation(const openfluid::core::UnitClassID_t FromUnit,
277  const openfluid::core::UnitClassID_t ToUnit);
278 
279  /**
280  * @brief Remove ToUnit from the list of "Tos" of FromUnit
281  * @throw openfluid::base::OFException if FromUnit or ToUnit doesn't exist or if the relation doesn't exists
282  */
283  void removeFromToRelation(const openfluid::core::UnitClassID_t FromUnit,
284  const openfluid::core::UnitClassID_t ToUnit);
285 
286  /**
287  * @brief Add ChildUnit to the list of "Children" of ParentUnit
288  * @details Does nothing if the relation already exists
289  * @throw openfluid::base::OFException if ParentUnit or ChildUnit doesn't exist
290  */
291  void addParentChildRelation(const openfluid::core::UnitClassID_t ParentUnit,
292  const openfluid::core::UnitClassID_t ChildUnit);
293 
294  /**
295  * @brief Remove ChildUnit from the list of "Children" of ParentUnit
296  * @throw openfluid::base::OFException if ParentUnit or ChildUnit doesn't exist or if the relation doesn't exists
297  */
298  void removeParentChildRelation(
299  const openfluid::core::UnitClassID_t ParentUnit,
300  const openfluid::core::UnitClassID_t ChildUnit);
301 
302  /**
303  * @brief Clear the list of "Tos" and "Parents" of Unit,
304  * and remove Unit from the list of "Tos" and "Parents" of all other Units of the Domain
305  * @throw openfluid::base::OFException if Unit doesn't exist
306  */
307  void clearRelations(const openfluid::core::UnitClassID_t Unit);
308 
309  void clearDomain();
310 };
311 
312 
313 // =====================================================================
314 // =====================================================================
315 
316 
317 } } // namespaces
318 
319 #endif /* ADVANCEDDOMAINDESCRIPTOR_HPP_ */
320 
openfluid::fluidx::UnitDescriptor * UnitDescriptor
Definition: AdvancedDomainDescriptor.hpp:71
Definition: AdvancedDomainDescriptor.hpp:66
std::string UnitClass_t
Definition: TypeDefs.hpp:69
std::map< openfluid::core::AttributeName_t, std::string * > Attributes
Definition: AdvancedDomainDescriptor.hpp:73
std::pair< UnitClass_t, UnitID_t > UnitClassID_t
Definition: TypeDefs.hpp:82
std::map< std::string, std::map< int, AdvancedUnitDescriptor > > UnitsByIdByClass_t
Definition: AdvancedDomainDescriptor.hpp:93
Definition: UnitDescriptor.hpp:51
unsigned int UnitID_t
Definition: TypeDefs.hpp:59
Definition: DomainDescriptor.hpp:53
Definition: AdvancedDomainDescriptor.hpp:89
AdvancedUnitDescriptor(openfluid::fluidx::UnitDescriptor &UnitDesc)
Definition: AdvancedDomainDescriptor.hpp:77
Class defining a discrete event, including attached information.
Definition: Event.hpp:61
unsigned long long EventID_t
Definition: EventDescriptor.hpp:51
class DLLEXPORT Event
Definition: EventsColl.hpp:52
std::list< openfluid::fluidx::EventDescriptor * > EventsDescriptors
Definition: AdvancedDomainDescriptor.hpp:75
Definition: EventDescriptor.hpp:53
#define DLLEXPORT
Definition: dllexport.hpp:51