Modelib: NumVarArray.h Source File

Page principale | Hiérarchie des classes | Liste des composants | Liste des fichiers | Composants

# NumVarArray.h

    00001 #ifndef __NUMVARARRAY_H
    00002 #define __NUMVARARRAY_H
    00003
    00004 #include "Config.h"
    00005 #include "Constant.h"
    00006 #include "MuteVar.h"
    00007
    00008 #include <vector>
    00009 #include <string>
    00010 #include <stdexcept>
    00011
    00012 //Pour éviter les définitions circulaire
    00013 class Model;
    00014 class NumVar;
    00015
    00017
    00022 class NumVarArray
    00023 {
    00024   protected:
    00025   Model * modele;
    00026   std::vector<NumVar *> varArray;
    00027   MuteVar::VarType type;
    00028
    00029   public:
    00031     NumVarArray():modele(0),type(MuteVar::FLOAT) {}
    00032
    00033     NumVarArray( Model & _modele,
    00034                  unsigned size = 0,
    00035                  float _lb= 0,
    00036                  float _ub= Infinity,
    00037                  MuteVar::VarType _type = MuteVar::FLOAT,
    00038                  const std::string & nom = "unknow",
    00039                  const std::string & fin = "");
    00040
    00041     NumVarArray( const NumVarArray & nva );
    00042
    00043     NumVarArray( const std::vector<NumVar> & nva );
    00044
    00045     NumVarArray & operator= ( const NumVarArray & nva );
    00046
    00050     unsigned Size() const { return varArray.size();}
    00055     NumVar& operator[] (unsigned n) const
    00056     {
    00057         if( n < varArray.size() )
    00058             return *(varArray[n]);
    00059         else
    00060             throw std::out_of_range("NumVarray::operator[] : index out of range");
    00061     }
    00067 #ifndef COMPILE_FOR_PYTHON
    00068         NumVar * Get(unsigned n) const
    00069     {
    00070         if( n < varArray.size() )
    00071             return varArray[n];
    00072         else
    00073             throw std::out_of_range("NumVarray::Get : index out of range");
    00074     }
    00075 #else
    00076         NumVar&   Get(unsigned n) const
    00077     {
    00078         if( n < varArray.size() )
    00079             return *(varArray[n]);
    00080         else
    00081             throw std::out_of_range("NumVarray::Get : index out of range");
    00082     }
    00083 #endif
    00084
    00087     MuteVar::VarType GetType() const { return type;}
    00088
    00089     ~NumVarArray();
    00090
    00091 #ifdef COMPILE_FOR_PYTHON
    00092     NumVar&   GetItem(unsigned n) const      {return *(varArray[n]);}
    00093     void     SetItem(NumVar* _n, unsigned n) {varArray[n] = _n;  }
    00094 #endif
    00095
    00096
    00097 };
    00098
    00099 /*--------------------------------------------------------------------------------------------*/
    00101
    00102 class IntVarArray: public NumVarArray
    00103 {
    00104   public:
    00105 #ifndef COMPILE_FOR_PYTHON
    00106    IntVarArray( Model &_modele,
    00107                  unsigned size=0,
    00108                  int _lb= 0,
    00109                  int _ub= Infinity,  // ou MaxInt à voir
    00110                  const std::string & nom = "unknow",
    00111                  const std::string & fin = "")
    00112     :NumVarArray( _modele,size,static_cast<float>(_lb),static_cast<float>(_ub),MuteVar::INT,nom,fin) {}
    00113 #else
    00114     IntVarArray( Model &_modele,
    00115                    unsigned size=0,
    00116                    float _lb= 0,
    00117                    float _ub= Infinity,
    00118                    const std::string & nom = "unknow",
    00119                    const std::string & fin = "")
    00120     :NumVarArray( _modele,size,_lb,_ub,MuteVar::INT,nom,fin) {}
    00121 #endif
    00122 };
    00123
    00125 class FloatVarArray: public NumVarArray
    00126 {
    00127   public:
    00128     FloatVarArray( Model &_modele,
    00129                    unsigned size=0,
    00130                    float _lb= 0.0f,
    00131                    float _ub= Infinity,
    00132                    const std::string & nom = "unknow",
    00133                  const std::string & fin = "")
    00134     :NumVarArray( _modele,size,_lb,_ub,MuteVar::FLOAT,nom,fin) {}
    00135 };
    00136
    00138 class BoolVarArray: public NumVarArray
    00139 {
    00140   public:
    00141     BoolVarArray( Model &_modele,
    00142                   unsigned size=0,
    00143                   const std::string & nom = "unknow",
    00144                  const std::string & fin = "")
    00145     :NumVarArray( _modele,size,0.0f,1.0f,MuteVar::BOOL,nom,fin) {}
    00146 };
    00147
    00148 #ifdef COMPILE_FOR_PYTHON
    00149         void export_NumVarArray();
    00150 #endif
    00151
    00152 #endif