Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xerces" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache\@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation, and was
* originally based on software copyright (c) 2001, International
* Business Machines, Inc., http://www.ibm.com . For more information
* on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
/*
* $Id$
* $Log$
* Revision 1.7 2003/05/15 19:07:46 knoaman
* Partial implementation of the configurable memory manager.
*
* Revision 1.6 2003/05/09 15:13:46 peiyongz
* Deprecated toString() in XMLNumber family
*
* Revision 1.5 2003/03/10 20:55:58 peiyongz
* Schema Errata E2-40 double/float
*
* Revision 1.4 2003/02/02 23:54:43 peiyongz
* getFormattedString() added to return original and converted value.
*
* Revision 1.3 2003/01/30 21:55:22 tng
* Performance: create getRawData which is similar to toString but return the internal data directly, user is not required to delete the returned memory.
*
* Revision 1.2 2002/11/04 15:22:05 tng
* C++ Namespace Support.
*
* Revision 1.1.1.1 2002/02/01 22:22:14 peiyongz
* sane_include
*
* Revision 1.4 2001/11/22 20:23:00 peiyongz
* _declspec(dllimport) and inline warning C4273
*
* Revision 1.3 2001/11/12 20:36:54 peiyongz
* SchemaDateTimeException defined
*
* Revision 1.2 2001/11/09 20:41:45 peiyongz
* Fix: compilation error on Solaris and AIX.
*
* Revision 1.1 2001/11/07 19:16:03 peiyongz
* DateTime Port
*
*/
#ifndef XML_DATETIME_HPP
#define XML_DATETIME_HPP
#include <xercesc/util/XMLNumber.hpp>
#include <xercesc/util/PlatformUtils.hpp>
#include <xercesc/util/XMLString.hpp>
#include <xercesc/util/XMLUniDefs.hpp>
#include <xercesc/util/SchemaDateTimeException.hpp>
class XMLUTIL_EXPORT XMLDateTime : public XMLNumber
{
public:
enum valueIndex
{
CentYear = 0,
Month ,
Day ,
Hour ,
Minute ,
Second ,
MiliSecond ,
utc ,
{
UTC_UNKNOWN = 0,
UTC_STD , // set in parse() or normalize()
UTC_POS , // set in parse()
UTC_NEG // set in parse()
};
// -----------------------------------------------------------------------
// ctors and dtor
// -----------------------------------------------------------------------
XMLDateTime();
XMLDateTime(const XMLCh* const);
~XMLDateTime();
inline void setBuffer(const XMLCh* const);
// -----------------------------------------------------------------------
// Copy ctor and Assignment operators
// -----------------------------------------------------------------------
XMLDateTime(const XMLDateTime&);
// -----------------------------------------------------------------------
// Implementation of Abstract Interface
// -----------------------------------------------------------------------
/**
*
* Deprecated: please use getRawData
*
*/
virtual XMLCh* getRawData() const;
virtual const XMLCh* getFormattedString() const;
virtual int getSign() const;
// -----------------------------------------------------------------------
// parsers
// -----------------------------------------------------------------------
void parseDateTime(); //DateTime
void parseDate(); //Date
void parseTime(); //Time
void parseDay(); //gDay
void parseMonth(); //gMonth
void parseYear(); //gYear
void parseMonthDay(); //gMonthDay
void parseYearMonth(); //gYearMonth
void parseDuration(); //duration
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
, const XMLDateTime* const
, bool );
static int compareOrder(const XMLDateTime* const
, const XMLDateTime* const);
private:
// -----------------------------------------------------------------------
// Constant data
// -----------------------------------------------------------------------
//
{
hh = 0,
mm ,
TIMEZONE_ARRAYSIZE
};
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
, bool);
static void addDuration(XMLDateTime* pDuration
, const XMLDateTime* const pBaseDate
, int index);
static int compareResult(const XMLDateTime* const
, const XMLDateTime* const
, bool
, int);
static inline int getRetVal(int, int);
// -----------------------------------------------------------------------
// helper
// -----------------------------------------------------------------------
inline void reset();
inline void assertBuffer() const;
inline void copy(const XMLDateTime&);
// allow multiple parsing
inline void initParser();
inline bool isNormalized() const;
// -----------------------------------------------------------------------
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
// -----------------------------------------------------------------------
void getDate();
void getTime();
void getYearMonth();
void getTimeZone(const int);
void parseTimeZone();
// -----------------------------------------------------------------------
// locator and converter
// -----------------------------------------------------------------------
int findUTCSign(const int start);
int indexOf(const int start
, const int end
, const XMLCh ch) const;
int parseInt(const int start
, const int end) const;
int parseIntYear(const int end) const;
// -----------------------------------------------------------------------
// validator and normalizer
// -----------------------------------------------------------------------
void validateDateTime() const;
void normalize();
// -----------------------------------------------------------------------
// Unimplemented operator ==
// -----------------------------------------------------------------------
bool operator==(const XMLDateTime& toCompare) const;
// -----------------------------------------------------------------------
// Private data members
//
// fValue[]
// object representation of date time.
//
// fTimeZone[]
// temporary storage for normalization
//
// fStart, fEnd
// pointers to the portion of fBuffer being parsed
//
// fBuffer
// raw data to be parsed, own it.
//
// -----------------------------------------------------------------------
int fTimeZone[TIMEZONE_ARRAYSIZE];
int fStart;
int fEnd;
XMLCh* fBuffer;
MemoryManager* fMemoryManager;
};
inline void XMLDateTime::setBuffer(const XMLCh* const aString)
{
reset();
fBuffer = XMLString::replicate(aString, fMemoryManager);
fEnd = XMLString::stringLen(fBuffer);
}
inline void XMLDateTime::reset()
{
fValue[i] = 0;
fTimeZone[hh] = fTimeZone[mm] = 0;
fStart = fEnd = 0;
if (fBuffer)
{
fMemoryManager->deallocate(fBuffer);//delete[] fBuffer;
fBuffer = 0;
}
}
inline void XMLDateTime::copy(const XMLDateTime& rhs)
{
fValue[i] = rhs.fValue[i];
fTimeZone[hh] = rhs.fTimeZone[hh];
fTimeZone[mm] = rhs.fTimeZone[mm];
fStart = rhs.fStart;
fEnd = rhs.fEnd;
if (fBuffer)
{
fMemoryManager->deallocate(fBuffer);//delete[] fBuffer;
fBuffer = XMLString::replicate(rhs.fBuffer, fMemoryManager);
}
inline void XMLDateTime::assertBuffer() const
{
( fBuffer[0] == chNull ) )
{
ThrowXML(SchemaDateTimeException
, XMLExcepts::DateTime_Assert_Buffer_Fail);
}
}
inline void XMLDateTime::initParser()
{
assertBuffer();
fStart = 0; // to ensure scan from the very first beginning
// in case the pointer is updated accidentally by someone else.
}
inline bool XMLDateTime::isNormalized() const
{
return ( fValue[utc] == UTC_STD ? true : false );
}
inline int XMLDateTime::getRetVal(int c1, int c2)
{
if ((c1 == LESS_THAN && c2 == GREATER_THAN) ||
}
return ( c1 != INDETERMINATE ) ? c1 : c2;
}