numbers.h

Go to the documentation of this file.
00001 // Copyright (C) 1999-2005 Open Source Telecom Corporation.
00002 //
00003 // This program is free software; you can redistribute it and/or modify
00004 // it under the terms of the GNU General Public License as published by
00005 // the Free Software Foundation; either version 2 of the License, or
00006 // (at your option) any later version.
00007 // 
00008 // This program is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 // GNU General Public License for more details.
00012 // 
00013 // You should have received a copy of the GNU General Public License
00014 // along with this program; if not, write to the Free Software 
00015 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00016 // 
00017 // As a special exception, you may use this file as part of a free software
00018 // library without restriction.  Specifically, if other files instantiate
00019 // templates or use macros or inline functions from this file, or you compile
00020 // this file and link it with other files to produce an executable, this
00021 // file does not by itself cause the resulting executable to be covered by
00022 // the GNU General Public License.  This exception does not however    
00023 // invalidate any other reasons why the executable file might be covered by
00024 // the GNU General Public License.    
00025 //
00026 // This exception applies only to the code released under the name GNU
00027 // Common C++.  If you copy code from other releases into a copy of GNU
00028 // Common C++, as the General Public License permits, the exception does
00029 // not apply to the code that you add in this way.  To avoid misleading
00030 // anyone as to the status of such modified files, you must delete
00031 // this exception notice from them.
00032 //
00033 // If you write modifications of your own for GNU Common C++, it is your choice
00034 // whether to permit this exception to apply to your modifications.
00035 // If you do not wish that, delete this exception notice.
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         virtual ~Date();
00170 
00171         int getYear(void) const;
00172         unsigned getMonth(void) const;
00173         unsigned getDay(void) const;
00174         unsigned getDayOfWeek(void) const;
00175         char *getDate(char *buffer) const;
00176         time_t getDate(void) const;
00177         time_t getDate(tm *buf) const;
00178         long getValue(void) const;
00179         void setDate(const char *str, size_t size = 0);
00180         bool isValid(void) const;
00181 
00182         friend Date operator+(const Date &date, const long val);
00183         friend Date operator-(const Date &date, const long val);
00184         friend Date operator+(const long val, const Date &date);
00185         friend Date operator-(const long val, const Date &date);
00186 
00187         operator long() const
00188                 {return getValue();};
00189 
00190         String operator()() const;
00191         Date& operator++();
00192         Date& operator--();
00193         Date& operator+=(const long val);
00194         Date& operator-=(const long val);
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         int operator>=(const Date &date);
00201         bool operator!() const
00202                 {return !isValid();};
00203 };
00204 
00214 class __EXPORT Time
00215 {
00216 protected:
00217         long seconds;
00218 
00219 protected:
00220         void toSeconds(int hour, int minute, int second);
00221         void fromSeconds(char *buf) const;
00222         virtual void update(void);
00223 
00224 public:
00225         Time(time_t tm);
00226         Time(tm *dt);
00227         Time(char *str, size_t size = 0);
00228         Time(int hour, int minute, int second); 
00229         Time();
00230         virtual ~Time();
00231 
00232         long getValue(void) const;
00233         int getHour(void) const;
00234         int getMinute(void) const;
00235         int getSecond(void) const;
00236         char *getTime(char *buffer) const;
00237         time_t getTime(void) const;
00238         tm *getTime(tm *buf) const;
00239         void setTime(char *str, size_t size = 0);
00240         bool isValid(void) const;
00241 
00242         friend Time operator+(const Time &time1, const Time &time2);
00243         friend Time operator-(const Time &time1, const Time &time2);
00244         friend Time operator+(const Time &time, const int val);
00245         friend Time operator-(const Time &time, const int val);
00246         friend Time operator+(const int val, const Time &time);
00247         friend Time operator-(const int val, const Time &time);
00248 
00249         operator long()
00250                 {return getValue();};
00251 
00252         String operator()() const;
00253         Time& operator++();
00254         Time& operator--();
00255         Time& operator+=(const int val);
00256         Time& operator-=(const int val);
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         int operator>(const Time &time);
00262         int operator>=(const Time &time);
00263         bool operator!() const
00264                 {return !isValid();};
00265 };
00266 
00277 class __EXPORT Datetime : public Date, public Time
00278 {
00279   public:
00280         Datetime(time_t tm);
00281         Datetime(tm *dt);
00282         Datetime(const char *str, size_t size = 0);
00283         Datetime(int year, unsigned month, unsigned day,
00284                  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 

Generated on Thu Nov 9 19:39:09 2006 for GNU CommonC++ by  doxygen 1.4.6