SpatialUnit.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 SpatialUnit.hpp
34 
35  @author Jean-Christophe Fabre <jean-christophe.fabre@inra.fr>
36 */
37 
38 
39 #ifndef __OPENFLUID_CORE_SPATIALUNIT_HPP__
40 #define __OPENFLUID_CORE_SPATIALUNIT_HPP__
41 
42 
43 #include <map>
44 #include <string>
45 
46 #include <openfluid/dllexport.hpp>
51 
52 
53 class OGRGeometry;
54 
55 
56 namespace openfluid { namespace core {
57 
58 
59 /**
60  Type for a hashmap of lists of units, indexed by UnitClass
61 */
62 typedef std::map<UnitsClass_t,UnitsCollection> UnitsListByClassMap_t;
63 
64 
65 /**
66  Type for a list of pointers on Unit
67 */
68 typedef std::list<SpatialUnit*> UnitsPtrList_t;
69 
70 
71 /**
72  Type for a map associating a unit class to a list of pointers on Unit
73 */
74 typedef std::map<UnitsClass_t,UnitsPtrList_t> LinkedUnitsListByClassMap_t;
75 
76 
77 /**
78  Class defining a spatial unit
79 
80  example of use:
81  @code
82  openfluid::core::SpatialUnit aUnit;
83  openfluid::core::SpatialUnit* aUnitPtr;
84  openfluid::core::UnitsClass_t aUnitClass;
85  openfluid::core::UnitID_t aUnitID;
86  openfluid::core::UnitsPtrList_t* aUnitListPtr;
87 
88 
89  // get unit ID
90  aUnitID = aUnit.getID();
91  // or (pointed unit)
92  aUnitID = aUnitPtr->getID();
93 
94  // get unit class
95  aUnitClass = aUnit.getClass();
96  // or (pointed unit)
97  aUnitClass = aUnitPtr->getClass();
98 
99  // get connected units (to and from)
100  aUnitListPtr = aUnit.toSpatialUnits("foo");
101  // or
102  aUnitListPtr = aUnit.fromSpatialUnits("bar");
103  @endcode
104 */
106 {
107  private:
108 
109  UnitID_t m_ID;
110 
111  UnitsClass_t m_Class;
112 
113  openfluid::core::PcsOrd_t m_PcsOrder;
114 
115  LinkedUnitsListByClassMap_t m_FromUnits;
116 
117  LinkedUnitsListByClassMap_t m_ToUnits;
118 
119  LinkedUnitsListByClassMap_t m_ParentUnits;
120 
121  LinkedUnitsListByClassMap_t m_ChildrenUnits;
122 
123  Attributes m_Attributes;
124 
125  Variables m_Variables;
126 
127  EventsCollection m_Events;
128 
129  OGRGeometry* m_Geometry;
130 
131 
132  public:
133 
134  SpatialUnit() = delete;
135 
136  /*
137  Constructor
138  @param[in] aClass the class of the unit
139  @param[in] anID the ID of the unit
140  @param[in] aPcsOrder the process order of the unit
141  */
142  SpatialUnit(const UnitsClass_t& aClass, const UnitID_t anID, const PcsOrd_t aPcsOrder);
143 
144  /*
145  Destructor
146  */
147  ~SpatialUnit();
148 
149  /**
150  Returns the process order of the unit
151  */
152  inline PcsOrd_t getProcessOrder() const
153  {
154  return m_PcsOrder;
155  };
156 
157  /**
158  Returns the ID of the unit
159  */
160  inline UnitID_t getID() const
161  {
162  return m_ID;
163  };
164 
165  /**
166  Returns the class of the unit
167  */
168  inline UnitsClass_t getClass() const
169  {
170  return m_Class;
171  };
172 
173  bool addToUnit(SpatialUnit* aUnit);
174 
175  bool addFromUnit(SpatialUnit* aUnit);
176 
177  bool addParentUnit(SpatialUnit* aUnit);
178 
179  bool addChildUnit(SpatialUnit* aUnit);
180 
181  /**
182  Returns a list of units, of the requested class, connected to this unit.
183  Returns nullptr if no units of the requested class are connected to this unit.
184  @param[in] aClass the requested class
185  */
186  UnitsPtrList_t* toSpatialUnits(const UnitsClass_t& aClass);
187 
188  const UnitsPtrList_t* toSpatialUnits(const UnitsClass_t& aClass) const;
189 
190  /**
191  @deprecated Since version 2.1.0. Use openfluid::core::SpatialUnit::toSpatialUnits(const UnitsClass_t&) instead
192  */
193  [[deprecated]] UnitsPtrList_t* getToUnits(const UnitsClass_t& aClass)
194  {
195  return toSpatialUnits(aClass);
196  }
197 
198  /**
199  @deprecated Since version 2.1.0.
200  Use openfluid::core::SpatialUnit::toSpatialUnits(const UnitsClass_t&) const instead
201  */
202  [[deprecated]] const UnitsPtrList_t* getToUnits(const UnitsClass_t& aClass) const
203  {
204  return toSpatialUnits(aClass);
205  }
206 
207  /**
208  Returns a list of units, of the requested class, connected from this unit.
209  Returns nullptr if no units of the requested class are connected from this unit.
210  @param[in] aClass the requested class
211  */
212  UnitsPtrList_t* fromSpatialUnits(const UnitsClass_t& aClass);
213 
214  const UnitsPtrList_t* fromSpatialUnits(const UnitsClass_t& aClass) const;
215 
216  /**
217  @deprecated Since version 2.1.0. Use openfluid::core::SpatialUnit::fromSpatialUnits(const UnitsClass_t&) instead
218  */
219  [[deprecated]] UnitsPtrList_t* getFromUnits(const UnitsClass_t& aClass)
220  {
221  return fromSpatialUnits(aClass);
222  }
223 
224  /**
225  @deprecated Since version 2.1.0.
226  Use openfluid::core::SpatialUnit::fromSpatialUnits(const UnitsClass_t&) const instead
227  */
228  const UnitsPtrList_t* getFromUnits(const UnitsClass_t& aClass) const
229  {
230  return fromSpatialUnits(aClass);
231  }
232 
233  /**
234  Returns a list of parent units of the requested class.
235  Returns nullptr if this unit has no parent
236  @param[in] aClass the requested class
237  */
238  UnitsPtrList_t* parentSpatialUnits(const UnitsClass_t& aClass);
239 
240  const UnitsPtrList_t* parentSpatialUnits(const UnitsClass_t& aClass) const;
241 
242  /**
243  @deprecated Since version 2.1.0. Use openfluid::core::SpatialUnit::parentSpatialUnits(const UnitsClass_t&) instead
244  */
245  [[deprecated]] UnitsPtrList_t* getParentUnits(const UnitsClass_t& aClass)
246  {
247  return parentSpatialUnits(aClass);
248  }
249 
250  /**
251  @deprecated Since version 2.1.0.
252  Use openfluid::core::SpatialUnit::parentSpatialUnits(const UnitsClass_t&) const instead
253  */
254  [[deprecated]] const UnitsPtrList_t* getParentUnits(const UnitsClass_t& aClass) const
255  {
256  return parentSpatialUnits(aClass);
257  }
258 
259  /**
260  Returns a list of children units of the requested class.
261  Returns nullptr if this unit has no child
262  @param[in] aClass the requested class
263  */
264  UnitsPtrList_t* childSpatialUnits(const UnitsClass_t& aClass);
265 
266  const UnitsPtrList_t* childSpatialUnits(const UnitsClass_t& aClass) const;
267 
268  /**
269  @deprecated Since version 2.1.0. Use openfluid::core::SpatialUnit::childSpatialUnits(const UnitsClass_t&) instead
270  */
271  [[deprecated]] UnitsPtrList_t* getChildrenUnits(const UnitsClass_t& aClass)
272  { return childSpatialUnits(aClass); }
273 
274  /**
275  @deprecated Since version 2.1.0.
276  Use openfluid::core::SpatialUnit::childSpatialUnits(const UnitsClass_t&) const instead
277  */
278  [[deprecated]] const UnitsPtrList_t* getChildrenUnits(const UnitsClass_t& aClass) const
279  {
280  return childSpatialUnits(aClass);
281  }
282 
284  {
285  return &m_Attributes;
286  };
287 
288  inline const Attributes* attributes() const
289  {
290  return &m_Attributes;
291  };
292 
294  {
295  return &m_Variables;
296  };
297 
298  const Variables* variables() const
299  {
300  return &m_Variables;
301  };
302 
304  {
305  return &m_Events;
306  };
307 
308  inline const EventsCollection* events() const
309  {
310  return &m_Events;
311  };
312 
313  void streamContents(std::ostream& OStream);
314 
315  void setProcessOrder(unsigned int PcsOrder)
316  {
317  m_PcsOrder = PcsOrder;
318  };
319 
320  OGRGeometry* geometry()
321  {
322  return m_Geometry;
323  };
324 
325  const OGRGeometry* geometry() const
326  {
327  return m_Geometry;
328  };
329 
330  bool importGeometryFromWkt(const std::string& WKT);
331 
332  std::string exportGeometryToWkt() const;
333 
334  void deleteGeometry();
335 
336 };
337 
338 
339 [[deprecated]] typedef SpatialUnit Unit;
340 
341 
342 } } // namespace openfluid::core
343 
344 
345 #endif /* __OPENFLUID_CORE_SPATIALUNIT_HPP__ */
346 
Definition: Variables.hpp:52
std::map< UnitsClass_t, UnitsCollection > UnitsListByClassMap_t
Definition: SpatialUnit.hpp:62
const EventsCollection * events() const
Definition: SpatialUnit.hpp:308
const UnitsPtrList_t * getToUnits(const UnitsClass_t &aClass) const
Definition: SpatialUnit.hpp:202
int PcsOrd_t
Definition: TypeDefs.hpp:66
UnitsPtrList_t * getToUnits(const UnitsClass_t &aClass)
Definition: SpatialUnit.hpp:193
const UnitsPtrList_t * getChildrenUnits(const UnitsClass_t &aClass) const
Definition: SpatialUnit.hpp:278
UnitsClass_t getClass() const
Definition: SpatialUnit.hpp:168
const Variables * variables() const
Definition: SpatialUnit.hpp:298
Variables * variables()
Definition: SpatialUnit.hpp:293
Definition: Attributes.hpp:57
Definition: SpatialUnit.hpp:105
UnitsPtrList_t * getParentUnits(const UnitsClass_t &aClass)
Definition: SpatialUnit.hpp:245
EventsCollection * events()
Definition: SpatialUnit.hpp:303
UnitID_t getID() const
Definition: SpatialUnit.hpp:160
const UnitsPtrList_t * getFromUnits(const UnitsClass_t &aClass) const
Definition: SpatialUnit.hpp:228
Definition: ApplicationException.hpp:47
std::map< UnitsClass_t, UnitsPtrList_t > LinkedUnitsListByClassMap_t
Definition: SpatialUnit.hpp:74
PcsOrd_t getProcessOrder() const
Definition: SpatialUnit.hpp:152
std::string UnitsClass_t
Definition: TypeDefs.hpp:71
const OGRGeometry * geometry() const
Definition: SpatialUnit.hpp:325
const UnitsPtrList_t * getParentUnits(const UnitsClass_t &aClass) const
Definition: SpatialUnit.hpp:254
UnitsPtrList_t * getFromUnits(const UnitsClass_t &aClass)
Definition: SpatialUnit.hpp:219
const Attributes * attributes() const
Definition: SpatialUnit.hpp:288
void setProcessOrder(unsigned int PcsOrder)
Definition: SpatialUnit.hpp:315
OGRGeometry * geometry()
Definition: SpatialUnit.hpp:320
Attributes * attributes()
Definition: SpatialUnit.hpp:283
unsigned int UnitID_t
Definition: TypeDefs.hpp:61
#define OPENFLUID_API
Definition: dllexport.hpp:86
SpatialUnit Unit
Definition: SpatialUnit.hpp:339
std::list< SpatialUnit * > UnitsPtrList_t
Definition: SpatialUnit.hpp:68
UnitsPtrList_t * getChildrenUnits(const UnitsClass_t &aClass)
Definition: SpatialUnit.hpp:271
Class defining a collection of discrete events.
Definition: EventsCollection.hpp:59