00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00043 #ifndef CCXX_NUMBERS_H_
00044 #define CCXX_NUMBERS_H_
00045
00046 #ifndef CCXX_THREAD_H_
00047 #include <cc++/thread.h>
00048 #endif
00049
00050 #ifndef CCXX_MISSING_H_
00051 #include <cc++/missing.h>
00052 #endif
00053
00054 #ifndef CCXX_STRCHAR_H_
00055 #include <cc++/strchar.h>
00056 #endif
00057
00058 #ifndef CCXX_STRING_H_
00059 #include <cc++/string.h>
00060 #endif
00061
00062 #ifndef CCXX_THREAD_H_
00063 #include <cc++/thread.h>
00064 #endif
00065
00066 #include <ctime>
00067
00068 #ifdef CCXX_NAMESPACES
00069 namespace ost {
00070 #ifdef __BORLANDC__
00071 using std::tm;
00072 using std::time_t;
00073 #endif
00074 #endif
00075
00084 class __EXPORT Number
00085 {
00086 protected:
00087 char *buffer;
00088 unsigned size;
00089
00090 public:
00096 Number(char *buffer, unsigned size);
00097
00098 void setValue(long value);
00099 const char *getBuffer() const
00100 {return buffer;};
00101
00102 long getValue() const;
00103
00104 long operator()()
00105 {return getValue();};
00106
00107 operator long()
00108 {return getValue();};
00109
00110 operator char*()
00111 {return buffer;};
00112
00113 long operator=(const long value);
00114 long operator+=(const long value);
00115 long operator-=(const long value);
00116 long operator--();
00117 long operator++();
00118 int operator==(const Number &num);
00119 int operator!=(const Number &num);
00120 int operator<(const Number &num);
00121 int operator<=(const Number &num);
00122 int operator>(const Number &num);
00123 int operator>=(const Number &num);
00124
00125 friend long operator+(const Number &num, const long val);
00126 friend long operator+(const long val, const Number &num);
00127 friend long operator-(const Number &num, long val);
00128 friend long operator-(const long val, const Number &num);
00129 };
00130
00131 class __EXPORT ZNumber : public Number
00132 {
00133 public:
00134 ZNumber(char *buf, unsigned size);
00135 void setValue(long value);
00136 long operator=(long value);
00137 };
00138
00147 class __EXPORT Date
00148 {
00149 protected:
00150 long julian;
00151
00152 protected:
00153 void toJulian(long year, long month, long day);
00154 void fromJulian(char *buf) const;
00155
00160 virtual void update(void);
00161
00162 public:
00163
00164 Date(time_t tm);
00165 Date(tm *dt);
00166 Date(char *str, size_t size = 0);
00167 Date(int year, unsigned month, unsigned day);
00168 Date();
00169
00170 int getYear(void) const;
00171 unsigned getMonth(void) const;
00172 unsigned getDay(void) const;
00173 unsigned getDayOfWeek(void) const;
00174 char *getDate(char *buffer) const;
00175 time_t getDate(void) const;
00176 time_t getDate(tm *buf) const;
00177 long getValue(void) const;
00178 void setDate(const char *str, size_t size = 0);
00179 bool isValid(void) const;
00180
00181 friend Date operator+(const Date &date, const long val);
00182 friend Date operator-(const Date &date, const long val);
00183 friend Date operator+(const long val, const Date &date);
00184 friend Date operator-(const long val, const Date &date);
00185
00186 operator long() const
00187 {return getValue();};
00188
00189 String operator()() const;
00190 Date& operator++();
00191 Date& operator--();
00192 Date& operator+=(const long val);
00193 Date& operator-=(const long val);
00194 int operator==(const Date &date);
00195 int operator!=(const Date &date);
00196 int operator<(const Date &date);
00197 int operator<=(const Date &date);
00198 int operator>(const Date &date);
00199 int operator>=(const Date &date);
00200 bool operator!() const
00201 {return !isValid();};
00202 };
00203
00213 class __EXPORT Time
00214 {
00215 protected:
00216 long seconds;
00217
00218 protected:
00219 void toSeconds(int hour, int minute, int second);
00220 void fromSeconds(char *buf) const;
00221 virtual void update(void);
00222
00223 public:
00224 Time(time_t tm);
00225 Time(tm *dt);
00226 Time(char *str, size_t size = 0);
00227 Time(int hour, int minute, int second);
00228 Time();
00229
00230 long getValue(void) const;
00231 int getHour(void) const;
00232 int getMinute(void) const;
00233 int getSecond(void) const;
00234 char *getTime(char *buffer) const;
00235 time_t getTime(void) const;
00236 tm *getTime(tm *buf) const;
00237 void setTime(char *str, size_t size = 0);
00238 bool isValid(void) const;
00239
00240 friend Time operator+(const Time &time1, const Time &time2);
00241 friend Time operator-(const Time &time1, const Time &time2);
00242 friend Time operator+(const Time &time, const int val);
00243 friend Time operator-(const Time &time, const int val);
00244 friend Time operator+(const int val, const Time &time);
00245 friend Time operator-(const int val, const Time &time);
00246
00247 operator long()
00248 {return getValue();};
00249
00250 String operator()() const;
00251 Time& operator++();
00252 Time& operator--();
00253 Time& operator+=(const int val);
00254 Time& operator-=(const int val);
00255 int operator==(const Time &time);
00256 int operator!=(const Time &time);
00257 int operator<(const Time &time);
00258 int operator<=(const Time &time);
00259 int operator>(const Time &time);
00260 int operator>=(const Time &time);
00261 bool operator!() const
00262 {return !isValid();};
00263 };
00264
00275 class __EXPORT Datetime : public Date, public Time
00276 {
00277 public:
00278 Datetime(time_t tm);
00279 Datetime(tm *dt);
00280 Datetime(const char *str, size_t size = 0);
00281 Datetime(int year, unsigned month, unsigned day,
00282 int hour, int minute, int second);
00283 Datetime();
00284
00285 char *getDatetime(char *buffer) const;
00286 time_t getDatetime(void) const;
00287 bool isValid(void) const;
00288
00289 Datetime& operator=(const Datetime datetime);
00290 Datetime& operator+=(const Datetime &datetime);
00291 Datetime& operator-=(const Datetime &datetime);
00292 Datetime& operator+=(const Time &time);
00293 Datetime& operator-=(const Time &time);
00294
00295 int operator==(const Datetime&);
00296 int operator!=(const Datetime&);
00297 int operator<(const Datetime&);
00298 int operator<=(const Datetime&);
00299 int operator>(const Datetime&);
00300 int operator>=(const Datetime&);
00301 bool operator!() const;
00302
00303 String strftime(const char *format) const;
00304 };
00305
00312 class __EXPORT DateNumber : public Number, public Date
00313 {
00314 protected:
00315 void update(void)
00316 {fromJulian(buffer);};
00317
00318 public:
00319 DateNumber(char *buffer);
00320 };
00321
00322 #ifdef CCXX_NAMESPACES
00323 }
00324 #endif
00325
00326 #endif
00327