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

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