Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | 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_THREAD_H_
00050 #include <cc++/thread.h>
00051 #endif
00052 
00053 #ifndef CCXX_MISSING_H_
00054 #include <cc++/missing.h>
00055 #endif
00056 
00057 #ifndef CCXX_STRCHAR_H_
00058 #include <cc++/strchar.h>
00059 #endif
00060 
00061 #ifndef CCXX_STRING_H_
00062 #include <cc++/string.h>
00063 #endif
00064 
00065 #ifndef CCXX_THREAD_H_
00066 #include <cc++/thread.h>
00067 #endif
00068 
00069 #include <ctime>
00070 
00071 #ifdef  CCXX_NAMESPACES
00072 namespace ost {
00073 #ifdef __BORLANDC__
00074         using std::tm;
00075         using std::time_t;
00076 #endif
00077 #endif
00078 
00087 class __EXPORT Number
00088 {
00089 protected:
00090         char *buffer;
00091         unsigned size;
00092 
00093 public:
00099         Number(char *buffer, unsigned size);
00100 
00101         void setValue(long value);
00102         const char *getBuffer() const
00103                 {return buffer;};
00104 
00105         long getValue() const;
00106 
00107         long operator()()
00108                 {return getValue();};
00109 
00110         operator long()
00111                 {return getValue();};
00112 
00113         operator char*()
00114                 {return buffer;};
00115 
00116         long operator=(const long value);
00117         long operator+=(const long value);
00118         long operator-=(const long value);
00119         long operator--();
00120         long operator++();
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         int operator>(const Number &num);
00126         int operator>=(const Number &num);
00127 
00128         friend long operator+(const Number &num, const long val);
00129         friend long operator+(const long val, const Number &num);
00130         friend long operator-(const Number &num, long val);
00131         friend long operator-(const long val, const Number &num);
00132 };
00133 
00134 class __EXPORT ZNumber : public Number
00135 {
00136 public:
00137         ZNumber(char *buf, unsigned size);
00138         void setValue(long value);
00139         long operator=(long value);
00140 };
00141 
00150 class __EXPORT Date
00151 {
00152 protected:
00153         long julian;
00154 
00155 protected:
00156         void toJulian(long year, long month, long day);
00157         void fromJulian(char *buf) const;
00158 
00163         virtual void update(void)
00164                 {return;};
00165 
00166 public:
00167 
00168         Date(time_t tm);
00169         Date(tm *dt);
00170         Date(char *str, size_t size = 0);
00171         Date(int year, unsigned month, unsigned day);
00172         Date();
00173 
00174         int getYear(void) const;
00175         unsigned getMonth(void) const;
00176         unsigned getDay(void) const;
00177         unsigned getDayOfWeek(void) const;
00178         char *getDate(char *buffer) const;
00179         time_t getDate(void) const;
00180         time_t getDate(tm *buf) const;
00181         long getValue(void) const;
00182         void setDate(const char *str, size_t size = 0);
00183         bool isValid(void) const;
00184 
00185         friend Date operator+(const Date &date, const long val);
00186         friend Date operator-(const Date &date, const long val);
00187         friend Date operator+(const long val, const Date &date);
00188         friend Date operator-(const long val, const Date &date);
00189 
00190         operator long() const
00191                 {return getValue();};
00192 
00193         String operator()() const;
00194         Date& operator++();
00195         Date& operator--();
00196         Date& operator+=(const long val);
00197         Date& operator-=(const long val);
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         int operator>(const Date &date);
00203         int operator>=(const Date &date);
00204         bool operator!() const
00205                 {return !isValid();};
00206 };
00207 
00217 class __EXPORT Time
00218 {
00219 protected:
00220         long seconds;
00221 
00222 protected:
00223         void toSeconds(int hour, int minute, int second);
00224         void fromSeconds(char *buf) const;
00225         virtual void Update(void)
00226                 {return;};
00227 
00228 public:
00229         Time(time_t tm);
00230         Time(tm *dt);
00231         Time(char *str, size_t size = 0);
00232         Time(int hour, int minute, int second); 
00233         Time();
00234 
00235         long getValue(void) const;
00236         int getHour(void) const;
00237         int getMinute(void) const;
00238         int getSecond(void) const;
00239         char *getTime(char *buffer) const;
00240         time_t getTime(void) const;
00241         tm *getTime(tm *buf) const;
00242         void setTime(char *str, size_t size = 0);
00243         bool isValid(void) const;
00244 
00245         friend Time operator+(const Time &time1, const Time &time2);
00246         friend Time operator-(const Time &time1, const Time &time2);
00247         friend Time operator+(const Time &time, const int val);
00248         friend Time operator-(const Time &time, const int val);
00249         friend Time operator+(const int val, const Time &time);
00250         friend Time operator-(const int val, const Time &time);
00251 
00252         operator long()
00253                 {return getValue();};
00254 
00255         String operator()() const;
00256         Time& operator++();
00257         Time& operator--();
00258         Time& operator+=(const int val);
00259         Time& operator-=(const int val);
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         int operator>(const Time &time);
00265         int operator>=(const Time &time);
00266         bool operator!() const
00267                 {return !isValid();};
00268 };
00269 
00280 class __EXPORT Datetime : public Date, public Time
00281 {
00282   public:
00283         Datetime(time_t tm);
00284         Datetime(tm *dt);
00285         Datetime(const char *str, size_t size = 0);
00286         Datetime(int year, unsigned month, unsigned day,
00287                  int hour, int minute, int second);
00288         Datetime();
00289         
00290         char *getDatetime(char *buffer) const;
00291         time_t getDatetime(void) const;
00292         bool isValid(void) const;
00293 
00294         Datetime& operator=(const Datetime datetime);
00295         Datetime& operator+=(const Datetime &datetime);
00296         Datetime& operator-=(const Datetime &datetime);
00297         Datetime& operator+=(const Time &time);
00298         Datetime& operator-=(const Time &time);
00299 
00300         int operator==(const Datetime&);
00301         int operator!=(const Datetime&);
00302         int operator<(const Datetime&);
00303         int operator<=(const Datetime&);
00304         int operator>(const Datetime&);
00305         int operator>=(const Datetime&);
00306         bool operator!() const;
00307 
00308         String strftime(const char *format) const;
00309 };
00310 
00317 class __EXPORT DateNumber : public Number, public Date
00318 {
00319 protected:
00320         void update(void)
00321                 {fromJulian(buffer);};
00322 
00323 public:
00324         DateNumber(char *buffer);
00325 };
00326 
00327 #ifdef  CCXX_NAMESPACES
00328 }
00329 #endif
00330 
00331 #endif
00332 

Generated on Tue Jan 18 14:32:37 2005 for GNU CommonC++ by  doxygen 1.3.9.1