fluidx/AdvancedDomainDescriptor.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 AdvancedDomainDescriptor.hpp
00034  \brief Header of ...
00035 
00036  \author Aline LIBRES <aline.libres@gmail.com>
00037  */
00038 
00039 #ifndef ADVANCEDDOMAINDESCRIPTOR_HPP_
00040 #define ADVANCEDDOMAINDESCRIPTOR_HPP_
00041 
00042 #include <openfluid/core/TypeDefs.hpp>
00043 #include <openfluid/dllexport.hpp>
00044 #include <openfluid/fluidx/EventDescriptor.hpp>
00045 
00046 #include <map>
00047 #include <set>
00048 
00049 namespace openfluid {
00050 
00051 namespace core {
00052 class Event;
00053 }
00054 
00055 namespace fluidx {
00056 
00057 class DomainDescriptor;
00058 class UnitDescriptor;
00059 class AttributesDescriptor;
00060 
00061 
00062 // =====================================================================
00063 // =====================================================================
00064 
00065 
00066 class DLLEXPORT AdvancedUnitDescriptor
00067 {
00068 
00069   public:
00070 
00071     openfluid::fluidx::UnitDescriptor* UnitDescriptor;
00072 
00073     std::map<openfluid::core::AttributeName_t, std::string*> Attributes;
00074 
00075     std::list<openfluid::fluidx::EventDescriptor*> EventsDescriptors;
00076 
00077     AdvancedUnitDescriptor(openfluid::fluidx::UnitDescriptor& UnitDesc) :
00078         UnitDescriptor(&UnitDesc)
00079     {
00080     }
00081 
00082 };
00083 
00084 
00085 // =====================================================================
00086 // =====================================================================
00087 
00088 
00089 class DLLEXPORT AdvancedDomainDescriptor
00090 {
00091   public:
00092 
00093     typedef std::map<std::string, std::map<int, AdvancedUnitDescriptor> > UnitsByIdByClass_t;
00094 
00095   private:
00096 
00097     openfluid::fluidx::DomainDescriptor* mp_DomainDesc;
00098 
00099     /**
00100      * Units by ID by ClassName
00101      */
00102     std::map<std::string, std::map<int, AdvancedUnitDescriptor> > m_Units;
00103 
00104     std::map<std::string, std::set<openfluid::core::AttributeName_t> > m_AttrsNames;
00105 
00106     void dispatchUnits();
00107 
00108     void dispatchAttributes();
00109 
00110     void checkUnitRelations() const;
00111 
00112     void checkUnitRelations(openfluid::fluidx::UnitDescriptor& Unit) const;
00113 
00114     void checkAttributesConsistency() const;
00115 
00116     void dispatchEvents();
00117 
00118 
00119   public:
00120 
00121     AdvancedDomainDescriptor(openfluid::fluidx::DomainDescriptor& DomainDesc);
00122 
00123     ~AdvancedDomainDescriptor();
00124 
00125     bool isUnitExist(const std::string& ClassName, int ID) const;
00126 
00127     /**
00128      *
00129      * @return May return an empty map. Never throws.
00130      */
00131     const std::map<std::string, std::map<int, AdvancedUnitDescriptor> >& getUnitsByIdByClass() const;
00132 
00133     /**
00134      * @throw openfluid::base::OFException if Unit doesn't exist
00135      * @param ClassName
00136      * @param ID
00137      * @return
00138      */
00139     const AdvancedUnitDescriptor& getUnit(const std::string& ClassName, int ID) const;
00140 
00141     /**
00142      * @throw openfluid::base::OFException if Unit doesn't exist
00143      * @param ClassName
00144      * @param ID
00145      * @return
00146      */
00147     const openfluid::fluidx::UnitDescriptor& getUnitDescriptor(
00148         const std::string& ClassName, int ID) const;
00149 
00150     /**
00151      *
00152      * @param ClassName
00153      * @return An empty set if ClassName doesn't exist. Never throws.
00154      */
00155     std::set<int> getIDsOfClass(const std::string& ClassName) const;
00156 
00157     bool isClassNameExists(const std::string& ClassName) const;
00158 
00159     /**
00160      *
00161      * @return May return an empty set. Never throws.
00162      */
00163     std::set<std::string> getClassNames() const;
00164 
00165     unsigned int getUnitsCount() const;
00166 
00167     /**
00168      * @details Add this UnitDesc ID to the descriptor for all attributes of this UnitDesc class,
00169      * with a default value of "-"
00170      * @warning Invalidate UnitDesc
00171      * @throw openfluid::base::OFException if Unit already exists or if Unit has a relation with a non-existent Unit
00172      * @param UnitDesc
00173      */
00174     void addUnit(openfluid::fluidx::UnitDescriptor* UnitDesc);
00175 
00176     /**
00177      * Does nothing if Unit doesn't exist
00178      *
00179      * @param ClassName
00180      * @param ID
00181      */
00182     void deleteUnit(const std::string& ClassName, int ID);
00183 
00184     /**
00185      * @throw openfluid::base::OFException if Unit or DataName doesn't exist
00186      * @param ClassName
00187      * @param ID
00188      * @param AttrName
00189      * @return
00190      */
00191     std::string& getAttribute(const std::string& ClassName, int ID,
00192                               const std::string& AttrName);
00193 
00194     /**
00195      *
00196      * @param ClassName
00197      * @return An empty set if ClassName doesn't exist or has no attribute. Never throws.
00198      */
00199     std::set<std::string> getAttributesNames(const std::string& ClassName) const;
00200 
00201     /**
00202      * @throw openfluid::base::OFException if ClassName doesn't exist
00203      * or if AttrName already exists for class ClassName
00204      * @param ClassName
00205      * @param AttrName
00206      * @param DefaultValue
00207      */
00208     void addAttribute(const std::string& ClassName, const std::string& AttrName,
00209                       const std::string& DefaultValue);
00210 
00211     /**
00212      * @throw openfluid::base::OFException if ClassName doesn't exist
00213      * or if AttrName doesn't exist for class ClassName
00214      * @param ClassName
00215      * @param AttrName
00216      */
00217     void deleteAttribute(const std::string& ClassName, const std::string& AttrName);
00218 
00219     /**
00220      * Does nothing if NewDataName is the same as OldDataName
00221      * @throw openfluid::base::OFException if ClassName doesn't exist
00222      * or if OldDataName doesn't exist for the class ClassName
00223      * @param ClassName
00224      * @param OldAttrName
00225      * @param NewAttrName
00226      */
00227     void renameAttribute(const std::string& ClassName, const std::string& OldAttrName,
00228                          const std::string& NewAttrName);
00229 
00230     /**
00231       Adds an event
00232       @param[in] UnitsClass The units class of the event
00233       @param[in] UnitID The unit ID of the event
00234       @param[in] Event The event definition
00235     */
00236     void addEvent(const openfluid::core::UnitClass_t& UnitsClass, const openfluid::core::UnitID_t& UnitID,
00237                      const openfluid::core::Event& Event);
00238 
00239     /**
00240       Deletes an event
00241       @param[in] UnitsClass The units class of the event
00242       @param[in] UnitID The unit ID of the event
00243       @param[in] EventID The ID of the event to delete
00244     */
00245     void deleteEvent(const openfluid::core::UnitClass_t& UnitsClass, const openfluid::core::UnitID_t& UnitID,
00246                      const openfluid::fluidx::EventID_t& EventID);
00247 
00248     /**
00249       Modify an event
00250       @param[in] EventID The ID of the event to modify
00251       @param[in] Event The new content of the event
00252     */
00253     void modifyEvent(const openfluid::fluidx::EventID_t& EventID,
00254                      const openfluid::core::Event& Event);
00255 
00256     /**
00257       Returns a pointer to the event descriptor corresponding to the event ID
00258       @param[in] ID The ID of the event to delete
00259     */
00260     openfluid::fluidx::EventDescriptor* getEventDescriptor(const openfluid::fluidx::EventID_t& ID);
00261 
00262 
00263     const std::list<openfluid::core::UnitClassID_t>& getUnitsToOf(const openfluid::core::UnitClassID_t Unit) const;
00264 
00265     const std::list<openfluid::core::UnitClassID_t>& getUnitsParentsOf(const openfluid::core::UnitClassID_t Unit) const;
00266 
00267     std::list<openfluid::core::UnitClassID_t> getUnitsFromOf(const openfluid::core::UnitClassID_t Unit) const;
00268 
00269     std::list<openfluid::core::UnitClassID_t> getUnitsChildrenOf(const openfluid::core::UnitClassID_t Unit) const;
00270 
00271     /**
00272      * @brief Add ToUnit to the list of "Tos" of FromUnit
00273      * @details Does nothing if the relation already exists
00274      * @throw openfluid::base::OFException if FromUnit or ToUnit doesn't exist
00275      */
00276     void addFromToRelation(const openfluid::core::UnitClassID_t FromUnit,
00277                            const openfluid::core::UnitClassID_t ToUnit);
00278 
00279     /**
00280      * @brief Remove ToUnit from the list of "Tos" of FromUnit
00281      * @throw openfluid::base::OFException if FromUnit or ToUnit doesn't exist or if the relation doesn't exists
00282      */
00283     void removeFromToRelation(const openfluid::core::UnitClassID_t FromUnit,
00284                               const openfluid::core::UnitClassID_t ToUnit);
00285 
00286     /**
00287      * @brief Add ChildUnit to the list of "Children" of ParentUnit
00288      * @details Does nothing if the relation already exists
00289      * @throw openfluid::base::OFException if ParentUnit or ChildUnit doesn't exist
00290      */
00291     void addParentChildRelation(const openfluid::core::UnitClassID_t ParentUnit,
00292                                 const openfluid::core::UnitClassID_t ChildUnit);
00293 
00294     /**
00295      * @brief Remove ChildUnit from the list of "Children" of ParentUnit
00296      * @throw openfluid::base::OFException if ParentUnit or ChildUnit doesn't exist or if the relation doesn't exists
00297      */
00298     void removeParentChildRelation(
00299         const openfluid::core::UnitClassID_t ParentUnit,
00300         const openfluid::core::UnitClassID_t ChildUnit);
00301 
00302     /**
00303      * @brief Clear the list of "Tos" and "Parents" of Unit,
00304      * and remove Unit from the list of "Tos" and "Parents" of all other Units of the Domain
00305      * @throw openfluid::base::OFException if Unit doesn't exist
00306      */
00307     void clearRelations(const openfluid::core::UnitClassID_t Unit);
00308 
00309     void clearDomain();
00310 };
00311 
00312 
00313 // =====================================================================
00314 // =====================================================================
00315 
00316 
00317 } } // namespaces
00318 
00319 #endif /* ADVANCEDDOMAINDESCRIPTOR_HPP_ */
00320 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines