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 
35  @author Aline LIBRES <aline.libres@gmail.com>
36  */
37 
38 #ifndef __OPENFLUID_FLUIDX_ADVANCEDDOMAINDESCRIPTOR_HPP__
39 #define __OPENFLUID_FLUIDX_ADVANCEDDOMAINDESCRIPTOR_HPP__
40 
41 #include <openfluid/core/TypeDefs.hpp>
42 #include <openfluid/dllexport.hpp>
44 
45 #include <map>
46 #include <set>
47 
48 namespace openfluid {
49 
50 namespace core {
51 class Event;
52 }
53 
54 namespace fluidx {
55 
56 class SpatialDomainDescriptor;
57 class SpatialUnitDescriptor;
58 class AttributesDescriptor;
59 
60 
61 // =====================================================================
62 // =====================================================================
63 
64 
66 {
67 
68  public:
69 
71 
72  std::map<openfluid::core::AttributeName_t, std::string*> Attributes;
73 
74  std::list<openfluid::fluidx::EventDescriptor*> EventsDescriptors;
75 
77  UnitDescriptor(&UnitDesc)
78  {
79  }
80 
81 };
82 
83 
84 // =====================================================================
85 // =====================================================================
86 
87 
89 {
90  public:
91 
92  typedef std::map<std::string, std::map<int, AdvancedUnitDescriptor> > UnitsByIdByClass_t;
93 
94  private:
95 
97 
98  /**
99  * Units by ID by ClassName
100  */
101  std::map<std::string, std::map<int, AdvancedUnitDescriptor> > m_Units;
102 
103  std::map<std::string, std::set<openfluid::core::AttributeName_t> > m_AttrsNames;
104 
105  void dispatchUnits();
106 
107  void dispatchAttributes();
108 
109  void checkUnitRelations() const;
110 
111  void checkUnitRelations(openfluid::fluidx::SpatialUnitDescriptor& Unit) const;
112 
113  void checkAttributesConsistency() const;
114 
115  void dispatchEvents();
116 
117 
118  public:
119 
121 
123 
124  bool isSpatialUnitExist(const std::string& ClassName, int ID) const;
125 
126  /**
127  *
128  * @return May return an empty map. Never throws.
129  */
130  const std::map<std::string, std::map<int, AdvancedUnitDescriptor> >& spatialUnitsByIdByClass() const;
131 
132  /**
133  * @throw openfluid::base::FrameworkException if Unit doesn't exist
134  * @param ClassName
135  * @param ID
136  * @return
137  */
138  const AdvancedUnitDescriptor& spatialUnit(const std::string& ClassName, int ID) const;
139 
140  /**
141  * @throw openfluid::base::FrameworkException if Unit doesn't exist
142  * @param ClassName
143  * @param ID
144  * @return
145  */
146  const openfluid::fluidx::SpatialUnitDescriptor& spatialUnitDescriptor(const std::string& ClassName,
147  int ID) const;
148 
149  /**
150  *
151  * @param ClassName
152  * @return An empty set if ClassName doesn't exist. Never throws.
153  */
154  std::set<int> getIDsOfClass(const std::string& ClassName) const;
155 
156  bool isClassNameExists(const std::string& ClassName) const;
157 
158  /**
159  *
160  * @return May return an empty set. Never throws.
161  */
162  std::set<std::string> getClassNames() const;
163 
164  unsigned int getUnitsCount() const;
165 
166  /**
167  @details Add this UnitDesc ID to the descriptor for all attributes of this UnitDesc class,
168  with a default value of "-"
169  @warning Invalidate UnitDesc
170  @throw openfluid::base::FrameworkException if Unit already exists or if Unit has a relation
171  with a non-existent Unit
172  @param UnitDesc
173  */
174  void addUnit(openfluid::fluidx::SpatialUnitDescriptor* 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::FrameworkException if Unit or DataName doesn't exist
186  * @param ClassName
187  * @param ID
188  * @param AttrName
189  * @return
190  */
191  std::string& attribute(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::FrameworkException 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::FrameworkException 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::FrameworkException 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::UnitsClass_t& UnitsClass, const openfluid::core::UnitID_t& UnitID,
237  const openfluid::core::Event& Event);
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::UnitsClass_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,
254  const openfluid::core::Event& Event);
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>& toSpatialUnits(const openfluid::core::UnitClassID_t Unit) const;
264 
265  const std::list<openfluid::core::UnitClassID_t>&
266  parentSpatialUnits(const openfluid::core::UnitClassID_t Unit) const;
267 
268  std::list<openfluid::core::UnitClassID_t> getFromSpatialUnits(const openfluid::core::UnitClassID_t Unit) const;
269 
270  std::list<openfluid::core::UnitClassID_t> getChildSpatialUnits(const openfluid::core::UnitClassID_t Unit) const;
271 
272  /**
273  * @brief Add ToUnit to the list of "Tos" of FromUnit
274  * @details Does nothing if the relation already exists
275  * @throw openfluid::base::FrameworkException if FromUnit or ToUnit doesn't exist
276  */
277  void addFromToRelation(const openfluid::core::UnitClassID_t FromUnit,
278  const openfluid::core::UnitClassID_t ToUnit);
279 
280  /**
281  * @brief Remove ToUnit from the list of "Tos" of FromUnit
282  * @throw openfluid::base::FrameworkException if FromUnit or ToUnit doesn't exist or if the relation doesn't exists
283  */
284  void removeFromToRelation(const openfluid::core::UnitClassID_t FromUnit,
285  const openfluid::core::UnitClassID_t ToUnit);
286 
287  /**
288  * @brief Add ChildUnit to the list of "Children" of ParentUnit
289  * @details Does nothing if the relation already exists
290  * @throw openfluid::base::FrameworkException if ParentUnit or ChildUnit doesn't exist
291  */
292  void addParentChildRelation(const openfluid::core::UnitClassID_t ParentUnit,
293  const openfluid::core::UnitClassID_t ChildUnit);
294 
295  /**
296  @brief Remove ChildUnit from the list of "Children" of ParentUnit
297  @throw openfluid::base::FrameworkException if ParentUnit or ChildUnit doesn't exist
298  or if the relation doesn't exists
299  */
300  void removeParentChildRelation(
301  const openfluid::core::UnitClassID_t ParentUnit,
302  const openfluid::core::UnitClassID_t ChildUnit);
303 
304  /**
305  * @brief Clear the list of "Tos" and "Parents" of Unit,
306  * and remove Unit from the list of "Tos" and "Parents" of all other Units of the Domain
307  * @throw openfluid::base::FrameworkException if Unit doesn't exist
308  */
309  void clearRelations(const openfluid::core::UnitClassID_t Unit);
310 
311  void clearDomain();
312 };
313 
314 
315 // =====================================================================
316 // =====================================================================
317 
318 
319 } } // namespaces
320 
321 #endif /* __OPENFLUID_FLUIDX_ADVANCEDDOMAINDESCRIPTOR_HPP__ */
322 
std::list< openfluid::fluidx::EventDescriptor * > EventsDescriptors
Definition: AdvancedDomainDescriptor.hpp:74
unsigned int UnitID_t
Definition: TypeDefs.hpp:61
Definition: SpatialUnitDescriptor.hpp:51
Definition: EventDescriptor.hpp:53
AdvancedUnitDescriptor(openfluid::fluidx::SpatialUnitDescriptor &UnitDesc)
Definition: AdvancedDomainDescriptor.hpp:76
openfluid::fluidx::SpatialUnitDescriptor * UnitDescriptor
Definition: AdvancedDomainDescriptor.hpp:70
std::string UnitsClass_t
Definition: TypeDefs.hpp:71
std::map< std::string, std::map< int, AdvancedUnitDescriptor > > UnitsByIdByClass_t
Definition: AdvancedDomainDescriptor.hpp:92
Definition: Event.hpp:59
Definition: AdvancedDomainDescriptor.hpp:65
std::map< openfluid::core::AttributeName_t, std::string * > Attributes
Definition: AdvancedDomainDescriptor.hpp:72
unsigned long long EventID_t
Definition: EventDescriptor.hpp:51
std::pair< UnitsClass_t, UnitID_t > UnitClassID_t
Definition: TypeDefs.hpp:91
Definition: AdvancedDomainDescriptor.hpp:88
#define OPENFLUID_API
Definition: dllexport.hpp:87
Definition: SpatialDomainDescriptor.hpp:53