| 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.10 2003/09/23 18:16:07 peiyongz Exp $
    00059  * $Log: XMLDateTime.hpp,v $
    00060  * Revision 1.10  2003/09/23 18:16:07  peiyongz
    00061  * Inplementation for Serialization/Deserialization
    00062  *
    00063  * Revision 1.9  2003/08/14 02:57:27  knoaman
    00064  * Code refactoring to improve performance of validation.
    00065  *
    00066  * Revision 1.8  2003/05/18 14:02:05  knoaman
    00067  * Memory manager implementation: pass per instance manager.
    00068  *
    00069  * Revision 1.7  2003/05/15 19:07:46  knoaman
    00070  * Partial implementation of the configurable memory manager.
    00071  *
    00072  * Revision 1.6  2003/05/09 15:13:46  peiyongz
    00073  * Deprecated toString() in XMLNumber family
    00074  *
    00075  * Revision 1.5  2003/03/10 20:55:58  peiyongz
    00076  * Schema Errata E2-40 double/float
    00077  *
    00078  * Revision 1.4  2003/02/02 23:54:43  peiyongz
    00079  * getFormattedString() added to return original and converted value.
    00080  *
    00081  * Revision 1.3  2003/01/30 21:55:22  tng
    00082  * Performance: create getRawData which is similar to toString but return the internal data directly, user is not required to delete the returned memory.
    00083  *
    00084  * Revision 1.2  2002/11/04 15:22:05  tng
    00085  * C++ Namespace Support.
    00086  *
    00087  * Revision 1.1.1.1  2002/02/01 22:22:14  peiyongz
    00088  * sane_include
    00089  *
    00090  * Revision 1.4  2001/11/22 20:23:00  peiyongz
    00091  * _declspec(dllimport) and inline warning C4273
    00092  *
    00093  * Revision 1.3  2001/11/12 20:36:54  peiyongz
    00094  * SchemaDateTimeException defined
    00095  *
    00096  * Revision 1.2  2001/11/09 20:41:45  peiyongz
    00097  * Fix: compilation error on Solaris and AIX.
    00098  *
    00099  * Revision 1.1  2001/11/07 19:16:03  peiyongz
    00100  * DateTime Port
    00101  *
    00102  */
    00103
    00104 #ifndef XML_DATETIME_HPP
    00105 #define XML_DATETIME_HPP
    00106
    00107 #include <xercesc/util/XMLNumber.hpp>
    00108 #include <xercesc/util/PlatformUtils.hpp>
    00109 #include <xercesc/util/XMLString.hpp>
    00110 #include <xercesc/util/XMLUniDefs.hpp>
    00111 #include <xercesc/util/SchemaDateTimeException.hpp>
    00112
    00113 XERCES_CPP_NAMESPACE_BEGIN
    00114
    00115 class  XMLDateTime : public XMLNumber
    00116 {
    00117 public:
    00118
    00119     enum valueIndex
    00120     {
    00121         CentYear   = 0,
    00122         Month      ,
    00123         Day        ,
    00124         Hour       ,
    00125         Minute     ,
    00126         Second     ,
    00127         MiliSecond ,
    00128         utc        ,
    00129         TOTAL_SIZE
    00130     };
    00131
    00132     enum utcType
    00133     {
    00134         UTC_UNKNOWN = 0,
    00135         UTC_STD        ,          // set in parse() or normalize()
    00136         UTC_POS        ,          // set in parse()
    00137         UTC_NEG                   // set in parse()
    00138     };
    00139
    00140     // -----------------------------------------------------------------------
    00141     // ctors and dtor
    00142     // -----------------------------------------------------------------------
    00143
    00144     XMLDateTime(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
    00145     XMLDateTime(const XMLCh* const,
    00146                 MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
    00147     ~XMLDateTime();
    00148
    00149     inline void           setBuffer(const XMLCh* const);
    00150
    00151     // -----------------------------------------------------------------------
    00152     // Copy ctor and Assignment operators
    00153     // -----------------------------------------------------------------------
    00154
    00155     XMLDateTime(const XMLDateTime&);
    00156
    00157     XMLDateTime&          operator=(const XMLDateTime&);
    00158
    00159     // -----------------------------------------------------------------------
    00160     // Implementation of Abstract Interface
    00161     // -----------------------------------------------------------------------
    00162
    00168     virtual XMLCh*        toString() const;
    00169
    00170     virtual XMLCh*        getRawData() const;
    00171
    00172     virtual const XMLCh*  getFormattedString() const;
    00173
    00174     virtual int           getSign() const;
    00175
    00176     // -----------------------------------------------------------------------
    00177     // parsers
    00178     // -----------------------------------------------------------------------
    00179
    00180     void                  parseDateTime();       //DateTime
    00181
    00182     void                  parseDate();           //Date
    00183
    00184     void                  parseTime();           //Time
    00185
    00186     void                  parseDay();            //gDay
    00187
    00188     void                  parseMonth();          //gMonth
    00189
    00190     void                  parseYear();           //gYear
    00191
    00192     void                  parseMonthDay();       //gMonthDay
    00193
    00194     void                  parseYearMonth();      //gYearMonth
    00195
    00196     void                  parseDuration();       //duration
    00197
    00198     // -----------------------------------------------------------------------
    00199     // Comparison
    00200     // -----------------------------------------------------------------------
    00201     static int            compare(const XMLDateTime* const
    00202                                 , const XMLDateTime* const);
    00203
    00204     static int            compare(const XMLDateTime* const
    00205                                 , const XMLDateTime* const
    00206                                 , bool                    );
    00207
    00208     static int            compareOrder(const XMLDateTime* const
    00209                                      , const XMLDateTime* const);
    00210
    00211     /***
    00212      * Support for Serialization/De-serialization
    00213      ***/
    00214     DECL_XSERIALIZABLE(XMLDateTime)
    00215
    00216 private:
    00217
    00218     // -----------------------------------------------------------------------
    00219     // Constant data
    00220     // -----------------------------------------------------------------------
    00221     //
    00222     enum timezoneIndex
    00223     {
    00224         hh = 0,
    00225         mm ,
    00226         TIMEZONE_ARRAYSIZE
    00227     };
    00228
    00229     // -----------------------------------------------------------------------
    00230     // Comparison
    00231     // -----------------------------------------------------------------------
    00232     static int            compareResult(short
    00233                                       , short
    00234                                       , bool);
    00235
    00236     static void           addDuration(XMLDateTime*             pDuration
    00237                                     , const XMLDateTime* const pBaseDate
    00238                                     , int                      index);
    00239
    00240
    00241     static int            compareResult(const XMLDateTime* const
    00242                                       , const XMLDateTime* const
    00243                                       , bool
    00244                                       , int);
    00245
    00246     static inline int     getRetVal(int, int);
    00247
    00248     // -----------------------------------------------------------------------
    00249     // helper
    00250     // -----------------------------------------------------------------------
    00251
    00252     inline  void          reset();
    00253
    00254     inline  void          assertBuffer()               const;
    00255
    00256     inline  void          copy(const XMLDateTime&);
    00257
    00258     // allow multiple parsing
    00259     inline  void          initParser();
    00260
    00261     inline  bool          isNormalized()               const;
    00262
    00263     // -----------------------------------------------------------------------
    00264     // scaners
    00265     // -----------------------------------------------------------------------
    00266
    00267     void                  getDate();
    00268
    00269     void                  getTime();
    00270
    00271     void                  getYearMonth();
    00272
    00273     void                  getTimeZone(const int);
    00274
    00275     void                  parseTimeZone();
    00276
    00277     // -----------------------------------------------------------------------
    00278     // locator and converter
    00279     // -----------------------------------------------------------------------
    00280
    00281     int                   findUTCSign(const int start);
    00282
    00283     int                   indexOf(const int start
    00284                                 , const int end
    00285                                 , const XMLCh ch)     const;
    00286
    00287     int                   parseInt(const int start
    00288                                  , const int end)     const;
    00289
    00290     int                   parseIntYear(const int end) const;
    00291
    00292     // -----------------------------------------------------------------------
    00293     // validator and normalizer
    00294     // -----------------------------------------------------------------------
    00295
    00296     void                  validateDateTime()          const;
    00297
    00298     void                  normalize();
    00299
    00300     // -----------------------------------------------------------------------
    00301     // Unimplemented operator ==
    00302     // -----------------------------------------------------------------------
    00303     bool operator==(const XMLDateTime& toCompare) const;
    00304
    00305
    00306     // -----------------------------------------------------------------------
    00307     //  Private data members
    00308     //
    00309     //     fValue[]
    00310     //          object representation of date time.
    00311     //
    00312     //     fTimeZone[]
    00313     //          temporary storage for normalization
    00314     //
    00315     //     fStart, fEnd
    00316     //          pointers to the portion of fBuffer being parsed
    00317     //
    00318     //     fBuffer
    00319     //          raw data to be parsed, own it.
    00320     //
    00321     // -----------------------------------------------------------------------
    00322
    00323     int          fValue[TOTAL_SIZE];
    00324     int          fTimeZone[TIMEZONE_ARRAYSIZE];
    00325     int          fStart;
    00326     int          fEnd;
    00327     int          fBufferMaxLen;
    00328     XMLCh*       fBuffer;
    00329     MemoryManager* fMemoryManager;
    00330 };
    00331
    00332 inline void XMLDateTime::setBuffer(const XMLCh* const aString)
    00333 {
    00334     reset();
    00335
    00336     fEnd = XMLString::stringLen(aString);
    00337     if (fEnd > 0) {
    00338
    00339         if (fEnd > fBufferMaxLen)
    00340         {
    00341             fMemoryManager->deallocate(fBuffer);
    00342             fBufferMaxLen = fEnd + 8;
    00343             fBuffer = (XMLCh*) fMemoryManager->allocate((fBufferMaxLen+1) * sizeof(XMLCh));
    00344         }
    00345
    00346         memcpy(fBuffer, aString, (fEnd+1) * sizeof(XMLCh));
    00347     }
    00348 }
    00349
    00350 inline void XMLDateTime::reset()
    00351 {
    00352     for ( int i=0; i < TOTAL_SIZE; i++ )
    00353         fValue[i] = 0;
    00354
    00355     fTimeZone[hh] = fTimeZone[mm] = 0;
    00356     fStart = fEnd = 0;
    00357
    00358     if (fBuffer)
    00359         *fBuffer = 0;
    00360 }
    00361
    00362 inline void XMLDateTime::copy(const XMLDateTime& rhs)
    00363 {
    00364     for ( int i = 0; i < TOTAL_SIZE; i++ )
    00365         fValue[i] = rhs.fValue[i];
    00366
    00367     fTimeZone[hh] = rhs.fTimeZone[hh];
    00368     fTimeZone[mm] = rhs.fTimeZone[mm];
    00369     fStart = rhs.fStart;
    00370     fEnd   = rhs.fEnd;
    00371
    00372     if (fEnd > 0)
    00373     {
    00374         if (fEnd > fBufferMaxLen)
    00375         {
    00376             fMemoryManager->deallocate(fBuffer);//delete[] fBuffer;
    00377             fBufferMaxLen = rhs.fBufferMaxLen;
    00378             fBuffer = (XMLCh*) fMemoryManager->allocate((fBufferMaxLen+1) * sizeof(XMLCh));
    00379         }
    00380
    00381         memcpy(fBuffer, rhs.fBuffer, (fEnd+1) * sizeof(XMLCh));
    00382     }
    00383 }
    00384
    00385 inline void XMLDateTime::assertBuffer() const
    00386 {
    00387     if ( ( !fBuffer )            ||
    00388          ( fBuffer[0] == chNull ) )
    00389     {
    00390         ThrowXML(SchemaDateTimeException
    00391                , XMLExcepts::DateTime_Assert_Buffer_Fail);
    00392     }
    00393
    00394 }
    00395
    00396 inline void XMLDateTime::initParser()
    00397 {
    00398     assertBuffer();
    00399     fStart = 0;   // to ensure scan from the very first beginning
    00400                   // in case the pointer is updated accidentally by someone else.
    00401 }
    00402
    00403 inline bool XMLDateTime::isNormalized() const
    00404 {
    00405     return ( fValue[utc] == UTC_STD ? true : false );
    00406 }
    00407
    00408 inline int XMLDateTime::getRetVal(int c1, int c2)
    00409 {
    00410     if ((c1 == LESS_THAN    && c2 == GREATER_THAN) ||
    00411         (c1 == GREATER_THAN && c2 == LESS_THAN)      )
    00412     {
    00413         return INDETERMINATE;
    00414     }
    00415
    00416     return ( c1 != INDETERMINATE ) ? c1 : c2;
    00417 }
    00418
    00419 XERCES_CPP_NAMESPACE_END
    00420
    00421 #endif

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