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