Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members

unumber.hpp

00001 /* ==================================================== ======== ======= *
00002  *
00003  *  unumber.hh
00004  *  Ubit Project  [Elc][2003]
00005  *  Author: Eric Lecolinet
00006  *
00007  *  Part of the Ubit Toolkit: A Brick Construction Game Model for Creating GUIs
00008  *
00009  *  (C) 1999-2003 Eric Lecolinet @ ENST Paris
00010  *  WWW: http://www.enst.fr/~elc/ubit   Email: elc@enst.fr (subject: ubit)
00011  *
00012  * ***********************************************************************
00013  * COPYRIGHT NOTICE : 
00014  * THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY AND WITHOUT EVEN THE 
00015  * IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. 
00016  * YOU CAN REDISTRIBUTE IT AND/OR MODIFY IT UNDER THE TERMS OF THE GNU 
00017  * GENERAL PUBLIC LICENSE AS PUBLISHED BY THE FREE SOFTWARE FOUNDATION; 
00018  * EITHER VERSION 2 OF THE LICENSE, OR (AT YOUR OPTION) ANY LATER VERSION.
00019  * SEE FILES 'COPYRIGHT' AND 'COPYING' FOR MORE DETAILS.
00020  * ***********************************************************************
00021  *
00022  * ==================================================== [Elc:03] ======= *
00023  * ==================================================== ======== ======= */
00024 
00025 #ifndef _unumber_hh
00026 #define _unumber_hh
00027 //pragma ident  "@(#)unumber.hh ubit:03.02.00"
00028 
00029 /* ==================================================== [Elc:03] ======= */
00030 /* ==================================================== ======== ======= */
00031 
00034 class UIntgBase {
00035 private:
00036   int value;
00037 
00038 public:
00039   UIntgBase(int v = 0)                 : value(v) {}
00040   UIntgBase(const UIntgBase& v)        : value(v.value) {}
00041   UIntgBase(const UFloatBase& v);
00042   UIntgBase(const UStr& v);
00043 
00044   // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
00045 
00046   int getValue() const {return value;}
00047 
00048   virtual void changed(bool update_now) {}
00050 
00051   // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
00052 
00053   void set(int);
00054   void set(const UIntgBase&);
00055   void set(const UFloatBase&);
00056   void set(const UStr&);
00057 
00058   UIntgBase& operator=(int v)               {set(v); return *this;}
00059   UIntgBase& operator=(const UIntgBase& v)  {set(v); return *this;}
00060   UIntgBase& operator=(const UFloatBase& v) {set(v); return *this;}
00061   
00062   UIntgBase& operator=(const UStr& v)       {set(v); return *this;}
00067   // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
00068 
00069   void incr(int);
00070   void incr(const UIntgBase&);
00071   void decr(int);
00072   void decr(const UIntgBase&);
00073 
00074   UIntgBase& operator++()                {incr(1); return *this;}
00075   UIntgBase& operator++(int)             {incr(1); return *this;}
00076   UIntgBase& operator--()                {decr(1); return *this;}
00077   UIntgBase& operator--(int)             {decr(1); return *this;}
00078 
00079   // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
00080 
00081   bool equals(int v)                     const {return value == v;}
00082   bool equals(const UIntgBase& v)        const {return value == v.value;}
00083   bool equals(const UFloatBase& v)       const;
00084 
00085   friend bool operator==(const UIntgBase& v1, int v2) 
00086   {return v1.equals(v2);}
00087 
00088   friend bool operator==(int v1, const UIntgBase& v2) 
00089   {return v2.equals(v1);}
00090 
00091   friend bool operator==(const UIntgBase& v1, const UIntgBase& v2) 
00092   {return v1.equals(v2);}
00093 
00094   friend bool operator==(const UIntgBase& v1, const UFloatBase& v2) 
00095   {return v1.equals(v2);}
00096 
00097   friend bool operator==(const UFloatBase& v1, const UIntgBase& v2) 
00098   {return v2.equals(v1);}
00099 };
00100 
00101 /* ==================================================== [Elc:03] ======= */
00102 /* ==================================================== ======== ======= */
00103 
00106 class UIntg: public UIntgBase, public UBrick {
00107 public:
00108   UIntg(int v = 0)                       : UIntgBase(v) {}
00109   UIntg(const UIntg& v)                  : UIntgBase(v) {}
00110   UIntg(const UIntgBase& v)              : UIntgBase(v) {}
00111   UIntg(const UFloatBase& v)             : UIntgBase(v) {}
00112   UIntg(const UStr& v)                   : UIntgBase(v) {}
00113 
00114   virtual void changed(bool update_now);
00116 
00117   virtual void onChange(UCall&);
00119 
00120   // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
00121 
00122   UIntg& operator=(int v)                {set(v); return *this;}
00123   UIntg& operator=(const UIntg& v)       {set(v); return *this;}
00124   UIntg& operator=(const UIntgBase& v)   {set(v); return *this;}
00125   UIntg& operator=(const UFloatBase& v)  {set(v); return *this;}
00126   
00127   UIntg& operator=(const UStr& v)        {set(v); return *this;}
00131   // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
00132 
00133   UIntg& operator++()                    {incr(1); return *this;}
00134   UIntg& operator++(int)                 {incr(1); return *this;}
00135   UIntg& operator--()                    {decr(1); return *this;}
00136   UIntg& operator--(int)                 {decr(1); return *this;}
00137 };
00138 
00139 /* ==================================================== [Elc:03] ======= */
00140 /* ==================================================== ======== ======= */
00141 
00144 class UFloatBase {
00145 private:
00146   float value;
00147 
00148 public:
00149   UFloatBase(float v = 0.0)                : value(v) {}
00150   UFloatBase(const UFloatBase& v)        : value(v.getValue()) {}
00151   UFloatBase(const UIntgBase& v)         : value(v.getValue()) {}
00152   UFloatBase(const UStr& v);
00153 
00154   // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
00155 
00156   float getValue() const {return value;}
00157 
00158   virtual void changed(bool update_now) {}
00160 
00161   // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
00162 
00163   void set(float);
00164   void set(const UIntgBase&);
00165   void set(const UFloatBase&);
00166   void set(const UStr&);
00167 
00168   UFloatBase& operator=(float v)             {set(v); return *this;}
00169   UFloatBase& operator=(const UFloatBase& v) {set(v); return *this;}
00170   UFloatBase& operator=(const UIntgBase& v)  {set(v); return *this;}  
00171   UFloatBase& operator=(const UStr& v)       {set(v); return *this;}
00175   // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
00176 
00177   void incr(float);
00178   void incr(const UFloatBase&);
00179   void decr(float);
00180   void decr(const UFloatBase&);
00181 
00182   UFloatBase& operator++()               {incr(1.); return *this;}
00183   UFloatBase& operator++(int)            {incr(1.); return *this;}
00184   UFloatBase& operator--()               {decr(1.); return *this;}
00185   UFloatBase& operator--(int)            {decr(1.); return *this;}
00186 
00187   // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
00188 
00189   bool equals(float v)                   const {return value == v;}
00190   bool equals(const UIntgBase& v)        const {return value == v.getValue();}
00191   bool equals(const UFloatBase& v)       const {return value == v.getValue();}
00192 
00193   friend bool operator==(const UFloatBase& v1, float v2)
00194   {return v1.equals(v2);}
00195 
00196   friend bool operator==(float v1, const UFloatBase& v2)
00197   {return v2.equals(v1);}
00198 
00199   friend bool operator==(const UFloatBase& v1, const UFloatBase& v2)
00200   {return v1.equals(v2);}
00201 };
00202 
00203 /* ==================================================== [Elc:03] ======= */
00204 /* ==================================================== ======== ======= */
00205 
00208 class UFloat: public UFloatBase, public UBrick {
00209 public:
00210   UFloat(float v = 0.0)                      : UFloatBase(v) {}
00211   UFloat(const UFloat& v)                : UFloatBase(v) {}
00212   UFloat(const UFloatBase& v)            : UFloatBase(v) {}
00213   UFloat(const UIntgBase& v)             : UFloatBase(v) {}
00214   UFloat(const UStr& v)                  : UFloatBase(v) {}
00215 
00216   virtual void changed(bool update_now);
00218 
00219   virtual void onChange(UCall&);
00221 
00222   // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
00223 
00224   UFloat& operator=(float v)             {set(v); return *this;}
00225   UFloat& operator=(const UFloat& v)     {set(v); return *this;}
00226   UFloat& operator=(const UFloatBase& v) {set(v); return *this;}
00227   UFloat& operator=(const UIntgBase& v)  {set(v); return *this;}  
00228   UFloat& operator=(const UStr& v)       {set(v); return *this;}
00232   // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
00233 
00234   UFloat& operator++()                   {incr(1.); return *this;}
00235   UFloat& operator++(int)                {incr(1.); return *this;}
00236   UFloat& operator--()                   {decr(1.); return *this;}
00237   UFloat& operator--(int)                {decr(1.); return *this;}
00238 };
00239 
00240 
00241 #endif
00242 /* ==================================================== [TheEnd] ======= */
00243 /* ==================================================== [Elc:03] ======= */

Generated on Thu Mar 3 09:57:47 2005 for Ubit[Eric.Lecolinet@enst.fr] by  doxygen 1.4.1