http://xml.apache.org/http://www.apache.org/http://www.w3.org/

Home

Readme
Download
Installation
Build

API Docs
Samples
Schema

FAQs
Programming
Migration

Releases
Bug-Reporting
Feedback

Y2K Compliance
PDF Document

CVS Repository
Mail Archive

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


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