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

NumVarArray.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 __NUMVARARRAY_H
00033 #define __NUMVARARRAY_H
00034 
00035 #include "Config.h"
00036 #include "Constant.h"
00037 #include "MuteVar.h"
00038 
00039 #include <vector>
00040 #include <string>
00041 #include <stdexcept>
00042 
00043 namespace Modelib {
00044 
00045 //Pour éviter les définitions circulaire
00046 class Model;
00047 class NumVar;
00048 
00050 
00055 class NumVarArray
00056 {
00057   protected:
00058   Model * modele;                   
00059   std::vector<NumVar *> varArray;    
00060   MuteVar::VarType type;             
00061 
00062   public:
00064     NumVarArray():modele(0),type(MuteVar::FLOAT) {}
00065 
00066     NumVarArray( Model & _modele,
00067                  unsigned size = 0,
00068                  float _lb= 0,
00069                  float _ub= Infinity,
00070                  MuteVar::VarType _type = MuteVar::FLOAT,
00071                  const std::string & nom = "unknow",
00072                  const std::string & fin = "");
00073 
00074     NumVarArray( const NumVarArray & nva );
00075     
00076     NumVarArray( const std::vector<NumVar> & nva );
00077 
00078     NumVarArray & operator= ( const NumVarArray & nva );
00079 
00083     unsigned Size() const { return varArray.size();}
00088     NumVar& operator[] (unsigned n) const
00089     {
00090         if( n < varArray.size() )
00091             return *(varArray[n]);
00092         else
00093             throw std::out_of_range("NumVarray::operator[] : index out of range");
00094     }
00100 #ifndef COMPILE_FOR_PYTHON    
00101     NumVar * Get(unsigned n) const 
00102     {
00103         if( n < varArray.size() )
00104             return varArray[n];
00105         else
00106             throw std::out_of_range("NumVarray::Get : index out of range");
00107     }
00108 #else
00109     NumVar&   Get(unsigned n) const 
00110     {
00111         if( n < varArray.size() )
00112             return *(varArray[n]);
00113         else
00114             throw std::out_of_range("NumVarray::Get : index out of range");
00115     }
00116 #endif
00117 
00120     MuteVar::VarType GetType() const { return type;}
00121 
00122     ~NumVarArray();
00123 
00124 #ifdef COMPILE_FOR_PYTHON
00125     NumVar&   GetItem(unsigned n) const      {return *(varArray[n]);}
00126     void     SetItem(NumVar* _n, unsigned n) {varArray[n] = _n;  }
00127 #endif
00128 
00129 
00130 };
00131 
00132 /*--------------------------------------------------------------------------------------------*/
00134 
00135 class IntVarArray: public NumVarArray
00136 {
00137   public:
00138 #ifndef COMPILE_FOR_PYTHON    
00139    IntVarArray( Model &_modele,
00140                  unsigned size=0,
00141                  int _lb= 0,
00142                  int _ub= Infinity,  // ou MaxInt à voir
00143                  const std::string & nom = "unknow",
00144                  const std::string & fin = "")
00145     :NumVarArray( _modele,size,static_cast<float>(_lb),static_cast<float>(_ub),MuteVar::INT,nom,fin) {}
00146 #else
00147     IntVarArray( Model &_modele,
00148                    unsigned size=0,
00149                    float _lb= 0,
00150                    float _ub= Infinity,
00151                    const std::string & nom = "unknow",
00152                    const std::string & fin = "")
00153     :NumVarArray( _modele,size,_lb,_ub,MuteVar::INT,nom,fin) {}
00154 #endif
00155 };
00156 
00158 class FloatVarArray: public NumVarArray
00159 {
00160   public:
00161     FloatVarArray( Model &_modele,
00162                    unsigned size=0,
00163                    float _lb= 0.0f,
00164                    float _ub= Infinity,
00165                    const std::string & nom = "unknow",
00166                  const std::string & fin = "")
00167     :NumVarArray( _modele,size,_lb,_ub,MuteVar::FLOAT,nom,fin) {}
00168 };
00169 
00171 class BoolVarArray: public NumVarArray
00172 {
00173   public:
00174     BoolVarArray( Model &_modele,
00175                   unsigned size=0,
00176                   const std::string & nom = "unknow",
00177                  const std::string & fin = "")
00178     :NumVarArray( _modele,size,0.0f,1.0f,MuteVar::BOOL,nom,fin) {}
00179 };
00180 
00181 #ifdef COMPILE_FOR_PYTHON
00182     void export_NumVarArray();
00183 #endif
00184 
00185 }
00186 
00187 #endif

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