Modelib: Fichier source de Num.h

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

# Num.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 __NUM_H_
    00033 #define __NUM_H_
    00034
    00035 #include "MuteVar.h" //pour MuteVar::VarType
    00036
    00037 namespace Modelib {
    00038
    00040
    00046 class Num
    00047 {
    00048   protected:
    00049   MuteVar::VarType type;
    00050   float value;
    00051   public:
    00053     Num(MuteVar::VarType _type = MuteVar::FLOAT,float _value = 0)
    00054     : type(_type) {*this = _value;}
    00058     Num(int entier):type( MuteVar::INT ), value( static_cast<float>(entier) ) {}
    00062     Num(unsigned int entier):type( MuteVar::INT ), value( static_cast<float>(entier) ) {}
    00066     Num(float _value):type( MuteVar::FLOAT ), value( _value ) {}
    00070     Num(double _value):type( MuteVar::FLOAT), value( static_cast<float>(_value) ) {}
    00072     Num(const Num & _n):type(_n.type), value(_n.value) {}
    00074     Num & operator= (const Num & _n)
    00075     {
    00076       type = _n.type;
    00077       value = _n.value;
    00078       return *this;
    00079     }
    00081     Num & operator= ( float _value )
    00082     {
    00083       switch(type)
    00084       {
    00085           case MuteVar::FLOAT:
    00086             value = _value;
    00087           break;
    00088           case MuteVar::INT:
    00089             value = static_cast<int>(_value);
    00090           break;
    00091           case MuteVar::BOOL:
    00092             value = _value;
    00093           break;
    00094       }
    00095       return *this;
    00096     };
    00097
    00101     float GetValue() const {return value;}
    00102
    00106     void SetValue( float f) { *this = f;}
    00110     MuteVar::VarType GetType() const { return type; }
    00111
    00115     void SetType(MuteVar::VarType _type)  { type = _type; }
    00116
    00117     ~Num() {}
    00118
    00119 };
    00120
    00122 class Int:public Num
    00123 {
    00124   public:
    00126     Int(int _entier = 0):Num(MuteVar::INT, static_cast<float>(_entier)) {}
    00127 };
    00128
    00130 class Float:public Num
    00131 {
    00132   public:
    00134     Float(float flottant = 0.0f):Num(MuteVar::FLOAT, flottant) {}
    00135 };
    00136
    00138 class Bool:public Num
    00139 {
    00140   public:
    00142     Bool(bool booleen = false):Num(MuteVar::BOOL, (booleen?1.0f:0.0f)) {}
    00143 };
    00144
    00145 }
    00146
    00147 #endif