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

Num.h

00001 #ifndef __NUM_H_
00002 #define __NUM_H_
00003 
00004 #include "MuteVar.h" //pour MuteVar::VarType
00005 
00007 
00013 class Num
00014 {
00015   protected:
00016   MuteVar::VarType type; 
00017   float value; 
00018   public:
00020     Num(MuteVar::VarType _type = MuteVar::FLOAT,float _value = 0)
00021     : type(_type) {*this = _value;}
00025     Num(int entier):type( MuteVar::INT ), value( static_cast<float>(entier) ) {}
00029     Num(unsigned int entier):type( MuteVar::INT ), value( static_cast<float>(entier) ) {}
00033     Num(float _value):type( MuteVar::FLOAT ), value( _value ) {}
00037     Num(double _value):type( MuteVar::FLOAT), value( static_cast<float>(_value) ) {}
00039     Num(const Num & _n):type(_n.type), value(_n.value) {}
00041     Num & operator= (const Num & _n)
00042     {
00043       type = _n.type;
00044       value = _n.value;
00045       return *this;
00046     }
00048     Num & operator= ( float _value )
00049     {
00050       switch(type)
00051       {
00052           case MuteVar::FLOAT:
00053             value = _value;
00054           break;
00055           case MuteVar::INT:
00056             value = static_cast<int>(_value);
00057           break;
00058           case MuteVar::BOOL:
00059             value = _value;
00060           break;
00061       }
00062       return *this;
00063     };      
00064    
00068     float GetValue() const {return value;}
00069 
00073     void SetValue( float f) { *this = f;}
00077     MuteVar::VarType GetType() const { return type; }
00078     
00082     void SetType(MuteVar::VarType _type)  { type = _type; }
00083 
00084     ~Num() {}
00085     
00086 };
00087 
00089 class Int:public Num
00090 {
00091   public:
00093     Int(int _entier = 0):Num(MuteVar::INT, static_cast<float>(_entier)) {}
00094 };  
00095 
00097 class Float:public Num
00098 {
00099   public:
00101     Float(float flottant = 0.0f):Num(MuteVar::FLOAT, flottant) {}
00102 };
00103 
00105 class Bool:public Num
00106 {
00107   public:
00109     Bool(bool booleen = false):Num(MuteVar::BOOL, (booleen?1.0f:0.0f)) {}
00110 };  
00111   
00112 
00113 #endif

Généré le Mon Jul 18 23:07:40 2005 pour Modelib par doxygen 1.3.6