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 
39 #ifndef __OPENFLUID_FLUIDX_ADVANCEDDOMAINDESCRIPTOR_HPP__
40 #define __OPENFLUID_FLUIDX_ADVANCEDDOMAINDESCRIPTOR_HPP__
41 
42 
43 #include <map>
44 #include <set>
45 
46 #include <openfluid/core/TypeDefs.hpp>
47 #include <openfluid/dllexport.hpp>
49 
50 
51 namespace openfluid {
52 
53 namespace core {
54 class Event;
55 }
56 
57 namespace fluidx {
58 
59 class SpatialDomainDescriptor;
60 class SpatialUnitDescriptor;
61 class AttributesDescriptor;
62 
63 
64 // =====================================================================
65 // =====================================================================
66 
67 
69 {
70 
71  public:
72 
74 
75  std::map<openfluid::core::AttributeName_t, std::string*> Attributes;
76 
77  std::list<openfluid::fluidx::EventDescriptor*> EventsDescriptors;
78 
80  UnitDescriptor(&UnitDesc)
81  {
82  }
83 
84 };
85 
86 
87 // =====================================================================
88 // =====================================================================
89 
90 
92 {
93  public:
94 
95  typedef std::map<std::string, std::map<int, AdvancedUnitDescriptor> > UnitsByIdByClass_t;
96 
97  private:
98 
100 
101  /**
102  * Units by ID by ClassName
103  */
104  std::map<std::string, std::map<int, AdvancedUnitDescriptor> > m_Units;
105 
106  std::map<std::string, std::set<openfluid::core::AttributeName_t> > m_AttrsNames;
107 
108  void dispatchUnits();
109 
110  void dispatchAttributes();
111 
112  void checkUnitRelations() const;
113 
114  void checkUnitRelations(openfluid::fluidx::SpatialUnitDescriptor& Unit) const;
115 
116  void checkAttributesConsistency() const;
117 
118  void dispatchEvents();
119 
120 
121  public:
122 
124 
126 
127  bool isSpatialUnitExist(const std::string& ClassName, int ID) const;
128 
129  /**
130  @return May return an empty map. Never throws.
131  */
132  const std::map<std::string, std::map<int, AdvancedUnitDescriptor> >& spatialUnitsByIdByClass() const;
133 
134  /**
135  @throw openfluid::base::FrameworkException if Unit doesn't exist
136  @param ClassName
137  @param ID
138  @return
139  */
140  const AdvancedUnitDescriptor& spatialUnit(const std::string& ClassName, int ID) const;
141 
142  /**
143  @throw openfluid::base::FrameworkException if Unit doesn't exist
144  @param ClassName
145  @param ID
146  @return
147  */
148  const openfluid::fluidx::SpatialUnitDescriptor& spatialUnitDescriptor(const std::string& ClassName,
149  int ID) const;
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  @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  @param ClassName
179  @param ID
180  */
181  void deleteUnit(const std::string& ClassName, int ID);
182 
183  /**
184  @throw openfluid::base::FrameworkException if Unit or DataName doesn't exist
185  @param ClassName
186  @param ID
187  @param AttrName
188  @return
189  */
190  std::string& attribute(const std::string& ClassName, int ID,
191  const std::string& AttrName);
192 
193  /**
194  @param ClassName
195  @return An empty set if ClassName doesn't exist or has no attribute. Never throws.
196  */
197  std::set<std::string> getAttributesNames(const std::string& ClassName) const;
198 
199  /**
200  @throw openfluid::base::FrameworkException if ClassName doesn't exist
201  or if AttrName already exists for class ClassName
202  @param ClassName
203  @param AttrName
204  @param DefaultValue
205  */
206  void addAttribute(const std::string& ClassName, const std::string& AttrName,
207  const std::string& DefaultValue);
208 
209  /**
210  @throw openfluid::base::FrameworkException if ClassName doesn't exist
211  or if AttrName doesn't exist for class ClassName
212  @param ClassName
213  @param AttrName
214  */
215  void deleteAttribute(const std::string& ClassName, const std::string& AttrName);
216 
217  /**
218  Does nothing if NewDataName is the same as OldDataName
219  @throw openfluid::base::FrameworkException if ClassName doesn't exist
220  or if OldDataName doesn't exist for the class ClassName
221  @param ClassName
222  @param OldAttrName
223  @param NewAttrName
224  */
225  void renameAttribute(const std::string& ClassName, const std::string& OldAttrName,
226  const std::string& NewAttrName);
227 
228  /**
229  Adds an event
230  @param[in] UnitsClass The units class of the event
231  @param[in] UnitID The unit ID of the event
232  @param[in] Event The event definition
233  */
234  void addEvent(const openfluid::core::UnitsClass_t& UnitsClass, const openfluid::core::UnitID_t& UnitID,
235  const openfluid::core::Event& Event);
236 
237  /**
238  Deletes an event
239  @param[in] UnitsClass The units class of the event
240  @param[in] UnitID The unit ID of the event
241  @param[in] EventID The ID of the event to delete
242  */
243  void deleteEvent(const openfluid::core::UnitsClass_t& UnitsClass, const openfluid::core::UnitID_t& UnitID,
244  const openfluid::fluidx::EventID_t& EventID);
245 
246  /**
247  Modify an event
248  @param[in] EventID The ID of the event to modify
249  @param[in] Event The new content of the event
250  */
251  void modifyEvent(const openfluid::fluidx::EventID_t& EventID,
252  const openfluid::core::Event& Event);
253 
254  /**
255  Returns a pointer to the event descriptor corresponding to the event ID
256  @param[in] ID The ID of the event to delete
257  */
259 
260 
261  const std::list<openfluid::core::UnitClassID_t>& toSpatialUnits(const openfluid::core::UnitClassID_t Unit) const;
262 
263  const std::list<openfluid::core::UnitClassID_t>&
264  parentSpatialUnits(const openfluid::core::UnitClassID_t Unit) const;
265 
266  std::list<openfluid::core::UnitClassID_t> getFromSpatialUnits(const openfluid::core::UnitClassID_t Unit) const;
267 
268  std::list<openfluid::core::UnitClassID_t> getChildSpatialUnits(const openfluid::core::UnitClassID_t Unit) const;
269 
270  /**
271  @brief Add ToUnit to the list of "Tos" of FromUnit
272  @details Does nothing if the relation already exists
273  @throw openfluid::base::FrameworkException if FromUnit or ToUnit doesn't exist
274  */
275  void addFromToRelation(const openfluid::core::UnitClassID_t FromUnit,
276  const openfluid::core::UnitClassID_t ToUnit);
277 
278  /**
279  @brief Remove ToUnit from the list of "Tos" of FromUnit
280  @throw openfluid::base::FrameworkException if FromUnit or ToUnit doesn't exist or if the relation doesn't exists
281  */
282  void removeFromToRelation(const openfluid::core::UnitClassID_t FromUnit,
283  const openfluid::core::UnitClassID_t ToUnit);
284 
285  /**
286  @brief Add ChildUnit to the list of "Children" of ParentUnit
287  @details Does nothing if the relation already exists
288  @throw openfluid::base::FrameworkException if ParentUnit or ChildUnit doesn't exist
289  */
290  void addParentChildRelation(const openfluid::core::UnitClassID_t ParentUnit,
291  const openfluid::core::UnitClassID_t ChildUnit);
292 
293  /**
294  @brief Remove ChildUnit from the list of "Children" of ParentUnit
295  @throw openfluid::base::FrameworkException if ParentUnit or ChildUnit doesn't exist
296  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::FrameworkException if Unit doesn't exist
306  */
307  void clearRelations(const openfluid::core::UnitClassID_t Unit);
308 
309  void clearDomain();
310 };
311 
312 
313 } } // namespaces
314 
315 
316 #endif /* __OPENFLUID_FLUIDX_ADVANCEDDOMAINDESCRIPTOR_HPP__ */
317 
#define OPENFLUID_API
Definition: dllexport.hpp:87
std::map< openfluid::core::AttributeName_t, std::string * > Attributes
Definition: AdvancedDomainDescriptor.hpp:75
AdvancedUnitDescriptor(openfluid::fluidx::SpatialUnitDescriptor &UnitDesc)
Definition: AdvancedDomainDescriptor.hpp:79
Definition: ApplicationException.hpp:47
openfluid::fluidx::SpatialUnitDescriptor * UnitDescriptor
Definition: AdvancedDomainDescriptor.hpp:73
Definition: SpatialDomainDescriptor.hpp:54
std::string UnitsClass_t
Definition: TypeDefs.hpp:71
std::pair< UnitsClass_t, UnitID_t > UnitClassID_t
Definition: TypeDefs.hpp:91
std::list< openfluid::fluidx::EventDescriptor * > EventsDescriptors
Definition: AdvancedDomainDescriptor.hpp:77
Definition: EventDescriptor.hpp:55
unsigned int UnitID_t
Definition: TypeDefs.hpp:61
Definition: AdvancedDomainDescriptor.hpp:91
Definition: Event.hpp:59
unsigned long long EventID_t
Definition: EventDescriptor.hpp:52
Definition: SpatialUnitDescriptor.hpp:52
std::map< std::string, std::map< int, AdvancedUnitDescriptor > > UnitsByIdByClass_t
Definition: AdvancedDomainDescriptor.hpp:95
Definition: AdvancedDomainDescriptor.hpp:68