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
00039
00040
00046 #ifndef CCXX_NUMBERS_H_
00047 #define CCXX_NUMBERS_H_
00048
00049 #ifndef CCXX_MISSING_H_
00050 #include <cc++/missing.h>
00051 #endif
00052
00053 #ifndef CCXX_STRCHAR_H_
00054 #include <cc++/strchar.h>
00055 #endif
00056
00057 #ifndef CCXX_STRING_H_
00058 #include <cc++/string.h>
00059 #endif
00060
00061 #include <ctime>
00062
00063 #ifdef CCXX_NAMESPACES
00064 namespace ost {
00065 #ifdef __BORLANDC__
00066 using std::tm;
00067 using std::time_t;
00068 #endif
00069 #endif
00070
00079 class __EXPORT Number
00080 {
00081 protected:
00082 char *buffer;
00083 unsigned size;
00084
00085 public:
00091 Number(char *buffer, unsigned size);
00092
00093 void setValue(long value);
00094 const char *getBuffer() const
00095 {return buffer;};
00096
00097 long getValue() const;
00098
00099 long operator()()
00100 {return getValue();};
00101
00102 operator long()
00103 {return getValue();};
00104
00105 operator char*()
00106 {return buffer;};
00107
00108 long operator=(const long value);
00109 long operator+=(const long value);
00110 long operator-=(const long value);
00111 long operator--();
00112 long operator++();
00113 int operator==(const Number &num);
00114 int operator!=(const Number &num);
00115 int operator<(const Number &num);
00116 int operator<=(const Number &num);
00117 int operator>(const Number &num);
00118 int operator>=(const Number &num);
00119
00120 friend long operator+(const Number &num, const long val);
00121 friend long operator+(const long val, const Number &num);
00122 friend long operator-(const Number &num, long val);
00123 friend long operator-(const long val, const Number &num);
00124 };
00125
00126 class __EXPORT ZNumber : public Number
00127 {
00128 public:
00129 ZNumber(char *buf, unsigned size);
00130 void setValue(long value);
00131 long operator=(long value);
00132 };
00133
00142 class __EXPORT Date
00143 {
00144 protected:
00145 long julian;
00146
00147 protected:
00148 void toJulian(long year, long month, long day);
00149 void fromJulian(char *buf) const;
00150
00155 virtual void update(void)
00156 {return;};
00157
00158 public:
00159
00160 Date(time_t tm);
00161 Date(tm *dt);
00162 Date(char *str, size_t size = 0);
00163 Date(int year, unsigned month, unsigned day);
00164 Date();
00165
00166 int getYear(void) const;
00167 unsigned getMonth(void) const;
00168 unsigned getDay(void) const;
00169 unsigned getDayOfWeek(void) const;
00170 char *getDate(char *buffer) const;
00171 time_t getDate(void) const;
00172 time_t getDate(tm *buf) const;
00173 long getValue(void) const;
00174 void setDate(const char *str, size_t size = 0);
00175 bool isValid(void) const;
00176
00177 friend Date operator+(const Date &date, const long val);
00178 friend Date operator-(const Date &date, const long val);
00179 friend Date operator+(const long val, const Date &date);
00180 friend Date operator-(const long val, const Date &date);
00181
00182 operator long() const
00183 {return getValue();};
00184
00185 String operator()() const;
00186 Date& operator++();
00187 Date& operator--();
00188 Date& operator+=(const long val);
00189 Date& operator-=(const long val);
00190 int operator==(const Date &date);
00191 int operator!=(const Date &date);
00192 int operator<(const Date &date);
00193 int operator<=(const Date &date);
00194 int operator>(const Date &date);
00195 int operator>=(const Date &date);
00196 bool operator!() const
00197 {return !isValid();};
00198 };
00199
00209 class __EXPORT Time
00210 {
00211 protected:
00212 long seconds;
00213
00214 protected:
00215 void toSeconds(int hour, int minute, int second);
00216 void fromSeconds(char *buf) const;
00217 virtual void Update(void)
00218 {return;};
00219
00220 public:
00221 Time(time_t tm);
00222 Time(tm *dt);
00223 Time(char *str, size_t size = 0);
00224 Time(int hour, int minute, int second);
00225 Time();
00226
00227 long getValue(void) const;
00228 int getHour(void) const;
00229 int getMinute(void) const;
00230 int getSecond(void) const;
00231 char *getTime(char *buffer) const;
00232 time_t getTime(void) const;
00233 tm *getTime(tm *buf) const;
00234 void setTime(char *str, size_t size = 0);
00235 bool isValid(void) const;
00236
00237 friend Time operator+(const Time &time1, const Time &time2);
00238 friend Time operator-(const Time &time1, const Time &time2);
00239 friend Time operator+(const Time &time, const int val);
00240 friend Time operator-(const Time &time, const int val);
00241 friend Time operator+(const int val, const Time &time);
00242 friend Time operator-(const int val, const Time &time);
00243
00244 operator long()
00245 {return getValue();};
00246
00247 String operator()() const;
00248 Time& operator++();
00249 Time& operator--();
00250 Time& operator+=(const int val);
00251 Time& operator-=(const int val);
00252 int operator==(const Time &time);
00253 int operator!=(const Time &time);
00254 int operator<(const Time &time);
00255 int operator<=(const Time &time);
00256 int operator>(const Time &time);
00257 int operator>=(const Time &time);
00258 bool operator!() const
00259 {return !isValid();};
00260 };
00261
00272 class __EXPORT Datetime : public Date, public Time
00273 {
00274 public:
00275 Datetime(time_t tm);
00276 Datetime(tm *dt);
00277 Datetime(char *str, size_t size = 0);
00278 Datetime(int year, unsigned month, unsigned day,
00279 int hour, int minute, int second);
00280 Datetime();
00281
00282 char *getDatetime(char *buffer) const;
00283 time_t getDatetime(void) const;
00284 bool isValid(void) const;
00285
00286 Datetime& operator=(const Datetime datetime);
00287 Datetime& operator+=(const Datetime &datetime);
00288 Datetime& operator-=(const Datetime &datetime);
00289 Datetime& operator+=(const Time &time);
00290 Datetime& operator-=(const Time &time);
00291
00292 int operator==(const Datetime&);
00293 int operator!=(const Datetime&);
00294 int operator<(const Datetime&);
00295 int operator<=(const Datetime&);
00296 int operator>(const Datetime&);
00297 int operator>=(const Datetime&);
00298 bool operator!() const;
00299
00300 String strftime(const char *format) const;
00301 };
00302
00309 class __EXPORT DateNumber : public Number, public Date
00310 {
00311 protected:
00312 void update(void)
00313 {fromJulian(buffer);};
00314
00315 public:
00316 DateNumber(char *buffer);
00317 };
00318
00319 #ifdef CCXX_NAMESPACES
00320 };
00321 #endif
00322
00323 #endif
00324