All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Unit.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
34 
35  @author JC.Fabre <fabrejc@supagro.inra.fr>
36 */
37 
38 
39 
40 
41 #ifndef __UNIT_H__
42 #define __UNIT_H__
43 
44 
45 #include <map>
46 #include <string>
47 
48 #include <openfluid/dllexport.hpp>
53 
54 
55 
56 namespace openfluid { namespace core {
57 
58 //class DLLEXPORT UnitsCollection;
59 
60 
61 
62 /**
63  Type for a hashmap of lists of units, indexed by UnitClass
64 */
65 typedef std::map<UnitClass_t,UnitsCollection> UnitsListByClassMap_t;
66 
67 //class DLLEXPORT Unit;
68 
69 /**
70  Type for a list of pointers on Unit
71 */
72 typedef std::list<Unit*> UnitsPtrList_t;
73 
74 /**
75  Type for a map associating a unit class to a list of pointers on Unit
76 */
77 typedef std::map<UnitClass_t,UnitsPtrList_t> LinkedUnitsListByClassMap_t;
78 
79 /**
80  Class defining a spatial unit
81 
82  example of use:
83  @code
84  openfluid::core::Unit aUnit;
85  openfluid::core::Unit* aUnitPtr;
86  openfluid::core::UnitClass_t aUnitClass;
87  openfluid::core::UnitID_t aUnitID;
88  openfluid::core::UnitsPtrList_t* aUnitListPtr;
89 
90 
91  // *** get unit ID ***
92  aUnitID = aUnit.getID();
93  // or (pointed unit)
94  aUnitID = aUnitPtr->getID();
95 
96  // *** get unit class ***
97  aUnitClass = aUnit.getClass();
98  // or (pointed unit)
99  aUnitClass = aUnitPtr->getClass();
100 
101  // *** get connected units (to and from) ***
102  aUnitListPtr = aUnit.getToUnits("foo");
103  // or
104  aUnitListPtr = aUnit.getFromUnits("bar");
105  @endcode
106 */
108 {
109  private:
110 
111  UnitID_t m_ID;
112 
113  UnitClass_t m_Class;
114 
115  // TODO use openfluid::core::PcsOrd_t instead
116  unsigned int m_PcsOrder;
117 
118  LinkedUnitsListByClassMap_t m_FromUnits;
119  LinkedUnitsListByClassMap_t m_ToUnits;
120  LinkedUnitsListByClassMap_t m_ParentUnits;
121  LinkedUnitsListByClassMap_t m_ChildrenUnits;
122 
123  Attributes m_Attributes;
124 
125  Variables m_Variables;
126 
127  EventsCollection m_Events;
128 
129  public:
130 
131  /*
132  Constructor
133  @param[in] aClass the class of the unit
134  @param[in] anID the ID of the unit
135  @param[in] aPcsOrder the process order of the unit
136  */
137  Unit(const UnitClass_t aClass, const UnitID_t anID,
138  const PcsOrd_t aPcsOrder);
139 
140  /*
141  Destructor
142  */
143  ~Unit();
144 
145  /**
146  Returns the process order of the unit
147  */
148  inline PcsOrd_t getProcessOrder() const { return m_PcsOrder; };
149 
150  /**
151  Returns the ID of the unit
152  */
153  inline UnitID_t getID() const { return m_ID; };
154 
155 
156  /**
157  Returns the class of the unit
158  */
159  inline UnitClass_t getClass() const { return m_Class; };
160 
161  bool addToUnit(Unit* aUnit);
162 
163  bool addFromUnit(Unit* aUnit);
164 
165  bool addParentUnit(Unit* aUnit);
166 
167  bool addChildUnit(Unit* aUnit);
168 
169  /**
170  Returns a list of units, of the requested class, connected to this unit.
171  Returns NULL if no units of the requested class are connected to this unit.
172  @param[in] aClass the requested class
173  */
174  UnitsPtrList_t* getToUnits(const UnitClass_t aClass);
175 
176  const UnitsPtrList_t* getToUnits(const UnitClass_t aClass) const;
177 
178  /**
179  Returns a list of units, of the requested class, connected from this unit.
180  Returns NULL if no units of the requested class are connected from this unit.
181  @param[in] aClass the requested class
182  */
183  UnitsPtrList_t* getFromUnits(const UnitClass_t aClass);
184 
185  const UnitsPtrList_t* getFromUnits(const UnitClass_t aClass) const;
186 
187  /**
188  Returns a list of parent units of the requested class.
189  Returns NULL if this unit has no parent
190  @param[in] aClass the requested class
191  */
192  UnitsPtrList_t* getParentUnits(const UnitClass_t aClass);
193 
194  const UnitsPtrList_t* getParentUnits(const UnitClass_t aClass) const;
195 
196  /**
197  Returns a list of children units of the requested class.
198  Returns NULL if this unit has no child
199  @param[in] aClass the requested class
200  */
201  UnitsPtrList_t* getChildrenUnits(const UnitClass_t aClass);
202 
203  const UnitsPtrList_t* getChildrenUnits(const UnitClass_t aClass) const;
204 
205 
206 
207 
208  inline Attributes* getAttributes() { return &m_Attributes; };
209 
210  inline const Attributes* getAttributes() const { return &m_Attributes; };
211 
212  Variables* getVariables() { return &m_Variables; };
213 
214  const Variables* getVariables() const { return &m_Variables; };
215 
216  inline EventsCollection* getEvents() { return &m_Events; };
217 
218  inline const EventsCollection* getEvents() const { return &m_Events; };
219 
220  void streamContents(std::ostream& OStream);
221 
222  void setProcessOrder(unsigned int PcsOrder) { m_PcsOrder = PcsOrder; };
223 
224 };
225 
226 
227 } } // namespace openfluid::core
228 
229 
230 #endif /* __UNIT_H__ */
231 
std::list< Unit * > UnitsPtrList_t
Definition: Unit.hpp:72
Attributes * getAttributes()
Definition: Unit.hpp:208
const Attributes * getAttributes() const
Definition: Unit.hpp:210
Definition: Variables.hpp:43
const Variables * getVariables() const
Definition: Unit.hpp:214
UnitID_t getID() const
Definition: Unit.hpp:153
std::map< UnitClass_t, UnitsPtrList_t > LinkedUnitsListByClassMap_t
Definition: Unit.hpp:77
std::map< UnitClass_t, UnitsCollection > UnitsListByClassMap_t
Definition: Unit.hpp:65
std::string UnitClass_t
Definition: TypeDefs.hpp:69
Definition: Attributes.hpp:45
unsigned int UnitID_t
Definition: TypeDefs.hpp:59
int PcsOrd_t
Definition: TypeDefs.hpp:64
PcsOrd_t getProcessOrder() const
Definition: Unit.hpp:148
void setProcessOrder(unsigned int PcsOrder)
Definition: Unit.hpp:222
Class defining a collection of discrete events.
Definition: EventsColl.hpp:59
const EventsCollection * getEvents() const
Definition: Unit.hpp:218
UnitClass_t getClass() const
Definition: Unit.hpp:159
EventsCollection * getEvents()
Definition: Unit.hpp:216
Variables * getVariables()
Definition: Unit.hpp:212
Definition: Unit.hpp:107
#define DLLEXPORT
Definition: dllexport.hpp:51