Documentation for OpenFLUID 2.2.2
Loading...
Searching...
No Matches
SpatialDomainDescriptor.hpp
Go to the documentation of this file.
1/*
2
3 This file is part of OpenFLUID software
4 Copyright(c) 2021-2026, INRAE
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 @file SpatialDomainDescriptor.hpp
35
36 @author Jean-Christophe FABRE <jean-christophe.fabre@inra.fr>
37 @author Aline LIBRES <aline.libres@gmail.com>
38*/
39
40
41#ifndef __OPENFLUID_FLUIDX_SPATIALDOMAINDESCRIPTOR_HPP__
42#define __OPENFLUID_FLUIDX_SPATIALDOMAINDESCRIPTOR_HPP__
43
44
45#include <map>
46#include <set>
47
48#include <openfluid/core/TypeDefs.hpp>
51
52
53namespace openfluid {
54
55namespace core {
56class Event;
57}
58
59namespace fluidx {
60
61
63{
64 public:
65
66 typedef std::map<openfluid::core::UnitID_t, SpatialUnitDescriptor> SpatialUnitsByID_t;
67
68 typedef std::map<openfluid::core::UnitsClass_t,SpatialUnitsByID_t> SpatialUnitsByIDByClass_t;
69
70
71 private:
72
73 /**
74 Units by ID by ClassName
75 */
76 SpatialUnitsByIDByClass_t m_SpatialUnits;
77
78 /**
79 Attributes names by ClassName
80 */
81 std::map<openfluid::core::UnitsClass_t, std::set<openfluid::core::AttributeName_t>> m_AttributesNames;
82
83 /**
84 Checks if the spatial relations (From-To, Parent-Child) are consistent for the given spatial unit
85 @throw openfluid::base::FrameworkException if spatial relations are not consistent
86 */
87 void checkUnitRelations(const openfluid::fluidx::SpatialUnitDescriptor& Unit) const;
88
89
90 public:
91
93
96
97 /**
98 Returns a reference to the structure of spatial units descriptors
99 @return a reference to the structure
100 */
102 {
103 return m_SpatialUnits;
104 }
105
106 /**
107 Returns a const reference to the structure of spatial units descriptors
108 @return a constreference to the structure
109 */
111 {
112 return m_SpatialUnits;
113 }
114
115 /**
116 Checks if spatial units relations (From-To, Parent-Child) are consistent.
117 @throw openfluid::base::FrameworkException if spatial units relations are not consistent
118 */
120
121 /**
122 Checks if spatial attributes are consistent.
123 @throw openfluid::base::FrameworkException if spatial attributes are not consistent
124 */
126
127 /**
128 Returns true if the spatial unit descriptor exists for the given units class and unit ID
129 @param[in] ClassName the name of the units class
130 @param[in] ID the ID of the spatial
131 @return true if the spatial unit descriptor exists
132 */
134 const openfluid::core::UnitID_t& ID) const;
135
136 /**
137 Returns a const reference to the spatial unit descriptor identified by a units class and a unit ID
138 @param[in] ClassName the name of the units class
139 @param[in] ID the ID of the spatial
140 @return a const reference to the spatial unit if found
141 @throw openfluid::base::FrameworkException if spatial unit is not found
142 */
144 const openfluid::core::UnitID_t& ID) const;
145
146 /**
147 Returns the spatial units IDs for a given units class
148 @param[in] ClassName the name of the spatial units class
149 @return a set of IDs for the given class, an empty set if the units class does not exist.
150 */
151 std::set<int> getIDsOfClass(const openfluid::core::UnitsClass_t& ClassName) const;
152
153 /**
154 Returns true if the spatial units class exists
155 @param[in] ClassName the name of the units class
156 @return true if the units class exists
157 */
159
160 /**
161 Returns the names of units classes of the spatial domain
162 @return a set of units class names
163 */
164 std::set<std::string> getClassNames() const;
165
166 /**
167 Returns the count of all spatial units in the spatial domain
168 @return the count of spatial units
169 */
170 unsigned int getUnitsCount() const;
171
172 /**
173 Returns the count of spatial units for a given units class in the spatial domain
174 @return the count of spatial units
175 */
176 unsigned int getUnitsCount(const openfluid::core::UnitsClass_t& ClassName) const;
177
178 /**
179 Adds a spatial unit to the spatial domain
180 @param[in] UnitDesc the spatial unit descriptor to add
181 @param[in] Check enables internal checks when set to true (default value = true)
182 @throw openfluid::base::FrameworkException if the spatial unit already exists, or if Check is true
183 and the spatial unit has a wrong spatial relation
184 */
185 void addUnit(const openfluid::fluidx::SpatialUnitDescriptor& UnitDesc, bool Check = true);
186
187 /**
188 Removes a spatial unit
189 @param[in] ClassName the units class of the spatial unit to remove
190 @param[in] ID the ID of the spatial unit to remove
191 */
193
194 /**
195 Returns a const reference to the list of units class and ID linked with a "To" relation to the given spatial unit
196 @param[in] Unit units class and ID of the spatial unit
197 @throw openfluid::base::FrameworkException if the spatial unit does not exists
198 @return a const reference to the list of the "To" spatial units
199 */
200 const std::list<openfluid::core::UnitClassID_t>& toSpatialUnits(const openfluid::core::UnitClassID_t& Unit) const;
201
202 /**
203 Returns a const reference to the list of units class and ID linked with a "Parent" relation
204 to the given spatial unit
205 @param[in] Unit units class and ID of the spatial unit
206 @throw openfluid::base::FrameworkException if the spatial unit does not exists
207 @return a const reference to the list of the "Parent" spatial units
208 */
209 const std::list<openfluid::core::UnitClassID_t>&
211
212 /**
213 Builds a list of units class and ID linked with a "From" relation
214 to the given spatial unit
215 @param[in] Unit units class and ID of the spatial unit
216 @throw openfluid::base::FrameworkException if the spatial unit does not exists
217 @return the list of the "From" spatial units, may be empty
218 */
219 std::list<openfluid::core::UnitClassID_t> getFromSpatialUnits(const openfluid::core::UnitClassID_t& Unit) const;
220
221 /**
222 Builds a list of units class and ID linked with a "Child" relation
223 to the given spatial unit
224 @param[in] Unit units class and ID of the spatial unit
225 @throw openfluid::base::FrameworkException if the spatial unit does not exists
226 @return the list of the "Child" spatial units, may be empty
227 */
228 std::list<openfluid::core::UnitClassID_t> getChildSpatialUnits(const openfluid::core::UnitClassID_t& Unit) const;
229
230 /**
231 Adds the ToUnit to the list of "To" relations of FromUnit. It does nothing if the relation already exists.
232 @param[in] FromUnit the source spatial unit of the relation
233 @param[in] ToUnit the target spatial unit of the relation
234 @throw openfluid::base::FrameworkException if FromUnit or ToUnit does not exist
235 */
237 const openfluid::core::UnitClassID_t& ToUnit);
238
239 /**
240 Removes the ToUnit from the list of "To" relations of FromUnit. It does nothing if the relation does not exists.
241 @param[in] FromUnit the source spatial unit of the relation
242 @param[in] ToUnit the target spatial unit of the relation
243 @throw openfluid::base::FrameworkException if FromUnit does not exist
244 */
246 const openfluid::core::UnitClassID_t& ToUnit);
247
248 /**
249 Adds the ParentUnit to the list of "Parent" relations of ChildUnit.
250 It does nothing if the relation already exists.
251 @param[in] ParentUnit the source spatial unit of the relation
252 @param[in] ChildUnit the target spatial unit of the relation
253 @throw openfluid::base::FrameworkException if ParentUnit or ChildUnit does not exist
254 */
256 const openfluid::core::UnitClassID_t& ChildUnit);
257
258 /**
259 Removes the ParentUnit from the list of "Parent" relations of ChildUnit.
260 It does nothing if the relation does not exists.
261 @param[in] ParentUnit the source spatial unit of the relation
262 @param[in] ChildUnit the target spatial unit of the relation
263 @throw openfluid::base::FrameworkException if ChildUnit does not exist
264 */
266 const openfluid::core::UnitClassID_t& ChildUnit);
267
268 /**
269 Removes all relations related to the given spatial unit.
270 @param[in] Unit units class and ID of the spatial unit
271 @throw openfluid::base::FrameworkException if the spatial unit does not exist
272 */
274
275 /**
276 Gets the value of a spatial attribute
277 @param[in] ClassName the units class of the spatial unit
278 @param[in] ID the ID of the spatial unit
279 @param[in] AttrName the name of the attribute
280 @return the value of the attribute as a string
281 @throw openfluid::base::FrameworkException if the spatial unit or the attribute does not exist
282 */
283 std::string getAttribute(const openfluid::core::UnitsClass_t& ClassName,
285 const openfluid::core::AttributeName_t& AttrName) const;
286
287 /**
288 Sets the value of an attribute on a spatial unit
289 @param[in] ClassName the units class of the spatial unit
290 @param[in] ID the ID of the spatial unit
291 @param[in] AttrName the name of the attribute
292 @param[in] AttrValue the value of the attribute
293 @throw openfluid::base::FrameworkException if the spatial unit or the attribute does not exist
294 */
297 const openfluid::core::AttributeName_t& AttrName,
298 const std::string& AttrValue);
299
300 /**
301 Returns the attributes names for a given units class
302 @param ClassName the units class of the spatial unit
303 @return a set of attributes names for the given class, an empty set if the units class does not exist.
304 */
305 std::set<std::string> getAttributesNames(const openfluid::core::UnitsClass_t& ClassName) const;
306
307 /**
308 @param[in] ClassName the units class of the spatial unit
309 @param[in] AttrName the name of the attribute
310 @param[in] DefaultValue the value of the attribute
311 @param[in] Check enables internal checks when set to true (default value = true)
312 @throw openfluid::base::FrameworkException if the spatial unit does not exist,
313 or if Check is true and the attribute already exists
314 */
315 void addAttribute(const openfluid::core::UnitsClass_t& ClassName, const std::string& AttrName,
316 const std::string& DefaultValue,
317 bool Check = true);
318
319 /**
320 Deletes an attribute for the given units class
321 @param[in] ClassName the units class of the spatial unit
322 @param[in] AttrName the name of the attribute
323 @throw openfluid::base::FrameworkException if the units class or attribute does not exist
324 */
325 void deleteAttribute(const openfluid::core::UnitsClass_t& ClassName, const std::string& AttrName);
326
327 /**
328 Renames an attribute
329 @param[in] ClassName the units class of the spatial unit
330 @param[in] OldAttrName the old name of the attribute
331 @param[in] NewAttrName the new name of the attribute
332 @throw openfluid::base::FrameworkException if the units class or attribute does not exist
333 */
334 void renameAttribute(const openfluid::core::UnitsClass_t& ClassName, const std::string& OldAttrName,
335 const std::string& NewAttrName);
336
337 /**
338 Adds an event from an event descriptor. If the spatial unit of the event does not exist, the event is ignored
339 @param[in] EvDesc the event descriptor to add
340 */
342
343 /**
344 Adds an event from an event definition. If the spatial unit of the event does not exist, the event is ignored
345 @param[in] UnitsClass the spatial units class
346 @param[in] UnitID the spatial unit ID
347 @param[in] Event the event definition
348 @return the ID assigned to the added event
349 */
351 const openfluid::core::Event& Event);
352
353 /**
354 Deletes an event
355 @param[in] UnitsClass the spatial units class
356 @param[in] UnitID the spatial unit ID
357 @param[in] EventID the ID of the event to delete
358 @throw openfluid::base::FrameworkException if the spatial units does not exist
359 */
361 const openfluid::fluidx::EventID_t& EventID);
362
363 /**
364 Modify an event
365 @param[in] EventID the ID of the event to modify
366 @param[in] Event the new definition of the event
367 */
369 const openfluid::core::Event& Event);
370
371 /**
372 Returns a reference to the event descriptor corresponding to the event ID
373 @param[in] ID The ID of the event
374 @throw openfluid::base::FrameworkException if the event ID does not exist
375 */
377
378 /**
379 Returns a const reference to the event descriptor corresponding to the event ID
380 @param[in] ID The ID of the event
381 @throw openfluid::base::FrameworkException if the event ID does not exist
382 */
384
385 /**
386 Clears the spatial domain
387 */
389};
390
391
392} } // namespaces
393
394
395#endif /* __OPENFLUID_FLUIDX_SPATIALDOMAINDESCRIPTOR_HPP__ */
Definition Event.hpp:69
Definition EventDescriptor.hpp:56
Definition SpatialDomainDescriptor.hpp:63
bool isClassNameExists(const openfluid::core::UnitsClass_t &ClassName) const
std::string getAttribute(const openfluid::core::UnitsClass_t &ClassName, const openfluid::core::UnitID_t &ID, const openfluid::core::AttributeName_t &AttrName) const
void modifyEvent(const openfluid::fluidx::EventID_t &EventID, const openfluid::core::Event &Event)
void addUnit(const openfluid::fluidx::SpatialUnitDescriptor &UnitDesc, bool Check=true)
const std::list< openfluid::core::UnitClassID_t > & parentSpatialUnits(const openfluid::core::UnitClassID_t &Unit) const
void deleteUnit(const openfluid::core::UnitsClass_t &ClassName, const openfluid::core::UnitID_t &ID)
EventID_t addEvent(const openfluid::core::UnitsClass_t &UnitsClass, const openfluid::core::UnitID_t &UnitID, const openfluid::core::Event &Event)
std::set< std::string > getClassNames() const
openfluid::fluidx::EventDescriptor & event(const openfluid::fluidx::EventID_t &ID)
void deleteEvent(const openfluid::core::UnitsClass_t &UnitsClass, const openfluid::core::UnitID_t &UnitID, const openfluid::fluidx::EventID_t &EventID)
SpatialUnitsByIDByClass_t & spatialUnits()
Definition SpatialDomainDescriptor.hpp:101
void clearRelations(const openfluid::core::UnitClassID_t &Unit)
void addParentChildRelation(const openfluid::core::UnitClassID_t &ParentUnit, const openfluid::core::UnitClassID_t &ChildUnit)
std::map< openfluid::core::UnitID_t, SpatialUnitDescriptor > SpatialUnitsByID_t
Definition SpatialDomainDescriptor.hpp:66
void addEvent(const openfluid::fluidx::EventDescriptor &EvDesc)
std::set< std::string > getAttributesNames(const openfluid::core::UnitsClass_t &ClassName) const
const SpatialUnitDescriptor & spatialUnit(const openfluid::core::UnitsClass_t &ClassName, const openfluid::core::UnitID_t &ID) const
void removeFromToRelation(const openfluid::core::UnitClassID_t &FromUnit, const openfluid::core::UnitClassID_t &ToUnit)
void removeParentChildRelation(const openfluid::core::UnitClassID_t &ParentUnit, const openfluid::core::UnitClassID_t &ChildUnit)
std::map< openfluid::core::UnitsClass_t, SpatialUnitsByID_t > SpatialUnitsByIDByClass_t
Definition SpatialDomainDescriptor.hpp:68
std::list< openfluid::core::UnitClassID_t > getChildSpatialUnits(const openfluid::core::UnitClassID_t &Unit) const
const SpatialUnitsByIDByClass_t & spatialUnits() const
Definition SpatialDomainDescriptor.hpp:110
void addAttribute(const openfluid::core::UnitsClass_t &ClassName, const std::string &AttrName, const std::string &DefaultValue, bool Check=true)
~SpatialDomainDescriptor()
Definition SpatialDomainDescriptor.hpp:94
void setAttribute(const openfluid::core::UnitsClass_t &ClassName, const openfluid::core::UnitID_t &ID, const openfluid::core::AttributeName_t &AttrName, const std::string &AttrValue)
std::list< openfluid::core::UnitClassID_t > getFromSpatialUnits(const openfluid::core::UnitClassID_t &Unit) const
void deleteAttribute(const openfluid::core::UnitsClass_t &ClassName, const std::string &AttrName)
std::set< int > getIDsOfClass(const openfluid::core::UnitsClass_t &ClassName) const
const openfluid::fluidx::EventDescriptor & event(const openfluid::fluidx::EventID_t &ID) const
bool isSpatialUnitExist(const openfluid::core::UnitsClass_t &ClassName, const openfluid::core::UnitID_t &ID) const
const std::list< openfluid::core::UnitClassID_t > & toSpatialUnits(const openfluid::core::UnitClassID_t &Unit) const
unsigned int getUnitsCount(const openfluid::core::UnitsClass_t &ClassName) const
void addFromToRelation(const openfluid::core::UnitClassID_t &FromUnit, const openfluid::core::UnitClassID_t &ToUnit)
void renameAttribute(const openfluid::core::UnitsClass_t &ClassName, const std::string &OldAttrName, const std::string &NewAttrName)
Definition SpatialUnitDescriptor.hpp:53
#define OPENFLUID_API
Definition dllexport.hpp:86
unsigned int UnitID_t
Definition TypeDefs.hpp:70
std::string UnitsClass_t
Definition TypeDefs.hpp:98
std::string AttributeName_t
Definition TypeDefs.hpp:117
std::pair< UnitsClass_t, UnitID_t > UnitClassID_t
Definition TypeDefs.hpp:136
unsigned long long EventID_t
Definition EventDescriptor.hpp:52
Definition ApplicationException.hpp:47