ucommon/numbers.h

Go to the documentation of this file.
00001 // Copyright (C) 2006-2010 David Sugar, Tycho Softworks.
00002 //
00003 // This file is part of GNU uCommon C++.
00004 //
00005 // GNU uCommon C++ is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU Lesser General Public License as published
00007 // by the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // GNU uCommon C++ is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU Lesser General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser General Public License
00016 // along with GNU uCommon C++.  If not, see <http://www.gnu.org/licenses/>.
00017 
00026 #ifndef _UCOMMON_NUMBERS_H_
00027 #define _UCOMMON_NUMBERS_H_
00028 
00029 #ifndef _UCOMMON_CONFIG_H_
00030 #include <ucommon/platform.h>
00031 #endif
00032 
00033 NAMESPACE_UCOMMON
00034 
00046 class __EXPORT Number
00047 {
00048 protected:
00049     char *buffer;
00050     unsigned size;
00051 
00052 public:
00058     Number(char *buffer, unsigned size);
00059 
00064     void set(long value);
00065 
00070     inline const char *c_str() const
00071         {return buffer;};
00072 
00077     long get() const;
00078 
00083     inline long operator()()
00084         {return get();};
00085 
00090     inline operator long()
00091         {return get();};
00092 
00097     inline operator char*()
00098         {return buffer;};
00099 
00105     long operator=(long value);
00106 
00112     long operator=(const Number& number);
00113 
00119     long operator+=(const long value);
00120 
00126     long operator-=(const long value);
00127 
00132     long operator--();
00133 
00138     long operator++();
00139 
00140     inline bool operator==(const long value) const
00141         {return get() == value;}
00142 
00143     inline bool operator!=(const long value) const
00144         {return get() != value;}
00145 
00146     inline bool operator<(const long value) const
00147         {return get() < value;}
00148 
00149     inline bool operator>(const long value) const
00150         {return get() > value;}
00151 
00152     inline bool operator<=(const long value) const
00153         {return get() <= value;}
00154 
00155     inline bool operator>=(const long value) const
00156         {return get() >= value;}
00157 };
00158 
00165 class __EXPORT ZNumber : public Number
00166 {
00167 public:
00173     ZNumber(char *pointer, unsigned size);
00174 
00180     void set(long value);
00181 
00187     long operator=(long value);
00188 };
00189 
00193 typedef Number  number_t;
00194 
00198 typedef ZNumber znumber_t;
00199 
00205 template<typename T>
00206 inline const T abs(const T& value)
00207 {
00208     if(value < (T)0)
00209         return -value;
00210     return value;
00211 }
00212 
00213 
00220 template<typename T>
00221 inline const T (min)(const T& v1, const T& v2)
00222 {
00223     return ((v1 < v2) ? v1 : v2);
00224 }
00225 
00232 template<typename T>
00233 inline const T (max)(const T& v1, const T& v2)
00234 {
00235     return ((v1 > v2) ? v1 : v2);
00236 }
00237 
00238 END_NAMESPACE
00239 
00240 #endif

Generated on 14 Aug 2013 for UCommon by  doxygen 1.4.7