Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound 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_CONFIG_H_
00050 #include <cc++/config.h>
00051 #endif
00052 
00053 #ifndef CCXX_STRCHAR_H_
00054 #include <cc++/strchar.h>
00055 #endif
00056 
00057 #include <ctime>
00058 
00059 #ifdef  CCXX_NAMESPACES
00060 namespace ost {
00061 #ifdef __BORLANDC__
00062         using std::tm;
00063         using std::time_t;
00064 #endif
00065 #endif
00066 
00075 class CCXX_CLASS_EXPORT Number
00076 {
00077 protected:
00078         char *buffer;
00079         unsigned size;
00080 
00081 public:
00087         Number(char *buffer, unsigned size);
00088 
00089         void setValue(long value);
00090         const char *getBuffer()
00091                 {return buffer;};
00092 
00093         long getValue();
00094 
00095         long operator()()
00096                 {return getValue();};
00097 
00098         operator long()
00099                 {return getValue();};
00100 
00101         operator char*()
00102                 {return buffer;};
00103 
00104         long operator=(long value);
00105         long operator+=(long value);
00106         long operator-=(long value);
00107         long operator--();
00108         long operator++();
00109         int operator==(Number &num);
00110         int operator!=(Number &num);
00111         int operator<(Number &num);
00112         int operator<=(Number &num);
00113         int operator>(Number &num);
00114         int operator>=(Number &num);
00115 
00116         friend long operator+(Number &num, long val);
00117         friend long operator+(long val, Number &num);
00118         friend long operator-(Number &num, long val);
00119         friend long operator-(long val, Number &num);
00120 };
00121 
00122 class CCXX_CLASS_EXPORT ZNumber : public Number
00123 {
00124 public:
00125         ZNumber(char *buf, unsigned size);
00126         void setValue(long value);
00127         long operator=(long value);
00128 };
00129 
00138 class CCXX_CLASS_EXPORT Date
00139 {
00140 protected:
00141         long julian;
00142 
00143 protected:
00144         void toJulian(long year, long month, long day);
00145         void fromJulian(char *buf) const;
00146 
00151         virtual void update(void)
00152                 {return;};
00153 
00154 public:
00155 
00156         Date(time_t tm);
00157         Date(tm *dt);
00158         Date(char *str, size_t size = 0);
00159         Date(int year, unsigned month, unsigned day);
00160         Date();
00161 
00162         int getYear(void) const;
00163         unsigned getMonth(void) const;
00164         unsigned getDay(void) const;
00165         unsigned getDayOfWeek(void) const;
00166         char *getDate(char *buffer) const;
00167         time_t getDate(void) const;
00168         time_t getDate(tm *buf) const;
00169         long getValue(void) const;
00170         void setDate(const char *str, size_t size = 0);
00171         bool isValid(void) const;
00172 
00173         friend Date operator+(Date &date, long val);
00174         friend Date operator-(Date &date, long val);
00175         friend Date operator+(long val, Date &date);
00176         friend Date operator-(long val, Date &date);
00177 
00178         operator long() const
00179                 {return getValue();};
00180 
00181         std::string operator()() const;
00182         Date& operator++();
00183         Date& operator--();
00184         Date& operator+=(long val);
00185         Date& operator-=(long val);
00186         int operator==(Date &date);
00187         int operator!=(Date &date);
00188         int operator<(Date &date);
00189         int operator<=(Date &date);
00190         int operator>(Date &date);
00191         int operator>=(Date &date);
00192         bool operator!() const
00193                 {return !isValid();};
00194 };
00195 
00205 class CCXX_CLASS_EXPORT Time
00206 {
00207 protected:
00208         long seconds;
00209 
00210 protected:
00211         void toSeconds(int hour, int minute, int second);
00212         void fromSeconds(char *buf) const;
00213         virtual void Update(void)
00214                 {return;};
00215 
00216 public:
00217         Time(time_t tm);
00218         Time(tm *dt);
00219         Time(char *str, size_t size = 0);
00220         Time(int hour, int minute, int second); 
00221         Time();
00222 
00223         long getValue(void) const;
00224         int getHour(void) const;
00225         int getMinute(void) const;
00226         int getSecond(void) const;
00227         char *getTime(char *buffer) const;
00228         time_t getTime(void) const;
00229         tm *getTime(tm *buf) const;
00230         void setTime(char *str, size_t size = 0);
00231         bool isValid(void) const;
00232 
00233         friend Time operator+(Time &time1, Time &time2);
00234         friend Time operator-(Time &time1, Time &time2);
00235         friend Time operator+(Time &time, int val);
00236         friend Time operator-(Time &time, int val);
00237         friend Time operator+(int val, Time &time);
00238         friend Time operator-(int val, Time &time);
00239 
00240         operator long()
00241                 {return getValue();};
00242 
00243         std::string operator()() const;
00244         Time& operator++();
00245         Time& operator--();
00246         Time& operator+=(int val);
00247         Time& operator-=(int val);
00248         int operator==(Time &time);
00249         int operator!=(Time &time);
00250         int operator<(Time &time);
00251         int operator<=(Time &time);
00252         int operator>(Time &time);
00253         int operator>=(Time &time);
00254         bool operator!()
00255                 {return !isValid();};
00256 };
00257 
00268 class CCXX_CLASS_EXPORT Datetime : public Date, public Time
00269 {
00270   public:
00271         Datetime(time_t tm);
00272         Datetime(tm *dt);
00273         Datetime(char *str, size_t size = 0);
00274         Datetime(int year, unsigned month, unsigned day,
00275                  int hour, int minute, int second);
00276         Datetime();
00277         
00278         char *getDatetime(char *buffer) const;
00279         time_t getDatetime(void) const;
00280         bool isValid(void) const;
00281 
00282         Datetime& operator=(Datetime datetime);
00283         Datetime& operator+=(Datetime &datetime);
00284         Datetime& operator-=(Datetime &datetime);
00285         Datetime& operator+=(Time &time);
00286         Datetime& operator-=(Time &time);
00287 
00288         int operator==(Datetime&);
00289         int operator!=(Datetime&);
00290         int operator<(Datetime&);
00291         int operator<=(Datetime&);
00292         int operator>(Datetime&);
00293         int operator>=(Datetime&);
00294         bool operator!();
00295 
00296         std::string strftime(const char *format) const;
00297 };
00298 
00305 class CCXX_CLASS_EXPORT DateNumber : public Number, public Date
00306 {
00307 protected:
00308         void update(void)
00309                 {fromJulian(buffer);};
00310 
00311 public:
00312         DateNumber(char *buffer);
00313 };
00314 
00315 #ifdef  CCXX_NAMESPACES
00316 };
00317 #endif
00318 
00319 #endif
00320 

Generated on Thu Sep 25 13:14:31 2003 for GNU CommonC++ by doxygen 1.3.3