Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:14:52

0001 /*
0002  * Licensed to the Apache Software Foundation (ASF) under one or more
0003  * contributor license agreements.  See the NOTICE file distributed with
0004  * this work for additional information regarding copyright ownership.
0005  * The ASF licenses this file to You under the Apache License, Version 2.0
0006  * (the "License"); you may not use this file except in compliance with
0007  * the License.  You may obtain a copy of the License at
0008  *
0009  *      http://www.apache.org/licenses/LICENSE-2.0
0010  *
0011  * Unless required by applicable law or agreed to in writing, software
0012  * distributed under the License is distributed on an "AS IS" BASIS,
0013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014  * See the License for the specific language governing permissions and
0015  * limitations under the License.
0016  */
0017 
0018 /*
0019  * $Id$
0020  */
0021 
0022 #if !defined(XERCESC_INCLUDE_GUARD_XSVALUE_HPP)
0023 #define XERCESC_INCLUDE_GUARD_XSVALUE_HPP
0024 
0025 #include <xercesc/util/PlatformUtils.hpp>
0026 #include <xercesc/util/ValueHashTableOf.hpp>
0027 
0028 XERCES_CPP_NAMESPACE_BEGIN
0029 
0030 class RegularExpression;
0031 
0032 class XMLPARSER_EXPORT XSValue : public XMemory
0033 {
0034 public:
0035 
0036     enum DataType {
0037               dt_string               = 0,
0038               dt_boolean              = 1,
0039               dt_decimal              = 2,
0040               dt_float                = 3,
0041               dt_double               = 4,
0042               dt_duration             = 5,
0043               dt_dateTime             = 6,
0044               dt_time                 = 7,
0045               dt_date                 = 8,
0046               dt_gYearMonth           = 9,
0047               dt_gYear                = 10,
0048               dt_gMonthDay            = 11,
0049               dt_gDay                 = 12,
0050               dt_gMonth               = 13,
0051               dt_hexBinary            = 14,
0052               dt_base64Binary         = 15,
0053               dt_anyURI               = 16,
0054               dt_QName                = 17,
0055               dt_NOTATION             = 18,
0056               dt_normalizedString     = 19,
0057               dt_token                = 20,
0058               dt_language             = 21,
0059               dt_NMTOKEN              = 22,
0060               dt_NMTOKENS             = 23,
0061               dt_Name                 = 24,
0062               dt_NCName               = 25,
0063               dt_ID                   = 26,
0064               dt_IDREF                = 27,
0065               dt_IDREFS               = 28,
0066               dt_ENTITY               = 29,
0067               dt_ENTITIES             = 30,
0068               dt_integer              = 31,
0069               dt_nonPositiveInteger   = 32,
0070               dt_negativeInteger      = 33,
0071               dt_long                 = 34,
0072               dt_int                  = 35,
0073               dt_short                = 36,
0074               dt_byte                 = 37,
0075               dt_nonNegativeInteger   = 38,
0076               dt_unsignedLong         = 39,
0077               dt_unsignedInt          = 40,
0078               dt_unsignedShort        = 41,
0079               dt_unsignedByte         = 42,
0080               dt_positiveInteger      = 43,
0081               dt_MAXCOUNT             = 44
0082     };
0083 
0084     enum XMLVersion {
0085             ver_10,
0086             ver_11
0087     };
0088 
0089     enum Status {
0090             st_Init,
0091             st_NoContent,
0092             st_NoCanRep,
0093             st_NoActVal,
0094             st_NotSupported,
0095             st_CantCreateRegEx,
0096             st_FOCA0002,        //invalid lexical value
0097             st_FOCA0001,        //input value too large/too small for decimal
0098             st_FOCA0003,        //input value too large for integer
0099             st_FODT0003,        //invalid timezone value
0100             st_UnknownType
0101     };
0102 
0103     enum DataGroup {
0104             dg_numerics,
0105             dg_datetimes,
0106             dg_strings
0107     };
0108 
0109     enum DoubleFloatType
0110     {
0111         DoubleFloatType_NegINF,
0112         DoubleFloatType_PosINF,
0113         DoubleFloatType_NaN,
0114         DoubleFloatType_Zero,
0115         DoubleFloatType_Normal
0116     };
0117 
0118     //  Constructors and Destructor
0119     // -----------------------------------------------------------------------
0120     /** @name Destructor */
0121     //@{
0122     ~XSValue();
0123     //@}
0124 
0125     //---------------------------------
0126     /** @name Externalization methods */
0127     //@{
0128 
0129     /**
0130       * Validate a given string of the data type specified
0131       *
0132       * @param  content    data to be validated
0133       * @param  datatype   schema datatype
0134       * @param  status     validation status which is set upon validation fails
0135       * @param  version    xml version
0136       * @param  manager    memory manager provided
0137       */
0138     static
0139     bool     validate
0140              (
0141                 const XMLCh*          const content
0142               ,       DataType              datatype
0143               ,       Status&               status
0144               ,       XMLVersion            version    = ver_10
0145               ,       MemoryManager*  const manager    = XMLPlatformUtils::fgMemoryManager
0146              );
0147 
0148     /**
0149       * Get the canonical representation for a given string of the
0150       * data type specified
0151       *
0152       * @param  content    raw data
0153       * @param  datatype   schema datatype
0154       * @param  status     validation status which is set upon validation fails
0155       * @param  version    xml version
0156       * @param  toValidate to validate the content before generate canonical representation
0157       * @param  manager    memory manager provided
0158       */
0159     static
0160     XMLCh*   getCanonicalRepresentation
0161              (
0162                 const XMLCh*          const content
0163               ,       DataType              datatype
0164               ,       Status&               status
0165               ,       XMLVersion            version    = ver_10
0166               ,       bool                  toValidate = true
0167               ,       MemoryManager*  const manager    = XMLPlatformUtils::fgMemoryManager
0168              );
0169 
0170     /**
0171       * Get the actual value, in the form of XSValue, for a given string of the
0172       * data type specified
0173       *
0174       * Client application is responsible for the deletion of the XSValue returned.
0175       *
0176       * @param  content    raw data
0177       * @param  datatype   schema datatype
0178       * @param  status     validation status which is set upon validation fails
0179       * @param  version    xml version
0180       * @param  toValidate to validate the content before generate actual value
0181       * @param  manager    memory manager provided
0182       */
0183     static
0184     XSValue* getActualValue
0185              (
0186                 const XMLCh*          const content
0187               ,       DataType              datatype
0188               ,       Status&               status
0189               ,       XMLVersion            version    = ver_10
0190               ,       bool                  toValidate = true
0191               ,       MemoryManager*  const manager    = XMLPlatformUtils::fgMemoryManager
0192              );
0193 
0194     static
0195     DataType  getDataType  (const XMLCh* const dtString);
0196 
0197     //@}
0198 
0199     //----------------------------------
0200     /** public data */
0201 
0202     struct XSValue_Data {
0203 
0204         DataType f_datatype;
0205 
0206         union {
0207                          bool      f_bool;
0208                          char      f_char;
0209                 unsigned char      f_uchar;
0210                          short     f_short;
0211                 unsigned short     f_ushort;
0212                          int       f_int;
0213                 unsigned int       f_uint;
0214                          long      f_long;
0215                 unsigned long      f_ulong;
0216                          float     f_float;
0217                          double    f_double;
0218                          XMLCh*    f_strVal;
0219                          XMLByte*  f_byteVal;
0220 
0221                 struct decimal {
0222                                 double           f_dvalue;
0223                 } f_decimal;
0224 
0225                 struct datetime {
0226                                 int       f_year;
0227                                 int       f_month;
0228                                 int       f_day;
0229                                 int       f_hour;
0230                                 int       f_min;
0231                                 int       f_second;
0232                                 double    f_milisec;
0233 
0234                 } f_datetime;
0235 
0236                 struct doubletype {
0237                                 double          f_double;
0238                                 DoubleFloatType f_doubleEnum;
0239                 } f_doubleType;
0240 
0241                 struct floattype {
0242                                 float           f_float;
0243                                 DoubleFloatType f_floatEnum;
0244                 } f_floatType;
0245 
0246 
0247 
0248         } fValue;
0249 
0250     } fData;
0251 
0252 private:
0253 
0254     typedef union
0255     {
0256                 long  f_long;
0257        unsigned long  f_ulong;
0258     } t_value;
0259 
0260     /** @name Constructors */
0261     //@{
0262     /**
0263       * The default constructor
0264       *
0265       */
0266     XSValue(
0267              DataType        const dt
0268            , MemoryManager*  const manager = XMLPlatformUtils::fgMemoryManager
0269            );
0270 
0271     //@};
0272 
0273     // -----------------------------------------------------------------------
0274     //  Unimplemented constructors and operators
0275     // -----------------------------------------------------------------------
0276     XSValue(const XSValue&);
0277     XSValue & operator=(const XSValue &);
0278 
0279     //---------------------------------
0280     /** @name Helpers */
0281 
0282     //@{
0283 
0284     static const XSValue::DataGroup inGroup[];
0285     static const bool numericSign[];
0286 
0287     //@}
0288 
0289     static
0290     bool     validateNumerics
0291              (
0292                 const XMLCh*          const content
0293               ,       DataType              datatype
0294               ,       Status&               status
0295               ,       MemoryManager*  const manager
0296              );
0297 
0298     static
0299     bool     validateDateTimes
0300              (
0301                 const XMLCh*          const content
0302               ,       DataType              datatype
0303               ,       Status&               status
0304               ,       MemoryManager*  const manager
0305              );
0306 
0307     static
0308     bool     validateStrings
0309              (
0310                 const XMLCh*          const content
0311               ,       DataType              datatype
0312               ,       Status&               status
0313               ,       XMLVersion            version
0314               ,       MemoryManager*  const manager
0315              );
0316 
0317     static
0318     XMLCh*   getCanRepNumerics
0319              (
0320                 const XMLCh*          const content
0321               ,       DataType              datatype
0322               ,       Status&               status
0323               ,       bool                  toValidate
0324               ,       MemoryManager*  const manager
0325              );
0326 
0327     static
0328     XMLCh*   getCanRepDateTimes
0329              (
0330                 const XMLCh*          const content
0331               ,       DataType              datatype
0332               ,       Status&               status
0333               ,       bool                  toValidate
0334               ,       MemoryManager*  const manager
0335              );
0336 
0337     static
0338     XMLCh*   getCanRepStrings
0339              (
0340                 const XMLCh*          const content
0341               ,       DataType              datatype
0342               ,       Status&               status
0343               ,       XMLVersion            version
0344               ,       bool                  toValidate
0345               ,       MemoryManager*  const manager
0346              );
0347 
0348     static
0349     XSValue*  getActValNumerics
0350              (
0351                 const XMLCh*          const content
0352               ,       DataType              datatype
0353               ,       Status&               status
0354               ,       bool                  toValidate
0355               ,       MemoryManager*  const manager
0356              );
0357 
0358     static
0359     XSValue*  getActValDateTimes
0360              (
0361                 const XMLCh*          const content
0362               ,       DataType              datatype
0363               ,       Status&               status
0364               ,       MemoryManager*  const manager
0365              );
0366 
0367     static
0368     XSValue*  getActValStrings
0369              (
0370                 const XMLCh*          const content
0371               ,       DataType              datatype
0372               ,       Status&               status
0373               ,       XMLVersion            version
0374               ,       bool                  toValidate
0375               ,       MemoryManager*  const manager
0376              );
0377 
0378     static
0379     bool      getActualNumericValue
0380               (
0381                  const XMLCh*         const content
0382                ,       Status&               status
0383                ,       t_value&              retVal
0384                ,       MemoryManager* const  manager
0385                ,       DataType              datatype
0386                );
0387 
0388     static ValueHashTableOf<DataType>*    fDataTypeRegistry;
0389 
0390     // -----------------------------------------------------------------------
0391     //  static helper methods
0392     // -----------------------------------------------------------------------
0393     static void initializeRegistry();
0394     friend class XMLInitializer;
0395 
0396     // -----------------------------------------------------------------------
0397     //  data members
0398     // -----------------------------------------------------------------------
0399     bool                fMemAllocated;
0400     MemoryManager*      fMemoryManager;
0401 
0402 };
0403 
0404 XERCES_CPP_NAMESPACE_END
0405 
0406 #endif