Xerces-C++: XMLDateTime.hpp Source File

Xerces-C++ 3.1.4

- Main Page
- Related Pages
- Classes
- Files

- File List
- File Members

XMLDateTime.hpp
Go to the documentation of this file.
1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 /*
19 * $Id: XMLDateTime.hpp 932887 2010-04-11 13:04:59Z borisk $
20 */
21
22 #if !defined(XERCESC_INCLUDE_GUARD_XML_DATETIME_HPP)
23 #define XERCESC_INCLUDE_GUARD_XML_DATETIME_HPP
24
25 #include <xercesc/util/XMLNumber.hpp>
26 #include <xercesc/util/PlatformUtils.hpp>
27 #include <xercesc/util/XMLString.hpp>
28 #include <xercesc/util/XMLUniDefs.hpp>
29 #include <xercesc/util/SchemaDateTimeException.hpp>
30 #include <xercesc/util/XMLChar.hpp>
31
32 XERCES_CPP_NAMESPACE_BEGIN
33
34 class XSValue;
35
36 class XMLUTIL_EXPORT XMLDateTime : public XMLNumber
37 {
38 public:
39
40 enum valueIndex
41 {
42 CentYear = 0,
43 Month ,
44 Day ,
45 Hour ,
46 Minute ,
47 Second ,
48 MiliSecond , //not to be used directly
49 utc ,
50 TOTAL_SIZE
51 };
52
53 enum utcType
54 {
55 UTC_UNKNOWN = 0,
56 UTC_STD , // set in parse() or normalize()
57 UTC_POS , // set in parse()
58 UTC_NEG // set in parse()
59 };
60
61 // -----------------------------------------------------------------------
62 // ctors and dtor
63 // -----------------------------------------------------------------------
64
65 XMLDateTime(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
66 XMLDateTime(const XMLCh* const,
67 MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
68 ~XMLDateTime();
69
70 inline void setBuffer(const XMLCh* const);
71
72 // -----------------------------------------------------------------------
73 // Copy ctor and Assignment operators
74 // -----------------------------------------------------------------------
75
76 XMLDateTime(const XMLDateTime&);
77
78 XMLDateTime& operator=(const XMLDateTime&);
79
80 // -----------------------------------------------------------------------
81 // Implementation of Abstract Interface
82 // -----------------------------------------------------------------------
83
84 virtual XMLCh* getRawData() const;
85
86 virtual const XMLCh* getFormattedString() const;
87
88 virtual int getSign() const;
89
90 // -----------------------------------------------------------------------
91 // Canonical Representation
92 // -----------------------------------------------------------------------
93
94 XMLCh* getDateTimeCanonicalRepresentation(MemoryManager* const memMgr) const;
95
96 XMLCh* getTimeCanonicalRepresentation(MemoryManager* const memMgr) const;
97
98 XMLCh* getDateCanonicalRepresentation(MemoryManager* const memMgr) const;
99
100 // -----------------------------------------------------------------------
101 // parsers
102 // -----------------------------------------------------------------------
103
104 void parseDateTime(); //DateTime
105
106 void parseDate(); //Date
107
108 void parseTime(); //Time
109
110 void parseDay(); //gDay
111
112 void parseMonth(); //gMonth
113
114 void parseYear(); //gYear
115
116 void parseMonthDay(); //gMonthDay
117
118 void parseYearMonth(); //gYearMonth
119
120 void parseDuration(); //duration
121
122 // -----------------------------------------------------------------------
123 // Comparison
124 // -----------------------------------------------------------------------
125 static int compare(const XMLDateTime* const
126 , const XMLDateTime* const);
127
128 static int compare(const XMLDateTime* const
129 , const XMLDateTime* const
130 , bool );
131
132 static int compareOrder(const XMLDateTime* const
133 , const XMLDateTime* const);
134
135 /***
136 * Support for Serialization/De-serialization
137 ***/
138 DECL_XSERIALIZABLE(XMLDateTime)
139
140 private:
141
142 // -----------------------------------------------------------------------
143 // Constant data
144 // -----------------------------------------------------------------------
145 //
146
147 enum timezoneIndex
148 {
149 hh = 0,
150 mm ,
151 TIMEZONE_ARRAYSIZE
152 };
153
154 // -----------------------------------------------------------------------
155 // Comparison
156 // -----------------------------------------------------------------------
157 static int compareResult(int
158 , int
159 , bool);
160
161 static void addDuration(XMLDateTime* pDuration
162 , const XMLDateTime* const pBaseDate
163 , int index);
164
165
166 static int compareResult(const XMLDateTime* const
167 , const XMLDateTime* const
168 , bool
169 , int);
170
171 static inline int getRetVal(int, int);
172
173 // -----------------------------------------------------------------------
174 // helper
175 // -----------------------------------------------------------------------
176
177 inline void reset();
178
179 inline void assertBuffer() const;
180
181 inline void copy(const XMLDateTime&);
182
183 // allow multiple parsing
184 inline bool initParser();
185
186 inline bool isNormalized() const;
187
188 // -----------------------------------------------------------------------
189 // scaners
190 // -----------------------------------------------------------------------
191
192 void getDate();
193
194 void getTime();
195
196 void getYearMonth();
197
198 void getTimeZone(const XMLSize_t);
199
200 void parseTimeZone();
201
202 // -----------------------------------------------------------------------
203 // locator and converter
204 // -----------------------------------------------------------------------
205
206 int findUTCSign(const XMLSize_t start);
207
208 int indexOf(const XMLSize_t start
209 , const XMLSize_t end
210 , const XMLCh ch) const;
211
212 int parseInt(const XMLSize_t start
213 , const XMLSize_t end) const;
214
215 int parseIntYear(const XMLSize_t end) const;
216
217 double parseMiliSecond(const XMLSize_t start
218 , const XMLSize_t end) const;
219
220 // -----------------------------------------------------------------------
221 // validator and normalizer
222 // -----------------------------------------------------------------------
223
224 void validateDateTime() const;
225
226 void normalize();
227
228 void fillString(XMLCh*& ptr, int value, XMLSize_t expLen) const;
229
230 int fillYearString(XMLCh*& ptr, int value) const;
231
232 void searchMiliSeconds(XMLCh*& miliStartPtr, XMLCh*& miliEndPtr) const;
233
234 // -----------------------------------------------------------------------
235 // Unimplemented operator ==
236 // -----------------------------------------------------------------------
237 bool operator==(const XMLDateTime& toCompare) const;
238
239
240 // -----------------------------------------------------------------------
241 // Private data members
242 //
243 // fValue[]
244 // object representation of date time.
245 //
246 // fTimeZone[]
247 // temporary storage for normalization
248 //
249 // fStart, fEnd
250 // pointers to the portion of fBuffer being parsed
251 //
252 // fBuffer
253 // raw data to be parsed, own it.
254 //
255 // -----------------------------------------------------------------------
256
257 int fValue[TOTAL_SIZE];
258 int fTimeZone[TIMEZONE_ARRAYSIZE];
259 XMLSize_t fStart;
260 XMLSize_t fEnd;
261 XMLSize_t fBufferMaxLen;
262
263 double fMilliSecond;
264 bool fHasTime;
265
266 XMLCh* fBuffer;
267 MemoryManager* fMemoryManager;
268
269 friend class XSValue;
270 };
271
272 inline void XMLDateTime::setBuffer(const XMLCh* const aString)
273 {
274 reset();
275
276 fEnd = XMLString::stringLen(aString);
277
278 for (; fEnd > 0; fEnd--)
279 {
280 if (!XMLChar1_0::isWhitespace(aString[fEnd - 1]))
281 break;
282 }
283
284 if (fEnd > 0) {
285
286 if (fEnd > fBufferMaxLen)
287 {
288 fMemoryManager->deallocate(fBuffer);
289 fBufferMaxLen = fEnd + 8;
290 fBuffer = (XMLCh*) fMemoryManager->allocate((fBufferMaxLen+1) * sizeof(XMLCh));
291 }
292
293 memcpy(fBuffer, aString, (fEnd) * sizeof(XMLCh));
294 fBuffer[fEnd] = '\0';
295 }
296 }
297
298 inline void XMLDateTime::reset()
299 {
300 for ( int i=0; i < TOTAL_SIZE; i++ )
301 fValue[i] = 0;
302
303 fMilliSecond = 0;
304 fHasTime = false;
305 fTimeZone[hh] = fTimeZone[mm] = 0;
306 fStart = fEnd = 0;
307
308 if (fBuffer)
309 *fBuffer = 0;
310 }
311
312 inline void XMLDateTime::copy(const XMLDateTime& rhs)
313 {
314 for ( int i = 0; i < TOTAL_SIZE; i++ )
315 fValue[i] = rhs.fValue[i];
316
317 fMilliSecond = rhs.fMilliSecond;
318 fHasTime = rhs.fHasTime;
319 fTimeZone[hh] = rhs.fTimeZone[hh];
320 fTimeZone[mm] = rhs.fTimeZone[mm];
321 fStart = rhs.fStart;
322 fEnd = rhs.fEnd;
323
324 if (fEnd > 0)
325 {
326 if (fEnd > fBufferMaxLen)
327 {
328 fMemoryManager->deallocate(fBuffer);//delete[] fBuffer;
329 fBufferMaxLen = rhs.fBufferMaxLen;
330 fBuffer = (XMLCh*) fMemoryManager->allocate((fBufferMaxLen+1) * sizeof(XMLCh));
331 }
332
333 memcpy(fBuffer, rhs.fBuffer, (fEnd+1) * sizeof(XMLCh));
334 }
335 }
336
337 inline bool XMLDateTime::initParser()
338 {
339 if (!fBuffer || fBuffer[0] == chNull)
340 return false;
341
342 fStart = 0; // to ensure scan from the very first beginning
343 // in case the pointer is updated accidentally by
344 // someone else.
345 return true;
346 }
347
348 inline bool XMLDateTime::isNormalized() const
349 {
350 return ( fValue[utc] == UTC_STD ? true : false );
351 }
352
353 inline int XMLDateTime::getRetVal(int c1, int c2)
354 {
355 if ((c1 == LESS_THAN && c2 == GREATER_THAN) ||
356 (c1 == GREATER_THAN && c2 == LESS_THAN) )
357 {
358 return INDETERMINATE;
359 }
360
361 return ( c1 != INDETERMINATE ) ? c1 : c2;
362 }
363
364 XERCES_CPP_NAMESPACE_END
365
366 #endif
XMLDateTime::MiliSecond
Definition: XMLDateTime.hpp:48
MemoryManager::deallocate
virtual void deallocate(void *p)=0
This method deallocates memory.
XMLPlatformUtils::fgMemoryManager
static MemoryManager * fgMemoryManager
The configurable memory manager.
Definition: PlatformUtils.hpp:121
XMLNumber.hpp
XMLNumber::LESS_THAN
Definition: XMLNumber.hpp:36
XMLNumber::GREATER_THAN
Definition: XMLNumber.hpp:38
XMLDateTime::setBuffer
void setBuffer(const XMLCh *const)
Definition: XMLDateTime.hpp:272
XMLDateTime::TOTAL_SIZE
Definition: XMLDateTime.hpp:50
XSValue
Definition: XSValue.hpp:32
SchemaDateTimeException.hpp
XMLDateTime::Month
Definition: XMLDateTime.hpp:43
XMLNumber::INDETERMINATE
Definition: XMLNumber.hpp:39
XMLDateTime::UTC_POS
Definition: XMLDateTime.hpp:57
PlatformUtils.hpp
MemoryManager
Configurable memory manager.
Definition: MemoryManager.hpp:39
XMLChar1_0::isWhitespace
static bool isWhitespace(const XMLCh toCheck)
Definition: XMLChar.hpp:223
XMLNumber::getRawData
virtual XMLCh * getRawData() const =0
Return string representation of the decimal value.
XMLString::stringLen
static XMLSize_t stringLen(const char *const src)
Get the length of the string.
XMLDateTime
Definition: XMLDateTime.hpp:36
XMLSize_t
SIZE_T XMLSize_t
Definition: Xerces_autoconf_config.borland.hpp:86
XMLUniDefs.hpp
XERCES_CPP_NAMESPACE_BEGIN
#define XERCES_CPP_NAMESPACE_BEGIN
Definition: XercesDefs.hpp:112
XMLCh
wchar_t XMLCh
Definition: Xerces_autoconf_config.borland.hpp:92
XMLDateTime::Second
Definition: XMLDateTime.hpp:47
XMLDateTime::utc
Definition: XMLDateTime.hpp:49
XMLString.hpp
XMLNumber
Definition: XMLNumber.hpp:30
XMLUTIL_EXPORT
#define XMLUTIL_EXPORT
Definition: XercesDefs.hpp:162
XERCES_CPP_NAMESPACE_END
#define XERCES_CPP_NAMESPACE_END
Definition: XercesDefs.hpp:113
MemoryManager::allocate
virtual void * allocate(XMLSize_t size)=0
This method allocates requested memory.
XMLDateTime::UTC_STD
Definition: XMLDateTime.hpp:56
XMLDateTime::utcType
utcType
Definition: XMLDateTime.hpp:53
XMLDateTime::Day
Definition: XMLDateTime.hpp:44
XMLNumber::getFormattedString
virtual const XMLCh * getFormattedString() const =0
Return the original and converted value of the original data.
chNull
XERCES_CPP_NAMESPACE_BEGIN const XMLCh chNull
Definition: XMLUniDefs.hpp:37
XMLNumber::getSign
virtual int getSign() const =0
Returns the sign of this number.
XMLDateTime::Minute
Definition: XMLDateTime.hpp:46
XMLDateTime::Hour
Definition: XMLDateTime.hpp:45
XMLChar.hpp
XMLDateTime::valueIndex
valueIndex
Definition: XMLDateTime.hpp:40