All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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@supagro.inra.fr>
36 */
37 
38 
39 
40 #ifndef __OPENFLUID_CORE_SPATIALUNIT_HPP__
41 #define __OPENFLUID_CORE_SPATIALUNIT_HPP__
42 
43 
44 #include <map>
45 #include <string>
46 
47 #include <openfluid/dllexport.hpp>
53 
54 
55 namespace openfluid { namespace core {
56 
57 
58 /**
59  Type for a hashmap of lists of units, indexed by UnitClass
60 */
61 typedef std::map<UnitsClass_t,UnitsCollection> UnitsListByClassMap_t;
62 
63 
64 /**
65  Type for a list of pointers on Unit
66 */
67 typedef std::list<SpatialUnit*> UnitsPtrList_t;
68 
69 
70 /**
71  Type for a map associating a unit class to a list of pointers on Unit
72 */
73 typedef std::map<UnitsClass_t,UnitsPtrList_t> LinkedUnitsListByClassMap_t;
74 
75 
76 /**
77  Class defining a spatial unit
78 
79  example of use:
80  @code
81  openfluid::core::SpatialUnit aUnit;
82  openfluid::core::SpatialUnit* aUnitPtr;
83  openfluid::core::UnitsClass_t aUnitClass;
84  openfluid::core::UnitID_t aUnitID;
85  openfluid::core::UnitsPtrList_t* aUnitListPtr;
86 
87 
88  // get unit ID
89  aUnitID = aUnit.getID();
90  // or (pointed unit)
91  aUnitID = aUnitPtr->getID();
92 
93  // get unit class
94  aUnitClass = aUnit.getClass();
95  // or (pointed unit)
96  aUnitClass = aUnitPtr->getClass();
97 
98  // get connected units (to and from)
99  aUnitListPtr = aUnit.toSpatialUnits("foo");
100  // or
101  aUnitListPtr = aUnit.fromSpatialUnits("bar");
102  @endcode
103 */
105 {
106  private:
107 
108  UnitID_t m_ID;
109 
110  UnitsClass_t m_Class;
111 
112  // TODO use openfluid::core::PcsOrd_t instead
113  unsigned int 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 
130  public:
131 
132  /*
133  Constructor
134  @param[in] aClass the class of the unit
135  @param[in] anID the ID of the unit
136  @param[in] aPcsOrder the process order of the unit
137  */
138  SpatialUnit(const UnitsClass_t& aClass, const UnitID_t anID, const PcsOrd_t aPcsOrder);
139 
140  /*
141  Destructor
142  */
143  ~SpatialUnit();
144 
145  /**
146  Returns the process order of the unit
147  */
148  inline PcsOrd_t getProcessOrder() const
149  { return m_PcsOrder; };
150 
151  /**
152  Returns the ID of the unit
153  */
154  inline UnitID_t getID() const
155  { return m_ID; };
156 
157 
158  /**
159  Returns the class of the unit
160  */
161  inline UnitsClass_t getClass() const
162  { return m_Class; };
163 
164  bool addToUnit(SpatialUnit* aUnit);
165 
166  bool addFromUnit(SpatialUnit* aUnit);
167 
168  bool addParentUnit(SpatialUnit* aUnit);
169 
170  bool addChildUnit(SpatialUnit* aUnit);
171 
172  /**
173  Returns a list of units, of the requested class, connected to this unit.
174  Returns NULL if no units of the requested class are connected to this unit.
175  @param[in] aClass the requested class
176  */
177  UnitsPtrList_t* toSpatialUnits(const UnitsClass_t& aClass);
178 
179  const UnitsPtrList_t* toSpatialUnits(const UnitsClass_t& aClass) const;
180 
181  /**
182  @deprecated Since version 2.1.0. Use openfluid::core::SpatialUnit::toSpatialUnits(const UnitsClass_t&) instead
183  */
185  { return toSpatialUnits(aClass); }
186 
187  /**
188  @deprecated Since version 2.1.0.
189  Use openfluid::core::SpatialUnit::toSpatialUnits(const UnitsClass_t&) const instead
190  */
192  { return toSpatialUnits(aClass); }
193 
194  /**
195  Returns a list of units, of the requested class, connected from this unit.
196  Returns NULL if no units of the requested class are connected from this unit.
197  @param[in] aClass the requested class
198  */
199  UnitsPtrList_t* fromSpatialUnits(const UnitsClass_t& aClass);
200 
201  const UnitsPtrList_t* fromSpatialUnits(const UnitsClass_t& aClass) const;
202 
203 
204  /**
205  @deprecated Since version 2.1.0. Use openfluid::core::SpatialUnit::fromSpatialUnits(const UnitsClass_t&) instead
206  */
208  { return fromSpatialUnits(aClass); }
209 
210  /**
211  @deprecated Since version 2.1.0.
212  Use openfluid::core::SpatialUnit::fromSpatialUnits(const UnitsClass_t&) const instead
213  */
214  const UnitsPtrList_t* getFromUnits(const UnitsClass_t& aClass) const
215  { return fromSpatialUnits(aClass); }
216 
217  /**
218  Returns a list of parent units of the requested class.
219  Returns NULL if this unit has no parent
220  @param[in] aClass the requested class
221  */
222  UnitsPtrList_t* parentSpatialUnits(const UnitsClass_t& aClass);
223 
224  const UnitsPtrList_t* parentSpatialUnits(const UnitsClass_t& aClass) const;
225 
226  /**
227  @deprecated Since version 2.1.0. Use openfluid::core::SpatialUnit::parentSpatialUnits(const UnitsClass_t&) instead
228  */
230  { return parentSpatialUnits(aClass); }
231 
232  /**
233  @deprecated Since version 2.1.0.
234  Use openfluid::core::SpatialUnit::parentSpatialUnits(const UnitsClass_t&) const instead
235  */
237  { return parentSpatialUnits(aClass); }
238 
239  /**
240  Returns a list of children units of the requested class.
241  Returns NULL if this unit has no child
242  @param[in] aClass the requested class
243  */
244  UnitsPtrList_t* childSpatialUnits(const UnitsClass_t& aClass);
245 
246  const UnitsPtrList_t* childSpatialUnits(const UnitsClass_t& aClass) const;
247 
248  /**
249  @deprecated Since version 2.1.0. Use openfluid::core::SpatialUnit::childSpatialUnits(const UnitsClass_t&) instead
250  */
252  { return childSpatialUnits(aClass); }
253 
254  /**
255  @deprecated Since version 2.1.0.
256  Use openfluid::core::SpatialUnit::childSpatialUnits(const UnitsClass_t&) const instead
257  */
259  { return childSpatialUnits(aClass); }
260 
262  { return &m_Attributes; };
263 
264  inline const Attributes* attributes() const
265  { return &m_Attributes; };
266 
268  { return &m_Variables; };
269 
270  const Variables* variables() const
271  { return &m_Variables; };
272 
274  { return &m_Events; };
275 
276  inline const EventsCollection* events() const
277  { return &m_Events; };
278 
279  void streamContents(std::ostream& OStream);
280 
281  void setProcessOrder(unsigned int PcsOrder)
282  { m_PcsOrder = PcsOrder; };
283 
284 };
285 
286 
288 
289 
290 } } // namespace openfluid::core
291 
292 
293 #endif /* __OPENFLUID_CORE_SPATIALUNIT_HPP__ */
294 
unsigned int UnitID_t
Definition: TypeDefs.hpp:61
UnitsPtrList_t * getFromUnits(const UnitsClass_t &aClass) OPENFLUID_DEPRECATED
Definition: SpatialUnit.hpp:207
Variables * variables()
Definition: SpatialUnit.hpp:267
const Variables * variables() const
Definition: SpatialUnit.hpp:270
std::list< SpatialUnit * > UnitsPtrList_t
Definition: SpatialUnit.hpp:67
std::string UnitsClass_t
Definition: TypeDefs.hpp:71
Definition: Attributes.hpp:57
UnitsPtrList_t * getParentUnits(const UnitsClass_t &aClass) OPENFLUID_DEPRECATED
Definition: SpatialUnit.hpp:229
SpatialUnit Unit OPENFLUID_DEPRECATED
Definition: SpatialUnit.hpp:287
UnitsPtrList_t * getChildrenUnits(const UnitsClass_t &aClass) OPENFLUID_DEPRECATED
Definition: SpatialUnit.hpp:251
Definition: Variables.hpp:48
Definition: SpatialUnit.hpp:104
void setProcessOrder(unsigned int PcsOrder)
Definition: SpatialUnit.hpp:281
const UnitsPtrList_t * getChildrenUnits(const UnitsClass_t &aClass) const OPENFLUID_DEPRECATED
Definition: SpatialUnit.hpp:258
const UnitsPtrList_t * getToUnits(const UnitsClass_t &aClass) const OPENFLUID_DEPRECATED
Definition: SpatialUnit.hpp:191
UnitsPtrList_t * getToUnits(const UnitsClass_t &aClass) OPENFLUID_DEPRECATED
Definition: SpatialUnit.hpp:184
const UnitsPtrList_t * getFromUnits(const UnitsClass_t &aClass) const
Definition: SpatialUnit.hpp:214
const EventsCollection * events() const
Definition: SpatialUnit.hpp:276
Class defining a collection of discrete events.
Definition: EventsCollection.hpp:59
Attributes * attributes()
Definition: SpatialUnit.hpp:261
PcsOrd_t getProcessOrder() const
Definition: SpatialUnit.hpp:148
const Attributes * attributes() const
Definition: SpatialUnit.hpp:264
std::map< UnitsClass_t, UnitsCollection > UnitsListByClassMap_t
Definition: SpatialUnit.hpp:61
#define OPENFLUID_API
Definition: dllexport.hpp:87
std::map< UnitsClass_t, UnitsPtrList_t > LinkedUnitsListByClassMap_t
Definition: SpatialUnit.hpp:73
EventsCollection * events()
Definition: SpatialUnit.hpp:273
const UnitsPtrList_t * getParentUnits(const UnitsClass_t &aClass) const OPENFLUID_DEPRECATED
Definition: SpatialUnit.hpp:236
int PcsOrd_t
Definition: TypeDefs.hpp:66
UnitID_t getID() const
Definition: SpatialUnit.hpp:154
UnitsClass_t getClass() const
Definition: SpatialUnit.hpp:161