Page principale | Liste des namespaces | Hiérarchie des classes | Liste alphabétique | Liste des classes | Liste des fichiers | Membres de namespace | Membres de classe | Membres de fichier

NumVar.h

Aller à la documentation de ce fichier.
00001 /*
00002     Copyright (c) 2005, Quentin Lequy and Romain Gaucher
00003     All rights reserved.
00004 
00005     Redistribution and use in source and binary forms, with or 
00006     without modification, are permitted provided that the following 
00007     conditions are met:
00008 
00009         * Redistributions of source code must retain the above copyright 
00010           notice, this list of conditions and the following disclaimer.
00011 
00012         * Redistributions in binary form must reproduce the above copyright 
00013           notice, this list of conditions and the following disclaimer in the 
00014           documentation and/or other materials provided with the distribution.
00015 
00016         * Neither the name of Quentin Lequy or Romain Gaucher nor the names 
00017           of its contributors may be used to endorse or promote products 
00018           derived from this software without specific prior written permission.
00019 
00020     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
00021     AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
00022     IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
00023     ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
00024     LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
00025     DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
00026     SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
00027     AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
00028     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
00029     SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00030 */
00031 
00032 #ifndef __NUMVAR_H_
00033 #define __NUMVAR_H_
00034 
00035 #include "Config.h"
00036 #include "Constant.h"
00037 #include "MuteVar.h"
00038 #include <string>
00039 
00040 namespace Modelib {
00041 
00042 class Model; //évite une déclaration cyclique
00043 
00045 
00060 class NumVar
00061 {
00062   protected:
00063     VarId varId; 
00064     Model * modele; 
00065   public:
00067     NumVar():varId(0),modele(0) {}
00068 
00069     NumVar(Model & _modele,
00070            float _lb= 0,
00071            float _ub= Infinity,
00072            MuteVar::VarType _type = MuteVar::FLOAT,
00073            const std::string & _nom = "unknow" );
00074 
00075     NumVar(Model & _modele,
00076            MuteVar::VarType _type = MuteVar::FLOAT,
00077            const std::string & _nom = "unknow" )
00078     {
00079         NumVar(_modele,0,Infinity,MuteVar::FLOAT,_nom);
00080     }
00081 
00082     NumVar(const Model *,VarId);
00083 
00085     NumVar(const NumVar & _n):varId( _n.varId), modele(_n.modele)  {}
00086 
00088     NumVar & operator= (const NumVar & _n)
00089     {
00090       modele = _n.modele;
00091       varId = _n.varId;
00092       return *this;
00093     }
00094 
00095     //Différents Geters et Seters
00099     VarId GetVarId() const { return varId;}
00100 
00104     Model * GetModel() const { return modele;}
00105 
00106     float GetValue() const;
00107 
00108     std::string GetName() const;
00109     void SetName(const std::string &);
00110 
00111     float GetLowerBound() const;
00112     void SetLowerBound(float _value);
00113     
00114     float GetUpperBound() const;
00115     void SetUpperBound(float _value);
00116     
00117     bool IsLowerBoundStrict() const;
00118     void SetLowerBoundStrict( bool _value = true );
00119     
00120     bool IsUpperBoundStrict() const;
00121     void SetUpperBoundStrict( bool _value = true );
00122     
00123     MuteVar::VarType GetType() const;
00124     void SetType( MuteVar::VarType _type);
00125 
00126     //Destructeur
00127     ~NumVar() {}
00128 };
00129 
00130 /*--------------------------------------------------------------------------------------------*/
00137 inline bool operator==( const NumVar & n1, const NumVar & n2)
00138 {
00139   return ( n1.GetVarId()==n2.GetVarId() && n1.GetModel()==n2.GetModel() );
00140 }
00141 
00142 /*--------------------------------------------------------------------------------------------*/
00144 class IntVar:public NumVar
00145 {
00146   public:
00147 
00148 #ifdef COMPILE_FOR_PYTHON
00149     IntVar( Model &_modele,
00150             float lowerBound = 0,
00151             float upperBound = Infinity, // ou MaxInt, il faut voir
00152             const std::string & nom = "unknow" )
00153     :NumVar(_modele,lowerBound,upperBound,MuteVar::INT,nom)
00154     {}  
00155 #else
00156     IntVar( Model &_modele,
00157             int lowerBound = 0,
00158             int upperBound = Infinity, // ou MaxInt, il faut voir
00159             const std::string & nom = "unknow" )
00160     :NumVar( _modele,
00161              (lowerBound > -MaxInt? static_cast<float>(lowerBound) : -Infinity),
00162              (upperBound <  MaxInt? static_cast<float>(upperBound) :  Infinity),
00163              MuteVar::INT,nom)
00164     {}
00165 
00166     IntVar(Model & _modele,
00167            const std::string & _nom = "unknow" )
00168     :NumVar(_modele,0,Infinity,MuteVar::INT,_nom)
00169     {}
00170 
00171 #endif  
00172     
00173 };
00174 
00176 class FloatVar:public NumVar
00177 {
00178   public:
00179     FloatVar( Model &_modele,
00180             float lowerBound = 0,
00181             float upperBound = Infinity,
00182             const std::string & nom = "unknow" )
00183     :NumVar(_modele,lowerBound,upperBound,MuteVar::FLOAT,nom)
00184     {}
00185     
00186     FloatVar(Model & _modele,
00187            const std::string & _nom = "unknow" )
00188     :NumVar(_modele,0,Infinity,MuteVar::FLOAT,_nom)
00189     {}  
00190 };
00191 
00193 class BoolVar:public NumVar
00194 {
00195   public:
00196     BoolVar( Model &_modele,
00197             const std::string & nom = "unknow" )
00198     :NumVar(_modele,0.0f,1.0f,MuteVar::BOOL,nom)
00199     {}
00200 };
00201 
00202 #ifdef COMPILE_FOR_PYTHON
00203     void export_NumVar();
00204 #endif
00205 
00206 }
00207 
00208 #endif

Généré le Sun Oct 2 19:13:11 2005 pour Modelib par  doxygen 1.4.4