Xerces-C++: XSValue.hpp Source File

Xerces-C++ 3.3.0

XSValue.hpp
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18/*
19 * $Id$
20 */
21
22#if !defined(XERCESC_INCLUDE_GUARD_XSVALUE_HPP)
23#define XERCESC_INCLUDE_GUARD_XSVALUE_HPP
24
25#include <xercesc/util/PlatformUtils.hpp>
26#include <xercesc/util/ValueHashTableOf.hpp>
27
28 XERCES_CPP_NAMESPACE_BEGIN
29
30class RegularExpression;
31
32 class XMLPARSER_EXPORT XSValue : public XMemory
33{
34public:
35
36 enum DataType {
37 dt_string = 0,
38 dt_boolean = 1,
39 dt_decimal = 2,
40 dt_float = 3,
41 dt_double = 4,
42 dt_duration = 5,
43 dt_dateTime = 6,
44 dt_time = 7,
45 dt_date = 8,
46 dt_gYearMonth = 9,
47 dt_gYear = 10,
48 dt_gMonthDay = 11,
49 dt_gDay = 12,
50 dt_gMonth = 13,
51 dt_hexBinary = 14,
52 dt_base64Binary = 15,
53 dt_anyURI = 16,
54 dt_QName = 17,
55 dt_NOTATION = 18,
56 dt_normalizedString = 19,
57 dt_token = 20,
58 dt_language = 21,
59 dt_NMTOKEN = 22,
60 dt_NMTOKENS = 23,
61 dt_Name = 24,
62 dt_NCName = 25,
63 dt_ID = 26,
64 dt_IDREF = 27,
65 dt_IDREFS = 28,
66 dt_ENTITY = 29,
67 dt_ENTITIES = 30,
68 dt_integer = 31,
69 dt_nonPositiveInteger = 32,
70 dt_negativeInteger = 33,
71 dt_long = 34,
72 dt_int = 35,
73 dt_short = 36,
74 dt_byte = 37,
75 dt_nonNegativeInteger = 38,
76 dt_unsignedLong = 39,
77 dt_unsignedInt = 40,
78 dt_unsignedShort = 41,
79 dt_unsignedByte = 42,
80 dt_positiveInteger = 43,
81 dt_MAXCOUNT = 44
82 };
83
84 enum XMLVersion {
85 ver_10,
86 ver_11
87 };
88
89 enum Status {
90 st_Init,
91 st_NoContent,
92 st_NoCanRep,
93 st_NoActVal,
94 st_NotSupported,
95 st_CantCreateRegEx,
96 st_FOCA0002, //invalid lexical value
97 st_FOCA0001, //input value too large/too small for decimal
98 st_FOCA0003, //input value too large for integer
99 st_FODT0003, //invalid timezone value
100 st_UnknownType
101 };
102
103 enum DataGroup {
104 dg_numerics,
105 dg_datetimes,
106 dg_strings
107 };
108
109 enum DoubleFloatType
110 {
111 DoubleFloatType_NegINF,
112 DoubleFloatType_PosINF,
113 DoubleFloatType_NaN,
114 DoubleFloatType_Zero,
115 DoubleFloatType_Normal
116 };
117
118 // Constructors and Destructor
119 // -----------------------------------------------------------------------
122 ~XSValue();
124
125 //---------------------------------
128
138 static
139 bool validate
140 (
141 const XMLCh* const content
142 , DataType datatype
143 , Status& status
144 , XMLVersion version = ver_10
145 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
146 );
147
159 static
160 XMLCh* getCanonicalRepresentation
161 (
162 const XMLCh* const content
163 , DataType datatype
164 , Status& status
165 , XMLVersion version = ver_10
166 , bool toValidate = true
167 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
168 );
169
183 static
184 XSValue* getActualValue
185 (
186 const XMLCh* const content
187 , DataType datatype
188 , Status& status
189 , XMLVersion version = ver_10
190 , bool toValidate = true
191 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
192 );
193
194 static
195 DataType getDataType (const XMLCh* const dtString);
196
198
199 //----------------------------------
202 struct XSValue_Data {
203
204 DataType f_datatype;
205
206 union {
207 bool f_bool;
208 char f_char;
209 unsigned char f_uchar;
210 short f_short;
211 unsigned short f_ushort;
212 int f_int;
213 unsigned int f_uint;
214 long f_long;
215 unsigned long f_ulong;
216 float f_float;
217 double f_double;
218 XMLCh* f_strVal;
219 XMLByte* f_byteVal;
220
221 struct decimal {
222 double f_dvalue;
223 } f_decimal;
224
225 struct datetime {
226 int f_year;
227 int f_month;
228 int f_day;
229 int f_hour;
230 int f_min;
231 int f_second;
232 double f_milisec;
233
234 } f_datetime;
235
236 struct doubletype {
237 double f_double;
238 DoubleFloatType f_doubleEnum;
239 } f_doubleType;
240
241 struct floattype {
242 float f_float;
243 DoubleFloatType f_floatEnum;
244 } f_floatType;
245
246
247
248 } fValue;
249
250 } fData;
251
252private:
253
254 typedef union
255 {
256 long f_long;
257 unsigned long f_ulong;
258 } t_value;
259
266 XSValue(
267 DataType const dt
268 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
269 );
270
272
273 // -----------------------------------------------------------------------
274 // Unimplemented constructors and operators
275 // -----------------------------------------------------------------------
276 XSValue(const XSValue&);
277 XSValue & operator=(const XSValue &);
278
279 //---------------------------------
283
284 static const XSValue::DataGroup inGroup[];
285 static const bool numericSign[];
286
288
289 static
290 bool validateNumerics
291 (
292 const XMLCh* const content
293 , DataType datatype
294 , Status& status
295 , MemoryManager* const manager
296 );
297
298 static
299 bool validateDateTimes
300 (
301 const XMLCh* const content
302 , DataType datatype
303 , Status& status
304 , MemoryManager* const manager
305 );
306
307 static
308 bool validateStrings
309 (
310 const XMLCh* const content
311 , DataType datatype
312 , Status& status
313 , XMLVersion version
314 , MemoryManager* const manager
315 );
316
317 static
318 XMLCh* getCanRepNumerics
319 (
320 const XMLCh* const content
321 , DataType datatype
322 , Status& status
323 , bool toValidate
324 , MemoryManager* const manager
325 );
326
327 static
328 XMLCh* getCanRepDateTimes
329 (
330 const XMLCh* const content
331 , DataType datatype
332 , Status& status
333 , bool toValidate
334 , MemoryManager* const manager
335 );
336
337 static
338 XMLCh* getCanRepStrings
339 (
340 const XMLCh* const content
341 , DataType datatype
342 , Status& status
343 , XMLVersion version
344 , bool toValidate
345 , MemoryManager* const manager
346 );
347
348 static
349 XSValue* getActValNumerics
350 (
351 const XMLCh* const content
352 , DataType datatype
353 , Status& status
354 , bool toValidate
355 , MemoryManager* const manager
356 );
357
358 static
359 XSValue* getActValDateTimes
360 (
361 const XMLCh* const content
362 , DataType datatype
363 , Status& status
364 , MemoryManager* const manager
365 );
366
367 static
368 XSValue* getActValStrings
369 (
370 const XMLCh* const content
371 , DataType datatype
372 , Status& status
373 , XMLVersion version
374 , bool toValidate
375 , MemoryManager* const manager
376 );
377
378 static
379 bool getActualNumericValue
380 (
381 const XMLCh* const content
382 , Status& status
383 , t_value& retVal
384 , MemoryManager* const manager
385 , DataType datatype
386 );
387
388 static ValueHashTableOf<DataType>* fDataTypeRegistry;
389
390 // -----------------------------------------------------------------------
391 // static helper methods
392 // -----------------------------------------------------------------------
393 static void initializeRegistry();
394 friend class XMLInitializer;
395
396 // -----------------------------------------------------------------------
397 // data members
398 // -----------------------------------------------------------------------
399 bool fMemAllocated;
400 MemoryManager* fMemoryManager;
401
402};
403
404 XERCES_CPP_NAMESPACE_END
405
406#endif
PlatformUtils.hpp
XMLPARSER_EXPORT
#define XMLPARSER_EXPORT
Definition XercesDefs.hpp:163
XERCES_CPP_NAMESPACE_BEGIN
#define XERCES_CPP_NAMESPACE_BEGIN
Definition XercesDefs.hpp:112
XMLByte
unsigned char XMLByte
Definition XercesDefs.hpp:65
XERCES_CPP_NAMESPACE_END
#define XERCES_CPP_NAMESPACE_END
Definition XercesDefs.hpp:113
XMLCh
char16_t XMLCh
Definition Xerces_autoconf_config.hpp:120
MemoryManager
Configurable memory manager.
Definition MemoryManager.hpp:40
XMLInitializer
Utilities that must be implemented in a class-specific way.
Definition XMLInitializer.hpp:38
XMLPlatformUtils::fgMemoryManager
static MemoryManager * fgMemoryManager
The configurable memory manager.
Definition PlatformUtils.hpp:121
XMemory
This class makes it possible to override the C++ memory management by adding new/delete operators to ...
Definition XMemory.hpp:41
XSValue
Definition XSValue.hpp:33
XSValue::Status
Status
Definition XSValue.hpp:89
XSValue::st_FOCA0003
@ st_FOCA0003
Definition XSValue.hpp:98
XSValue::st_CantCreateRegEx
@ st_CantCreateRegEx
Definition XSValue.hpp:95
XSValue::st_Init
@ st_Init
Definition XSValue.hpp:90
XSValue::st_NotSupported
@ st_NotSupported
Definition XSValue.hpp:94
XSValue::st_FOCA0002
@ st_FOCA0002
Definition XSValue.hpp:96
XSValue::st_NoContent
@ st_NoContent
Definition XSValue.hpp:91
XSValue::st_FOCA0001
@ st_FOCA0001
Definition XSValue.hpp:97
XSValue::st_NoCanRep
@ st_NoCanRep
Definition XSValue.hpp:92
XSValue::st_FODT0003
@ st_FODT0003
Definition XSValue.hpp:99
XSValue::st_NoActVal
@ st_NoActVal
Definition XSValue.hpp:93
XSValue::~XSValue
~XSValue()
XSValue::getActualValue
static XSValue * getActualValue(const XMLCh *const content, DataType datatype, Status &status, XMLVersion version=ver_10, bool toValidate=true, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Get the actual value, in the form of XSValue, for a given string of the data type specified.
XSValue::validate
static bool validate(const XMLCh *const content, DataType datatype, Status &status, XMLVersion version=ver_10, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Validate a given string of the data type specified.
XSValue::DataGroup
DataGroup
Definition XSValue.hpp:103
XSValue::dg_datetimes
@ dg_datetimes
Definition XSValue.hpp:105
XSValue::dg_numerics
@ dg_numerics
Definition XSValue.hpp:104
XSValue::DoubleFloatType
DoubleFloatType
Definition XSValue.hpp:110
XSValue::DoubleFloatType_Zero
@ DoubleFloatType_Zero
Definition XSValue.hpp:114
XSValue::DoubleFloatType_NegINF
@ DoubleFloatType_NegINF
Definition XSValue.hpp:111
XSValue::DoubleFloatType_NaN
@ DoubleFloatType_NaN
Definition XSValue.hpp:113
XSValue::DoubleFloatType_PosINF
@ DoubleFloatType_PosINF
Definition XSValue.hpp:112
XSValue::XMLVersion
XMLVersion
Definition XSValue.hpp:84
XSValue::ver_10
@ ver_10
Definition XSValue.hpp:85
XSValue::getCanonicalRepresentation
static XMLCh * getCanonicalRepresentation(const XMLCh *const content, DataType datatype, Status &status, XMLVersion version=ver_10, bool toValidate=true, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Get the canonical representation for a given string of the data type specified.
XSValue::DataType
DataType
Definition XSValue.hpp:36
XSValue::getDataType
static DataType getDataType(const XMLCh *const dtString)
XSValue::XSValue_Data
public data
Definition XSValue.hpp:202
XSValue::XSValue_Data::f_floatEnum
DoubleFloatType f_floatEnum
Definition XSValue.hpp:243
XSValue::XSValue_Data::f_long
long f_long
Definition XSValue.hpp:214
XSValue::XSValue_Data::f_ushort
unsigned short f_ushort
Definition XSValue.hpp:211
XSValue::XSValue_Data::f_hour
int f_hour
Definition XSValue.hpp:229
XSValue::XSValue_Data::f_bool
bool f_bool
Definition XSValue.hpp:207
XSValue::XSValue_Data::f_char
char f_char
Definition XSValue.hpp:208
XSValue::XSValue_Data::f_milisec
double f_milisec
Definition XSValue.hpp:232
XSValue::XSValue_Data::f_byteVal
XMLByte * f_byteVal
Definition XSValue.hpp:219
XSValue::XSValue_Data::f_datatype
DataType f_datatype
Definition XSValue.hpp:204
XSValue::XSValue_Data::f_month
int f_month
Definition XSValue.hpp:227
XSValue::XSValue_Data::f_doubleEnum
DoubleFloatType f_doubleEnum
Definition XSValue.hpp:238
XSValue::XSValue_Data::f_year
int f_year
Definition XSValue.hpp:226
XSValue::XSValue_Data::f_second
int f_second
Definition XSValue.hpp:231
XSValue::XSValue_Data::f_ulong
unsigned long f_ulong
Definition XSValue.hpp:215
XSValue::XSValue_Data::f_double
double f_double
Definition XSValue.hpp:217
XSValue::XSValue_Data::f_float
float f_float
Definition XSValue.hpp:216
XSValue::XSValue_Data::f_day
int f_day
Definition XSValue.hpp:228
XSValue::XSValue_Data::f_uint
unsigned int f_uint
Definition XSValue.hpp:213
XSValue::XSValue_Data::f_strVal
XMLCh * f_strVal
Definition XSValue.hpp:218
XSValue::XSValue_Data::f_short
short f_short
Definition XSValue.hpp:210
XSValue::XSValue_Data::f_uchar
unsigned char f_uchar
Definition XSValue.hpp:209
XSValue::XSValue_Data::f_dvalue
double f_dvalue
Definition XSValue.hpp:222
XSValue::XSValue_Data::f_min
int f_min
Definition XSValue.hpp:230
XSValue::XSValue_Data::f_int
int f_int
Definition XSValue.hpp:212