1 // Copyright (C) 1999-2005 Open Source Telecom Corporation.
2 // Copyright (C) 2006-2010 David Sugar, Tycho Softworks.
3 //
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 //
18 // As a special exception, you may use this file as part of a free software
19 // library without restriction. Specifically, if other files instantiate
20 // templates or use macros or inline functions from this file, or you compile
21 // this file and link it with other files to produce an executable, this
22 // file does not by itself cause the resulting executable to be covered by
23 // the GNU General Public License. This exception does not however
24 // invalidate any other reasons why the executable file might be covered by
25 // the GNU General Public License.
26 //
27 // This exception applies only to the code released under the name GNU
28 // Common C++. If you copy code from other releases into a copy of GNU
29 // Common C++, as the General Public License permits, the exception does
30 // not apply to the code that you add in this way. To avoid misleading
31 // anyone as to the status of such modified files, you must delete
32 // this exception notice from them.
33 //
34 // If you write modifications of your own for GNU Common C++, it is your choice
35 // whether to permit this exception to apply to your modifications.
36 // If you do not wish that, delete this exception notice.
37 //
38
44 #ifndef CCXX_NUMBERS_H_
45 #define CCXX_NUMBERS_H_
46
47 #ifndef CCXX_THREAD_H_
49 #endif
50
51 #ifndef CCXX_MISSING_H_
53 #endif
54
55 #ifndef CCXX_STRCHAR_H_
57 #endif
58
59 #ifndef CCXX_STRING_H_
61 #endif
62
63 #ifndef CCXX_THREAD_H_
65 #endif
66
67 #include <ctime>
68
69 #ifdef CCXX_NAMESPACES
70 namespace ost {
71 #ifdef __BORLANDC__
72 using std::tm;
73 using std::time_t;
74 #endif
75 #endif
76
86 {
87 protected:
90
91 public:
97 Number(
char *buffer,
unsigned size);
98
99 void setValue(long value);
101 {return buffer;};
102
103 long getValue() const;
104
106 {return getValue();};
107
109 {return getValue();};
110
112 {return buffer;};
113
114 long operator=(const long value);
115 long operator+=(const long value);
116 long operator-=(const long value);
117 long operator--();
118 long operator++();
119 int operator==(
const Number &num);
120 int operator!=(
const Number &num);
121 int operator<(
const Number &num);
122 int operator<=(
const Number &num);
123 int operator>(
const Number &num);
124 int operator>=(
const Number &num);
125
126 friend long operator+(
const Number &num,
const long val);
127 friend long operator+(
const long val,
const Number &num);
128 friend long operator-(
const Number &num,
long val);
129 friend long operator-(
const long val,
const Number &num);
130 };
131
133 {
134 public:
135 ZNumber(
char *buf,
unsigned size);
136 void setValue(long value);
137 long operator=(long value);
138 };
139
149 {
150 protected:
152
153 protected:
154 void toJulian(long year, long month, long day);
155 void fromJulian(char *buf) const;
156
161 virtual void update(void);
162
163 public:
164
167 Date(
char *str,
size_t size = 0);
168 Date(
int year,
unsigned month,
unsigned day);
171
172 int getYear(void) const;
173 unsigned getMonth(void) const;
174 unsigned getDay(void) const;
175 unsigned getDayOfWeek(void) const;
176 char *getDate(char *buffer) const;
177 time_t getDate(void) const;
178 time_t getDate(tm *buf) const;
179 long getValue(void) const;
180 void setDate(const char *str, size_t size = 0);
181 bool isValid(void) const;
182
183 friend Date operator+(
const Date &date,
const long val);
184 friend Date operator-(
const Date &date,
const long val);
185 friend Date operator+(
const long val,
const Date &date);
186 friend Date operator-(
const long val,
const Date &date);
187
188 operator long()
const
189 {return getValue();};
190
191 String operator()()
const;
194 Date& operator+=(
const long val);
195 Date& operator-=(
const long val);
196 int operator==(
const Date &date);
197 int operator!=(
const Date &date);
198 int operator<(
const Date &date);
199 int operator<=(
const Date &date);
200 int operator>(
const Date &date);
201 int operator>=(
const Date &date);
203 {return !isValid();};
204 };
205
216 {
217 protected:
219
220 protected:
221 void toSeconds(int hour, int minute, int second);
222 void fromSeconds(char *buf) const;
223 virtual void update(void);
224
225 public:
228 Time(
char *str,
size_t size = 0);
229 Time(
int hour,
int minute,
int second);
232
233 long getValue(void) const;
234 int getHour(void) const;
235 int getMinute(void) const;
236 int getSecond(void) const;
237 char *getTime(char *buffer) const;
238 time_t getTime(void) const;
239 tm *getTime(tm *buf) const;
240 void setTime(char *str, size_t size = 0);
241 bool isValid(void) const;
242
243 friend Time operator+(
const Time &time1,
const Time &time2);
244 friend Time operator-(
const Time &time1,
const Time &time2);
245 friend Time operator+(
const Time &time,
const int val);
246 friend Time operator-(
const Time &time,
const int val);
247 friend Time operator+(
const int val,
const Time &time);
248 friend Time operator-(
const int val,
const Time &time);
249
251 {return getValue();};
252
253 String operator()()
const;
256 Time& operator+=(
const int val);
257 Time& operator-=(
const int val);
258 int operator==(
const Time &time);
259 int operator!=(
const Time &time);
260 int operator<(
const Time &time);
261 int operator<=(
const Time &time);
262 int operator>(
const Time &time);
263 int operator>=(
const Time &time);
265 {return !isValid();};
266 };
267
279 {
280 public:
283 Datetime(
const char *str,
size_t size = 0);
284 Datetime(
int year,
unsigned month,
unsigned day,
int hour,
int minute,
int second);
287
288 char *getDatetime(char *buffer) const;
289 time_t getDatetime(void) const;
290 bool isValid(void) const;
291
297
304 bool operator!() const;
305
306 String strftime(
const char *format)
const;
307 };
308
316 {
317 protected:
319 {fromJulian(buffer);};
320
321 public:
324 };
325
326 #ifdef CCXX_NAMESPACES
327 }
328 #endif
329
330 #endif
331
Common C++ generic string class.
The Time class uses a integer representation of the current time.
The Datetime class uses a julian date representation of the current year, month, and day and a intege...
substitute functions which may be missing in target platform libc.
const char * getBuffer() const
This is a generic and portable string class.
A number class that manipulates a string buffer that is also a date.
Synchronization and threading services.
Common and portable character string related functions.
The Date class uses a julian date representation of the current year, month, and day.
A number manipulation class.
void update(void)
A method to use to "post" any changed values when shadowing a mixed object class. ...