UCommon
|
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 00147 class __EXPORT ZNumber : public Number 00148 { 00149 public: 00155 ZNumber(char *pointer, unsigned size); 00156 00162 void set(long value); 00163 00169 long operator=(long value); 00170 }; 00171 00175 typedef Number number_t; 00176 00180 typedef ZNumber znumber_t; 00181 00187 template<typename T> 00188 inline const T abs(const T& value) 00189 { 00190 if(value < (T)0) 00191 return -value; 00192 return value; 00193 } 00194 00195 00202 template<typename T> 00203 inline const T (min)(const T& v1, const T& v2) 00204 { 00205 return ((v1 < v2) ? v1 : v2); 00206 } 00207 00214 template<typename T> 00215 inline const T (max)(const T& v1, const T& v2) 00216 { 00217 return ((v1 > v2) ? v1 : v2); 00218 } 00219 00220 END_NAMESPACE 00221 00222 #endif