Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages | Examples

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 
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 

Generated on Sat Jul 23 19:28:36 2005 for GNU CommonC++ by  doxygen 1.4.3-20050530