core/Unit.hpp
Go to the documentation of this file.
00001 /*
00002 
00003   This file is part of OpenFLUID software
00004   Copyright(c) 2007, INRA - Montpellier SupAgro
00005 
00006 
00007  == GNU General Public License Usage ==
00008 
00009   OpenFLUID is free software: you can redistribute it and/or modify
00010   it under the terms of the GNU General Public License as published by
00011   the Free Software Foundation, either version 3 of the License, or
00012   (at your option) any later version.
00013 
00014   OpenFLUID is distributed in the hope that it will be useful,
00015   but WITHOUT ANY WARRANTY; without even the implied warranty of
00016   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017   GNU General Public License for more details.
00018 
00019   You should have received a copy of the GNU General Public License
00020   along with OpenFLUID. If not, see <http://www.gnu.org/licenses/>.
00021 
00022 
00023  == Other Usage ==
00024 
00025   Other Usage means a use of OpenFLUID that is inconsistent with the GPL
00026   license, and requires a written agreement between You and INRA.
00027   Licensees for Other Usage of OpenFLUID may use this file in accordance
00028   with the terms contained in the written agreement between You and INRA.
00029 
00030 */
00031 
00032 /**
00033   @file
00034 
00035   @author JC.Fabre <fabrejc@supagro.inra.fr>
00036 */
00037 
00038 
00039 
00040 
00041 #ifndef __UNIT_H__
00042 #define __UNIT_H__
00043 
00044 
00045 #include <map>
00046 #include <string>
00047 
00048 #include <openfluid/dllexport.hpp>
00049 #include <openfluid/core/UnitsColl.hpp>
00050 #include <openfluid/core/Attributes.hpp>
00051 #include <openfluid/core/Variables.hpp>
00052 #include <openfluid/core/EventsColl.hpp>
00053 
00054 
00055 
00056 namespace openfluid { namespace core {
00057 
00058 //class DLLEXPORT UnitsCollection;
00059 
00060 
00061 
00062 /**
00063   Type for a hashmap of lists of units, indexed by UnitClass
00064 */
00065 typedef std::map<UnitClass_t,UnitsCollection> UnitsListByClassMap_t;
00066 
00067 //class DLLEXPORT Unit;
00068 
00069 /**
00070   Type for a list of pointers on Unit
00071 */
00072 typedef std::list<Unit*> UnitsPtrList_t;
00073 
00074 /**
00075   Type for a map associating a unit class to a list of pointers on Unit
00076 */
00077 typedef std::map<UnitClass_t,UnitsPtrList_t> LinkedUnitsListByClassMap_t;
00078 
00079 /**
00080   Class defining a spatial unit
00081 
00082   example of use:
00083   @code
00084   openfluid::core::Unit aUnit;
00085   openfluid::core::Unit* aUnitPtr;
00086   openfluid::core::UnitClass_t aUnitClass;
00087   openfluid::core::UnitID_t aUnitID;
00088   openfluid::core::UnitsPtrList_t* aUnitListPtr;
00089 
00090 
00091   // *** get unit ID ***
00092   aUnitID = aUnit.getID();
00093   // or (pointed unit)
00094   aUnitID = aUnitPtr->getID();
00095 
00096   // *** get unit class ***
00097   aUnitClass = aUnit.getClass();
00098   // or (pointed unit)
00099   aUnitClass = aUnitPtr->getClass();
00100 
00101   // *** get connected units (to and from) ***
00102   aUnitListPtr = aUnit.getToUnits("foo");
00103   // or
00104   aUnitListPtr = aUnit.getFromUnits("bar");
00105   @endcode
00106 */
00107 class DLLEXPORT Unit
00108 {
00109   private:
00110 
00111     UnitID_t m_ID;
00112 
00113     UnitClass_t m_Class;
00114 
00115     // TODO use openfluid::core::PcsOrd_t instead
00116     unsigned int m_PcsOrder;
00117 
00118     LinkedUnitsListByClassMap_t m_FromUnits;
00119     LinkedUnitsListByClassMap_t m_ToUnits;
00120     LinkedUnitsListByClassMap_t m_ParentUnits;
00121     LinkedUnitsListByClassMap_t m_ChildrenUnits;
00122 
00123     Attributes m_Attributes;
00124 
00125     Variables m_Variables;
00126 
00127     EventsCollection m_Events;
00128 
00129   public:
00130 
00131     /*
00132           Constructor
00133       @param[in] aClass the class of the unit
00134       @param[in] anID the ID of the unit
00135       @param[in] aPcsOrder the process order of the unit
00136         */
00137     Unit(const UnitClass_t aClass, const UnitID_t anID,
00138          const PcsOrd_t aPcsOrder);
00139 
00140     /*
00141           Destructor
00142         */
00143     ~Unit();
00144 
00145     /**
00146       Returns the process order of the unit
00147       TODO use openfluid::core::PcsOrd_t instead
00148     */
00149     inline unsigned int getProcessOrder() const { return m_PcsOrder; };
00150 
00151     /**
00152       Returns the ID of the unit
00153     */
00154     inline UnitID_t getID() const { return m_ID; };
00155 
00156 
00157     /**
00158       Returns the class of the unit
00159     */
00160     inline UnitClass_t getClass() const { return m_Class; };
00161 
00162     bool addToUnit(Unit* aUnit);
00163 
00164     bool addFromUnit(Unit* aUnit);
00165 
00166     bool addParentUnit(Unit* aUnit);
00167 
00168     bool addChildUnit(Unit* aUnit);
00169 
00170     /**
00171       Returns a list of units, of the requested class, connected to this unit.
00172       Returns NULL if no units of the requested class are connected to this unit.
00173       @param[in] aClass the requested class
00174     */
00175     UnitsPtrList_t* getToUnits(const UnitClass_t aClass);
00176 
00177     const UnitsPtrList_t* getToUnits(const UnitClass_t aClass) const;
00178 
00179     /**
00180       Returns a list of units, of the requested class, connected from this unit.
00181       Returns NULL if no units of the requested class are connected from this unit.
00182       @param[in] aClass the requested class
00183     */
00184     UnitsPtrList_t* getFromUnits(const UnitClass_t aClass);
00185 
00186     const UnitsPtrList_t* getFromUnits(const UnitClass_t aClass) const;
00187 
00188     /**
00189       Returns a list of parent units of the requested class.
00190       Returns NULL if this unit has no parent
00191       @param[in] aClass the requested class
00192     */
00193     UnitsPtrList_t* getParentUnits(const UnitClass_t aClass);
00194 
00195     const UnitsPtrList_t* getParentUnits(const UnitClass_t aClass) const;
00196 
00197     /**
00198       Returns a list of children units of the requested class.
00199       Returns NULL if this unit has no child
00200       @param[in] aClass the requested class
00201     */
00202     UnitsPtrList_t* getChildrenUnits(const UnitClass_t aClass);
00203 
00204     const UnitsPtrList_t* getChildrenUnits(const UnitClass_t aClass) const;
00205 
00206 
00207 
00208 
00209     inline Attributes* getAttributes()  { return &m_Attributes; };
00210 
00211     inline const Attributes* getAttributes() const { return &m_Attributes; };
00212 
00213     Variables* getVariables() { return &m_Variables; };
00214 
00215     const Variables* getVariables() const { return &m_Variables; };
00216 
00217     inline EventsCollection* getEvents() { return &m_Events; };
00218 
00219     inline const EventsCollection* getEvents() const { return &m_Events; };
00220 
00221     void streamContents(std::ostream& OStream);
00222 
00223     void setProcessOrder(unsigned int PcsOrder) { m_PcsOrder = PcsOrder; };
00224 
00225 };
00226 
00227 
00228 } } // namespace openfluid::core
00229 
00230 
00231 #endif /* __UNIT_H__ */
00232 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines