00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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