UCommon
/usr/src/RPM/BUILD/ucommon-6.3.3/inc/ucommon/numbers.h
Go to the documentation of this file.
00001 // Copyright (C) 2006-2014 David Sugar, Tycho Softworks.
00002 // Copyright (C) 2015 Cherokees of Idaho.
00003 //
00004 // This file is part of GNU uCommon C++.
00005 //
00006 // GNU uCommon C++ is free software: you can redistribute it and/or modify
00007 // it under the terms of the GNU Lesser General Public License as published
00008 // by the Free Software Foundation, either version 3 of the License, or
00009 // (at your option) any later version.
00010 //
00011 // GNU uCommon C++ is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public License
00017 // along with GNU uCommon C++.  If not, see <http://www.gnu.org/licenses/>.
00018 
00027 #ifndef _UCOMMON_NUMBERS_H_
00028 #define _UCOMMON_NUMBERS_H_
00029 
00030 #ifndef _UCOMMON_CONFIG_H_
00031 #include <ucommon/platform.h>
00032 #endif
00033 
00034 namespace ucommon {
00035 
00047 class __EXPORT Number
00048 {
00049 protected:
00050     char *buffer;
00051     unsigned size;
00052 
00053 public:
00059     Number(char *buffer, unsigned size);
00060 
00065     void set(long value);
00066 
00071     inline const char *c_str() const
00072         {return buffer;}
00073 
00078     long get() const;
00079 
00084     inline long operator()() const
00085         {return get();}
00086 
00091     inline operator long() const
00092         {return get();}
00093 
00098     inline operator char*() const
00099         {return buffer;}
00100 
00106     long operator=(long value);
00107 
00113     long operator=(const Number& number);
00114 
00120     long operator+=(const long value);
00121 
00127     long operator-=(const long value);
00128 
00133     long operator--();
00134 
00139     long operator++();
00140 
00141     inline bool operator==(const long value) const
00142         {return get() == value;}
00143 
00144     inline bool operator!=(const long value) const
00145         {return get() != value;}
00146 
00147     inline bool operator<(const long value) const
00148         {return get() < value;}
00149 
00150     inline bool operator>(const long value) const
00151         {return get() > value;}
00152 
00153     inline bool operator<=(const long value) const
00154         {return get() <= value;}
00155 
00156     inline bool operator>=(const long value) const
00157         {return get() >= value;}
00158 };
00159 
00166 class __EXPORT ZNumber : public Number
00167 {
00168 public:
00174     ZNumber(char *pointer, unsigned size);
00175 
00181     void set(long value);
00182 
00188     long operator=(long value);
00189 };
00190 
00194 typedef Number  number_t;
00195 
00199 typedef ZNumber znumber_t;
00200 
00206 template<typename T>
00207 inline const T abs(const T& value)
00208 {
00209     if(value < (T)0)
00210         return -value;
00211     return value;
00212 }
00213 
00214 
00221 template<typename T>
00222 inline const T (min)(const T& v1, const T& v2)
00223 {
00224     return ((v1 < v2) ? v1 : v2);
00225 }
00226 
00233 template<typename T>
00234 inline const T (max)(const T& v1, const T& v2)
00235 {
00236     return ((v1 > v2) ? v1 : v2);
00237 }
00238 
00239 } // namespace ucommon
00240 
00241 #endif