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-2003 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 to the GNU General Public License, permission is 
00018 // granted for additional uses of the text contained in its release 
00019 // of Common C++.
00020 // 
00021 // The exception is that, if you link the Common C++ library with other
00022 // files to produce an executable, this does not by itself cause the
00023 // resulting executable to be covered by the GNU General Public License.
00024 // Your use of that executable is in no way restricted on account of
00025 // linking the Common C++ library code into it.
00026 // 
00027 // This exception does not however invalidate any other reasons why
00028 // the executable file might be covered by the GNU General Public License.
00029 // 
00030 // This exception applies only to the code released under the 
00031 // name Common C++.  If you copy code from other releases into a copy of
00032 // Common C++, as the General Public License permits, the exception does
00033 // not apply to the code that you add in this way.  To avoid misleading
00034 // anyone as to the status of such modified files, you must delete
00035 // this exception notice from them.
00036 // 
00037 // If you write modifications of your own for Common C++, it is your choice
00038 // whether to permit this exception to apply to your modifications.
00039 // If you do not wish that, delete this exception notice.
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 

Generated on Fri Feb 27 11:37:10 2004 for GNU CommonC++ by doxygen 1.3.5