GNU CommonC++
|
00001 // Copyright (C) 1999-2005 Open Source Telecom Corporation. 00002 // Copyright (C) 2006-2010 David Sugar, Tycho Softworks. 00003 // 00004 // This program is free software; you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation; either version 2 of the License, or 00007 // (at your option) any later version. 00008 // 00009 // This program is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with this program; if not, write to the Free Software 00016 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 // 00018 // As a special exception, you may use this file as part of a free software 00019 // library without restriction. Specifically, if other files instantiate 00020 // templates or use macros or inline functions from this file, or you compile 00021 // this file and link it with other files to produce an executable, this 00022 // file does not by itself cause the resulting executable to be covered by 00023 // the GNU General Public License. This exception does not however 00024 // invalidate any other reasons why the executable file might be covered by 00025 // the GNU General Public License. 00026 // 00027 // This exception applies only to the code released under the name GNU 00028 // Common C++. If you copy code from other releases into a copy of GNU 00029 // Common C++, as the General Public License permits, the exception does 00030 // not apply to the code that you add in this way. To avoid misleading 00031 // anyone as to the status of such modified files, you must delete 00032 // this exception notice from them. 00033 // 00034 // If you write modifications of your own for GNU Common C++, it is your choice 00035 // whether to permit this exception to apply to your modifications. 00036 // If you do not wish that, delete this exception notice. 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, int hour, int minute, int second); 00285 Datetime(); 00286 virtual ~Datetime(); 00287 00288 char *getDatetime(char *buffer) const; 00289 time_t getDatetime(void) const; 00290 bool isValid(void) const; 00291 00292 Datetime& operator=(const Datetime datetime); 00293 Datetime& operator+=(const Datetime &datetime); 00294 Datetime& operator-=(const Datetime &datetime); 00295 Datetime& operator+=(const Time &time); 00296 Datetime& operator-=(const Time &time); 00297 00298 int operator==(const Datetime&); 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 bool operator!() const; 00305 00306 String strftime(const char *format) const; 00307 }; 00308 00315 class __EXPORT DateNumber : public Number, public Date 00316 { 00317 protected: 00318 void update(void) 00319 {fromJulian(buffer);}; 00320 00321 public: 00322 DateNumber(char *buffer); 00323 virtual ~DateNumber(); 00324 }; 00325 00326 #ifdef CCXX_NAMESPACES 00327 } 00328 #endif 00329 00330 #endif 00331