| API Docs for SAX and DOM |

Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members File Members

# XMLDateTime.hpp

Go to the documentation of this file.

    00001 /*
    00002  * The Apache Software License, Version 1.1
    00003  *
    00004  * Copyright (c) 2001 The Apache Software Foundation.  All rights
    00005  * reserved.
    00006  *
    00007  * Redistribution and use in source and binary forms, with or without
    00008  * modification, are permitted provided that the following conditions
    00009  * are met:
    00010  *
    00011  * 1. Redistributions of source code must retain the above copyright
    00012  *    notice, this list of conditions and the following disclaimer.
    00013  *
    00014  * 2. Redistributions in binary form must reproduce the above copyright
    00015  *    notice, this list of conditions and the following disclaimer in
    00016  *    the documentation and/or other materials provided with the
    00017  *    distribution.
    00018  *
    00019  * 3. The end-user documentation included with the redistribution,
    00020  *    if any, must include the following acknowledgment:
    00021  *       "This product includes software developed by the
    00022  *        Apache Software Foundation (http://www.apache.org/)."
    00023  *    Alternately, this acknowledgment may appear in the software itself,
    00024  *    if and wherever such third-party acknowledgments normally appear.
    00025  *
    00026  * 4. The names "Xerces" and "Apache Software Foundation" must
    00027  *    not be used to endorse or promote products derived from this
    00028  *    software without prior written permission. For written
    00029  *    permission, please contact apache\@apache.org.
    00030  *
    00031  * 5. Products derived from this software may not be called "Apache",
    00032  *    nor may "Apache" appear in their name, without prior written
    00033  *    permission of the Apache Software Foundation.
    00034  *
    00035  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
    00036  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
    00037  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    00038  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
    00039  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    00040  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    00041  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
    00042  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
    00043  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
    00044  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
    00045  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    00046  * SUCH DAMAGE.
    00047  * ====================================================================
    00048  *
    00049  * This software consists of voluntary contributions made by many
    00050  * individuals on behalf of the Apache Software Foundation, and was
    00051  * originally based on software copyright (c) 2001, International
    00052  * Business Machines, Inc., http://www.ibm.com .  For more information
    00053  * on the Apache Software Foundation, please see
    00054  * <http://www.apache.org/>.
    00055  */
    00056
    00057 /*
    00058  * $Id: XMLDateTime.hpp,v 1.8 2003/05/18 14:02:05 knoaman Exp $
    00059  * $Log: XMLDateTime.hpp,v $
    00060  * Revision 1.8  2003/05/18 14:02:05  knoaman
    00061  * Memory manager implementation: pass per instance manager.
    00062  *
    00063  * Revision 1.7  2003/05/15 19:07:46  knoaman
    00064  * Partial implementation of the configurable memory manager.
    00065  *
    00066  * Revision 1.6  2003/05/09 15:13:46  peiyongz
    00067  * Deprecated toString() in XMLNumber family
    00068  *
    00069  * Revision 1.5  2003/03/10 20:55:58  peiyongz
    00070  * Schema Errata E2-40 double/float
    00071  *
    00072  * Revision 1.4  2003/02/02 23:54:43  peiyongz
    00073  * getFormattedString() added to return original and converted value.
    00074  *
    00075  * Revision 1.3  2003/01/30 21:55:22  tng
    00076  * Performance: create getRawData which is similar to toString but return the internal data directly, user is not required to delete the returned memory.
    00077  *
    00078  * Revision 1.2  2002/11/04 15:22:05  tng
    00079  * C++ Namespace Support.
    00080  *
    00081  * Revision 1.1.1.1  2002/02/01 22:22:14  peiyongz
    00082  * sane_include
    00083  *
    00084  * Revision 1.4  2001/11/22 20:23:00  peiyongz
    00085  * _declspec(dllimport) and inline warning C4273
    00086  *
    00087  * Revision 1.3  2001/11/12 20:36:54  peiyongz
    00088  * SchemaDateTimeException defined
    00089  *
    00090  * Revision 1.2  2001/11/09 20:41:45  peiyongz
    00091  * Fix: compilation error on Solaris and AIX.
    00092  *
    00093  * Revision 1.1  2001/11/07 19:16:03  peiyongz
    00094  * DateTime Port
    00095  *
    00096  */
    00097
    00098 #ifndef XML_DATETIME_HPP
    00099 #define XML_DATETIME_HPP
    00100
    00101 #include <xercesc/util/XMLNumber.hpp>
    00102 #include <xercesc/util/PlatformUtils.hpp>
    00103 #include <xercesc/util/XMLString.hpp>
    00104 #include <xercesc/util/XMLUniDefs.hpp>
    00105 #include <xercesc/util/SchemaDateTimeException.hpp>
    00106
    00107 XERCES_CPP_NAMESPACE_BEGIN
    00108
    00109 class  XMLDateTime : public XMLNumber
    00110 {
    00111 public:
    00112
    00113     enum valueIndex
    00114     {
    00115         CentYear   = 0,
    00116         Month      ,
    00117         Day        ,
    00118         Hour       ,
    00119         Minute     ,
    00120         Second     ,
    00121         MiliSecond ,
    00122         utc        ,
    00123         TOTAL_SIZE
    00124     };
    00125
    00126     enum utcType
    00127     {
    00128         UTC_UNKNOWN = 0,
    00129         UTC_STD        ,          // set in parse() or normalize()
    00130         UTC_POS        ,          // set in parse()
    00131         UTC_NEG                   // set in parse()
    00132     };
    00133
    00134     // -----------------------------------------------------------------------
    00135     // ctors and dtor
    00136     // -----------------------------------------------------------------------
    00137
    00138     XMLDateTime(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
    00139     XMLDateTime(const XMLCh* const,
    00140                 MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
    00141     ~XMLDateTime();
    00142
    00143     inline void           setBuffer(const XMLCh* const);
    00144
    00145     // -----------------------------------------------------------------------
    00146     // Copy ctor and Assignment operators
    00147     // -----------------------------------------------------------------------
    00148
    00149     XMLDateTime(const XMLDateTime&);
    00150
    00151     XMLDateTime&          operator=(const XMLDateTime&);
    00152
    00153     // -----------------------------------------------------------------------
    00154     // Implementation of Abstract Interface
    00155     // -----------------------------------------------------------------------
    00156
    00162     virtual XMLCh*        toString() const;
    00163
    00164     virtual XMLCh*        getRawData() const;
    00165
    00166     virtual const XMLCh*  getFormattedString() const;
    00167
    00168     virtual int           getSign() const;
    00169
    00170     // -----------------------------------------------------------------------
    00171     // parsers
    00172     // -----------------------------------------------------------------------
    00173
    00174     void                  parseDateTime();       //DateTime
    00175
    00176     void                  parseDate();           //Date
    00177
    00178     void                  parseTime();           //Time
    00179
    00180     void                  parseDay();            //gDay
    00181
    00182     void                  parseMonth();          //gMonth
    00183
    00184     void                  parseYear();           //gYear
    00185
    00186     void                  parseMonthDay();       //gMonthDay
    00187
    00188     void                  parseYearMonth();      //gYearMonth
    00189
    00190     void                  parseDuration();       //duration
    00191
    00192     // -----------------------------------------------------------------------
    00193     // Comparison
    00194     // -----------------------------------------------------------------------
    00195     static int            compare(const XMLDateTime* const
    00196                                 , const XMLDateTime* const);
    00197
    00198     static int            compare(const XMLDateTime* const
    00199                                 , const XMLDateTime* const
    00200                                 , bool                    );
    00201
    00202     static int            compareOrder(const XMLDateTime* const
    00203                                      , const XMLDateTime* const);
    00204
    00205 private:
    00206
    00207     // -----------------------------------------------------------------------
    00208     // Constant data
    00209     // -----------------------------------------------------------------------
    00210     //
    00211     enum timezoneIndex
    00212     {
    00213         hh = 0,
    00214         mm ,
    00215         TIMEZONE_ARRAYSIZE
    00216     };
    00217
    00218     // -----------------------------------------------------------------------
    00219     // Comparison
    00220     // -----------------------------------------------------------------------
    00221     static int            compareResult(short
    00222                                       , short
    00223                                       , bool);
    00224
    00225     static void           addDuration(XMLDateTime*             pDuration
    00226                                     , const XMLDateTime* const pBaseDate
    00227                                     , int                      index);
    00228
    00229
    00230     static int            compareResult(const XMLDateTime* const
    00231                                       , const XMLDateTime* const
    00232                                       , bool
    00233                                       , int);
    00234
    00235     static inline int     getRetVal(int, int);
    00236
    00237     // -----------------------------------------------------------------------
    00238     // helper
    00239     // -----------------------------------------------------------------------
    00240
    00241     inline  void          reset();
    00242
    00243     inline  void          assertBuffer()               const;
    00244
    00245     inline  void          copy(const XMLDateTime&);
    00246
    00247     // allow multiple parsing
    00248     inline  void          initParser();
    00249
    00250     inline  bool          isNormalized()               const;
    00251
    00252     // -----------------------------------------------------------------------
    00253     // scaners
    00254     // -----------------------------------------------------------------------
    00255
    00256     void                  getDate();
    00257
    00258     void                  getTime();
    00259
    00260     void                  getYearMonth();
    00261
    00262     void                  getTimeZone(const int);
    00263
    00264     void                  parseTimeZone();
    00265
    00266     // -----------------------------------------------------------------------
    00267     // locator and converter
    00268     // -----------------------------------------------------------------------
    00269
    00270     int                   findUTCSign(const int start);
    00271
    00272     int                   indexOf(const int start
    00273                                 , const int end
    00274                                 , const XMLCh ch)     const;
    00275
    00276     int                   parseInt(const int start
    00277                                  , const int end)     const;
    00278
    00279     int                   parseIntYear(const int end) const;
    00280
    00281     // -----------------------------------------------------------------------
    00282     // validator and normalizer
    00283     // -----------------------------------------------------------------------
    00284
    00285     void                  validateDateTime()          const;
    00286
    00287     void                  normalize();
    00288
    00289     // -----------------------------------------------------------------------
    00290     // Unimplemented operator ==
    00291     // -----------------------------------------------------------------------
    00292     bool operator==(const XMLDateTime& toCompare) const;
    00293
    00294
    00295     // -----------------------------------------------------------------------
    00296     //  Private data members
    00297     //
    00298     //     fValue[]
    00299     //          object representation of date time.
    00300     //
    00301     //     fTimeZone[]
    00302     //          temporary storage for normalization
    00303     //
    00304     //     fStart, fEnd
    00305     //          pointers to the portion of fBuffer being parsed
    00306     //
    00307     //     fBuffer
    00308     //          raw data to be parsed, own it.
    00309     //
    00310     // -----------------------------------------------------------------------
    00311
    00312     int          fValue[TOTAL_SIZE];
    00313     int          fTimeZone[TIMEZONE_ARRAYSIZE];
    00314     int          fStart;
    00315     int          fEnd;
    00316     XMLCh*       fBuffer;
    00317     MemoryManager* fMemoryManager;
    00318 };
    00319
    00320 inline void XMLDateTime::setBuffer(const XMLCh* const aString)
    00321 {
    00322     reset();
    00323     fBuffer = XMLString::replicate(aString, fMemoryManager);
    00324     fEnd    = XMLString::stringLen(fBuffer);
    00325 }
    00326
    00327 inline void XMLDateTime::reset()
    00328 {
    00329     for ( int i=0; i < TOTAL_SIZE; i++ )
    00330         fValue[i] = 0;
    00331
    00332     fTimeZone[hh] = fTimeZone[mm] = 0;
    00333     fStart = fEnd = 0;
    00334
    00335     if (fBuffer)
    00336     {
    00337         fMemoryManager->deallocate(fBuffer);//delete[] fBuffer;
    00338         fBuffer = 0;
    00339     }
    00340
    00341 }
    00342
    00343 inline void XMLDateTime::copy(const XMLDateTime& rhs)
    00344 {
    00345     for ( int i = 0; i < TOTAL_SIZE; i++ )
    00346         fValue[i] = rhs.fValue[i];
    00347
    00348     fTimeZone[hh] = rhs.fTimeZone[hh];
    00349     fTimeZone[mm] = rhs.fTimeZone[mm];
    00350     fStart = rhs.fStart;
    00351     fEnd   = rhs.fEnd;
    00352
    00353     if (fBuffer)
    00354     {
    00355         fMemoryManager->deallocate(fBuffer);//delete[] fBuffer;
    00356         fBuffer = 0;
    00357     }
    00358
    00359     if (rhs.fBuffer)
    00360         fBuffer = XMLString::replicate(rhs.fBuffer, fMemoryManager);
    00361 }
    00362
    00363 inline void XMLDateTime::assertBuffer() const
    00364 {
    00365     if ( ( !fBuffer )            ||
    00366          ( fBuffer[0] == chNull ) )
    00367     {
    00368         ThrowXML(SchemaDateTimeException
    00369                , XMLExcepts::DateTime_Assert_Buffer_Fail);
    00370     }
    00371
    00372 }
    00373
    00374 inline void XMLDateTime::initParser()
    00375 {
    00376     assertBuffer();
    00377     fStart = 0;   // to ensure scan from the very first beginning
    00378                   // in case the pointer is updated accidentally by someone else.
    00379 }
    00380
    00381 inline bool XMLDateTime::isNormalized() const
    00382 {
    00383     return ( fValue[utc] == UTC_STD ? true : false );
    00384 }
    00385
    00386 inline int XMLDateTime::getRetVal(int c1, int c2)
    00387 {
    00388     if ((c1 == LESS_THAN    && c2 == GREATER_THAN) ||
    00389         (c1 == GREATER_THAN && c2 == LESS_THAN)      )
    00390     {
    00391         return INDETERMINATE;
    00392     }
    00393
    00394     return ( c1 != INDETERMINATE ) ? c1 : c2;
    00395 }
    00396
    00397 XERCES_CPP_NAMESPACE_END
    00398
    00399 #endif

Copyright © 2000 The Apache Software Foundation. All Rights Reserved.