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

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