ucommon
commoncpp/numbers.h
00001 // Copyright (C) 1999-2005 Open Source Telecom Corporation.
00002 // Copyright (C) 2006-2014 David Sugar, Tycho Softworks.
00003 //
00004 // This program is free software; you can redistribute it and/or modify
00005 // it under the terms of the GNU General Public License as published by
00006 // the Free Software Foundation; either version 2 of the License, or
00007 // (at your option) any later version.
00008 //
00009 // This program is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU Lesser General Public License
00015 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
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 
00038 #ifndef COMMONCPP_NUMBERS_H_
00039 #define COMMONCPP_NUMBERS_H_
00040 
00041 #ifndef COMMONCPP_CONFIG_H_
00042 #include <commoncpp/config.h>
00043 #endif
00044 
00045 #ifndef COMMONCPP_STRING_H_
00046 #include <commoncpp/string.h>
00047 #endif
00048 
00049 typedef ucommon::DateTimeString DateTimeString;
00050 typedef ucommon::DateNumber DateNumber;
00051 
00052 namespace ost {
00053 
00054 class __EXPORT Date : public ucommon::Date
00055 {
00056 protected:
00057     inline void toJulian(long year, long month, long day)
00058         {ucommon::Date::set(year, month, day);}
00059 
00060     inline void fromJulian(char *buf) const
00061         {put(buf);}
00062 
00063 public:
00064     inline Date(time_t value) : ucommon::Date(value) {}
00065 
00066     inline Date(struct tm *object) : ucommon::Date(object) {}
00067 
00068     inline Date(const char *ptr, size_t size = 0) : ucommon::Date(ptr, size) {}
00069 
00070     inline Date(int y, unsigned m, unsigned d) : ucommon::Date(y, m, d) {}
00071 
00072     inline Date(const Date& object) : ucommon::Date(object) {}
00073 
00074     inline Date() : ucommon::Date() {}
00075 
00076     inline int getYear(void) const
00077         {return year();}
00078 
00079     inline unsigned getMonth(void) const
00080         {return month();}
00081 
00082     inline unsigned getDay(void) const
00083         {return day();}
00084 
00085     inline unsigned getDayOfWeek(void) const
00086         {return dow();}
00087 
00088     inline long getJulian(void) const
00089         {return julian;}
00090 
00091     inline const char *get(char *buffer) const
00092         {return put(buffer);}
00093 
00094     inline time_t getTime(void) const
00095         {return timeref();}
00096 
00097     inline bool isValid(void) const
00098         {return is_valid();}
00099 };
00100 
00101 class __EXPORT Time : public ucommon::Time
00102 {
00103 protected:
00104     inline void toSeconds(int h, int m = 0, int s = 0)
00105         {set(h, m, s);}
00106 
00107     inline void fromSeconds(char *buf) const
00108         {put(buf);}
00109 
00110 public:
00111     inline Time(time_t value) : ucommon::Time(value) {}
00112 
00113     inline Time(tm_t *object) : ucommon::Time(object) {}
00114 
00115     inline Time(const char *ptr, size_t size) : ucommon::Time(ptr, size) {}
00116 
00117     inline Time(int h, int m, int s) : ucommon::Time(h, m, s) {}
00118 
00119     inline Time() : ucommon::Time() {}
00120 
00121     inline int getHour(void) const
00122         {return hour();}
00123 
00124     inline int getMinute(void) const
00125         {return minute();}
00126 
00127     inline int getSecond(void) const
00128         {return second();}
00129 
00130     inline const char *get(char *buffer) const
00131         {return put(buffer);}
00132 
00133     inline bool isValid(void) const
00134         {return is_valid();}
00135 
00136 };
00137 
00138 class __EXPORT DateTime : public ucommon::DateTime
00139 {
00140 public:
00141     inline DateTime(time_t time) : ucommon::DateTime(time) {}
00142 
00143     inline DateTime(struct tm *dt) : ucommon::DateTime(dt) {}
00144 
00145 
00146     inline DateTime(int year, unsigned month, unsigned day,
00147         int hour = 0, int minute = 0, int second = 0) :
00148             ucommon::DateTime(year, month, day, hour, minute, second) {}
00149 
00150     inline DateTime(const char *ptr, size_t size) :
00151         ucommon::DateTime(ptr, size) {}
00152 
00153     inline DateTime(const DateTime& obj) : ucommon::DateTime(obj) {}
00154 
00155     inline DateTime() : ucommon::DateTime() {}
00156 
00157     inline int getYear(void) const
00158         {return year();}
00159 
00160     inline unsigned getMonth(void) const
00161         {return month();}
00162 
00163     inline unsigned getDay(void) const
00164         {return day();}
00165 
00166     inline unsigned getDayOfWeek(void) const
00167         {return dow();}
00168 
00169     inline long getJulian(void) const
00170         {return julian;}
00171 
00172     inline const char *get(char *buffer) const
00173         {return ucommon::DateTime::put(buffer);}
00174 
00175     inline time_t getTime(void) const
00176         {return ucommon::DateTime::timeref();}
00177 
00178     inline bool isValid(void) const
00179         {return ucommon::DateTime::is_valid();}
00180 
00181     inline int getHour(void) const
00182         {return hour();}
00183 
00184     inline int getMinute(void) const
00185         {return minute();}
00186 
00187     inline int getSecond(void) const
00188         {return second();}
00189 
00190     inline static tm_t *glt(time_t *time = NULL)
00191         {return ucommon::DateTime::local(time);}
00192 };
00193 
00194 } // namespace ost
00195 
00196 #endif
00197