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
00038
00044 #ifndef CCXX_NUMBERS_H_
00045 #define CCXX_NUMBERS_H_
00046
00047 #ifndef CCXX_THREAD_H_
00048 #include <cc++/thread.h>
00049 #endif
00050
00051 #ifndef CCXX_MISSING_H_
00052 #include <cc++/missing.h>
00053 #endif
00054
00055 #ifndef CCXX_STRCHAR_H_
00056 #include <cc++/strchar.h>
00057 #endif
00058
00059 #ifndef CCXX_STRING_H_
00060 #include <cc++/string.h>
00061 #endif
00062
00063 #ifndef CCXX_THREAD_H_
00064 #include <cc++/thread.h>
00065 #endif
00066
00067 #include <ctime>
00068
00069 #ifdef CCXX_NAMESPACES
00070 namespace ost {
00071 #ifdef __BORLANDC__
00072 using std::tm;
00073 using std::time_t;
00074 #endif
00075 #endif
00076
00085 class __EXPORT Number
00086 {
00087 protected:
00088 char *buffer;
00089 unsigned size;
00090
00091 public:
00097 Number(char *buffer, unsigned size);
00098
00099 void setValue(long value);
00100 const char *getBuffer() const
00101 {return buffer;};
00102
00103 long getValue() const;
00104
00105 long operator()()
00106 {return getValue();};
00107
00108 operator long()
00109 {return getValue();};
00110
00111 operator char*()
00112 {return buffer;};
00113
00114 long operator=(const long value);
00115 long operator+=(const long value);
00116 long operator-=(const long value);
00117 long operator--();
00118 long operator++();
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 int operator>=(const Number &num);
00125
00126 friend long operator+(const Number &num, const long val);
00127 friend long operator+(const long val, const Number &num);
00128 friend long operator-(const Number &num, long val);
00129 friend long operator-(const long val, const Number &num);
00130 };
00131
00132 class __EXPORT ZNumber : public Number
00133 {
00134 public:
00135 ZNumber(char *buf, unsigned size);
00136 void setValue(long value);
00137 long operator=(long value);
00138 };
00139
00148 class __EXPORT Date
00149 {
00150 protected:
00151 long julian;
00152
00153 protected:
00154 void toJulian(long year, long month, long day);
00155 void fromJulian(char *buf) const;
00156
00161 virtual void update(void);
00162
00163 public:
00164
00165 Date(time_t tm);
00166 Date(tm *dt);
00167 Date(char *str, size_t size = 0);
00168 Date(int year, unsigned month, unsigned day);
00169 Date();
00170 virtual ~Date();
00171
00172 int getYear(void) const;
00173 unsigned getMonth(void) const;
00174 unsigned getDay(void) const;
00175 unsigned getDayOfWeek(void) const;
00176 char *getDate(char *buffer) const;
00177 time_t getDate(void) const;
00178 time_t getDate(tm *buf) const;
00179 long getValue(void) const;
00180 void setDate(const char *str, size_t size = 0);
00181 bool isValid(void) const;
00182
00183 friend Date operator+(const Date &date, const long val);
00184 friend Date operator-(const Date &date, const long val);
00185 friend Date operator+(const long val, const Date &date);
00186 friend Date operator-(const long val, const Date &date);
00187
00188 operator long() const
00189 {return getValue();};
00190
00191 String operator()() const;
00192 Date& operator++();
00193 Date& operator--();
00194 Date& operator+=(const long val);
00195 Date& operator-=(const long val);
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 int operator>(const Date &date);
00201 int operator>=(const Date &date);
00202 bool operator!() const
00203 {return !isValid();};
00204 };
00205
00215 class __EXPORT Time
00216 {
00217 protected:
00218 long seconds;
00219
00220 protected:
00221 void toSeconds(int hour, int minute, int second);
00222 void fromSeconds(char *buf) const;
00223 virtual void update(void);
00224
00225 public:
00226 Time(time_t tm);
00227 Time(tm *dt);
00228 Time(char *str, size_t size = 0);
00229 Time(int hour, int minute, int second);
00230 Time();
00231 virtual ~Time();
00232
00233 long getValue(void) const;
00234 int getHour(void) const;
00235 int getMinute(void) const;
00236 int getSecond(void) const;
00237 char *getTime(char *buffer) const;
00238 time_t getTime(void) const;
00239 tm *getTime(tm *buf) const;
00240 void setTime(char *str, size_t size = 0);
00241 bool isValid(void) const;
00242
00243 friend Time operator+(const Time &time1, const Time &time2);
00244 friend Time operator-(const Time &time1, const Time &time2);
00245 friend Time operator+(const Time &time, const int val);
00246 friend Time operator-(const Time &time, const int val);
00247 friend Time operator+(const int val, const Time &time);
00248 friend Time operator-(const int val, const Time &time);
00249
00250 operator long()
00251 {return getValue();};
00252
00253 String operator()() const;
00254 Time& operator++();
00255 Time& operator--();
00256 Time& operator+=(const int val);
00257 Time& operator-=(const int val);
00258 int operator==(const Time &time);
00259 int operator!=(const Time &time);
00260 int operator<(const Time &time);
00261 int operator<=(const Time &time);
00262 int operator>(const Time &time);
00263 int operator>=(const Time &time);
00264 bool operator!() const
00265 {return !isValid();};
00266 };
00267
00278 class __EXPORT Datetime : public Date, public Time
00279 {
00280 public:
00281 Datetime(time_t tm);
00282 Datetime(tm *dt);
00283 Datetime(const char *str, size_t size = 0);
00284 Datetime(int year, unsigned month, unsigned day,
00285 int hour, int minute, int second);
00286 Datetime();
00287 virtual ~Datetime();
00288
00289 char *getDatetime(char *buffer) const;
00290 time_t getDatetime(void) const;
00291 bool isValid(void) const;
00292
00293 Datetime& operator=(const Datetime datetime);
00294 Datetime& operator+=(const Datetime &datetime);
00295 Datetime& operator-=(const Datetime &datetime);
00296 Datetime& operator+=(const Time &time);
00297 Datetime& operator-=(const Time &time);
00298
00299 int operator==(const Datetime&);
00300 int operator!=(const Datetime&);
00301 int operator<(const Datetime&);
00302 int operator<=(const Datetime&);
00303 int operator>(const Datetime&);
00304 int operator>=(const Datetime&);
00305 bool operator!() const;
00306
00307 String strftime(const char *format) const;
00308 };
00309
00316 class __EXPORT DateNumber : public Number, public Date
00317 {
00318 protected:
00319 void update(void)
00320 {fromJulian(buffer);};
00321
00322 public:
00323 DateNumber(char *buffer);
00324 virtual ~DateNumber();
00325 };
00326
00327 #ifdef CCXX_NAMESPACES
00328 }
00329 #endif
00330
00331 #endif
00332