Xerces-C++ 3.2.4

XMLAttDef.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_XMLATTDEF_HPP)
23#define XERCESC_INCLUDE_GUARD_XMLATTDEF_HPP
24
25#include <xercesc/util/PlatformUtils.hpp>
26#include <xercesc/util/XMLString.hpp>
27#include <xercesc/util/XMemory.hpp>
28#include <xercesc/internal/XSerializable.hpp>
29
30 XERCES_CPP_NAMESPACE_BEGIN
31
32 class XMLAttr;
33
52 class XMLPARSER_EXPORT XMLAttDef : public XSerializable, public XMemory
53{
54 public:
55 // -----------------------------------------------------------------------
56 // Class specific types
57 //
58 // AttTypes
59 // The list of possible types that an attribute can have, according
60 // to the XML 1.0 spec and schema.
61 //
62 // DefAttTypes
63 // The modifiers that an attribute decl can have, which indicates
64 // whether instances of that attributes are required, implied, etc..
65 //
66 // CreateReasons
67 // This type is used to store how an attribute declaration got into
68 // the elementdecl's attribute pool.
69 //
70 // -----------------------------------------------------------------------
71 enum AttTypes
72 {
73 CData = 0
74 , ID = 1
75 , IDRef = 2
76 , IDRefs = 3
77 , Entity = 4
78 , Entities = 5
79 , NmToken = 6
80 , NmTokens = 7
81 , Notation = 8
82 , Enumeration = 9
83 , Simple = 10
84 , Any_Any = 11
85 , Any_Other = 12
86 , Any_List = 13
87
88 , AttTypes_Count
89 , AttTypes_Min = 0
90 , AttTypes_Max = 13
91 , AttTypes_Unknown = -1
92 };
93
94 enum DefAttTypes
95 {
96 Default = 0
97 , Fixed = 1
98 , Required = 2
99 , Required_And_Fixed = 3
100 , Implied = 4
101 , ProcessContents_Skip = 5
102 , ProcessContents_Lax = 6
103 , ProcessContents_Strict = 7
104 , Prohibited = 8
105
106 , DefAttTypes_Count
107 , DefAttTypes_Min = 0
108 , DefAttTypes_Max = 8
109 , DefAttTypes_Unknown = -1
110 };
111
112 enum CreateReasons
113 {
114 NoReason
115 , JustFaultIn
116 };
117
118 // -----------------------------------------------------------------------
119 // Public static data members
120 // -----------------------------------------------------------------------
121 static const unsigned int fgInvalidAttrId;
122
123
124 // -----------------------------------------------------------------------
125 // Public, static methods
126 // -----------------------------------------------------------------------
127
130
141 static const XMLCh* getAttTypeString(const AttTypes attrType
142 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
143
154 static const XMLCh* getDefAttTypeString(const DefAttTypes attrType
155 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
156
158
159
160 // -----------------------------------------------------------------------
161 // Destructor
162 // -----------------------------------------------------------------------
163
166
170 virtual ~XMLAttDef();
172
173
174 // -----------------------------------------------------------------------
175 // The virtual attribute def interface
176 // -----------------------------------------------------------------------
177
180
189 virtual const XMLCh* getFullName() const = 0;
190
195 virtual void reset() = 0;
196
198
199
200 // -----------------------------------------------------------------------
201 // Getter methods
202 // -----------------------------------------------------------------------
203
206
215 DefAttTypes getDefaultType() const;
216
226 const XMLCh* getEnumeration() const;
227
236 XMLSize_t getId() const;
237
247 AttTypes getType() const;
248
258 const XMLCh* getValue() const;
259
268 CreateReasons getCreateReason() const;
269
277 bool isExternal() const;
278
286 MemoryManager* getMemoryManager() const;
287
289
290
291 // -----------------------------------------------------------------------
292 // Setter methods
293 // -----------------------------------------------------------------------
294
297
306 void setDefaultType(const XMLAttDef::DefAttTypes newValue);
307
316 void setId(const XMLSize_t newId);
317
325 void setType(const XMLAttDef::AttTypes newValue);
326
337 void setValue(const XMLCh* const newValue);
338
349 void setEnumeration(const XMLCh* const newValue);
350
358 void setCreateReason(const CreateReasons newReason);
359
365 void setExternalAttDeclaration(const bool aValue);
366
368
369 /***
370 * Support for Serialization/De-serialization
371 ***/
372 DECL_XSERIALIZABLE(XMLAttDef)
373
374protected :
375 // -----------------------------------------------------------------------
376 // Hidden constructors
377 // -----------------------------------------------------------------------
378 XMLAttDef
379 (
380 const AttTypes type = CData
381 , const DefAttTypes defType= Implied
382 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
383 );
384 XMLAttDef
385 (
386 const XMLCh* const attValue
387 , const AttTypes type
388 , const DefAttTypes defType
389 , const XMLCh* const enumValues = 0
390 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
391 );
392
393
394private :
395 // -----------------------------------------------------------------------
396 // Unimplemented constructors and operators
397 // -----------------------------------------------------------------------
398 XMLAttDef(const XMLAttDef&);
399 XMLAttDef& operator=(const XMLAttDef&);
400
401
402 // -----------------------------------------------------------------------
403 // Private helper methods
404 // -----------------------------------------------------------------------
405 void cleanUp();
406
407
408 // -----------------------------------------------------------------------
409 // Private data members
410 //
411 // fDefaultType
412 // Indicates what, if any, default stuff this attribute has.
413 //
414 // fEnumeration
415 // If its an enumeration, this is the list of values as space
416 // separated values.
417 //
418 // fId
419 // This is the unique id of this attribute, given to it when its put
420 // into the validator's attribute decl pool. It defaults to the
421 // special value XMLAttrDef::fgInvalidAttrId.
422 //
423 // fType
424 // The type of attribute, which is one of the AttTypes values.
425 //
426 // fValue
427 // This is the value of the attribute, which is the default value
428 // given in the attribute declaration.
429 //
430 // fCreateReason
431 // This flag tells us how this attribute got created. Sometimes even
432 // the attribute was not declared for the element, we want to fault
433 // fault it into the pool to avoid lots of redundant errors.
434 //
435 // fExternalAttribute
436 // This flag indicates whether or not the attribute was declared externally.
437 // -----------------------------------------------------------------------
438 DefAttTypes fDefaultType;
439 AttTypes fType;
440 CreateReasons fCreateReason;
441 bool fExternalAttribute;
442 XMLSize_t fId;
443 XMLCh* fValue;
444 XMLCh* fEnumeration;
445 MemoryManager* fMemoryManager;
446};
447
448
449// ---------------------------------------------------------------------------
450// Getter methods
451// ---------------------------------------------------------------------------
452 inline XMLAttDef::DefAttTypes XMLAttDef::getDefaultType() const
453{
454 return fDefaultType;
455}
456
457 inline const XMLCh* XMLAttDef::getEnumeration() const
458{
459 return fEnumeration;
460}
461
462 inline XMLSize_t XMLAttDef::getId() const
463{
464 return fId;
465}
466
467 inline XMLAttDef::AttTypes XMLAttDef::getType() const
468{
469 return fType;
470}
471
472 inline const XMLCh* XMLAttDef::getValue() const
473{
474 return fValue;
475}
476
477 inline XMLAttDef::CreateReasons XMLAttDef::getCreateReason() const
478{
479 return fCreateReason;
480}
481
482 inline bool XMLAttDef::isExternal() const
483{
484 return fExternalAttribute;
485}
486
487 inline MemoryManager* XMLAttDef::getMemoryManager() const
488{
489 return fMemoryManager;
490}
491
492// ---------------------------------------------------------------------------
493// XMLAttDef: Setter methods
494// ---------------------------------------------------------------------------
495 inline void XMLAttDef::setDefaultType(const XMLAttDef::DefAttTypes newValue)
496{
497 fDefaultType = newValue;
498}
499
500 inline void XMLAttDef::setEnumeration(const XMLCh* const newValue)
501{
502 if (fEnumeration)
503 fMemoryManager->deallocate(fEnumeration);
504
505 fEnumeration = XMLString::replicate(newValue, fMemoryManager);
506}
507
508 inline void XMLAttDef::setId(const XMLSize_t newId)
509{
510 fId = newId;
511}
512
513 inline void XMLAttDef::setType(const XMLAttDef::AttTypes newValue)
514{
515 fType = newValue;
516}
517
518 inline void XMLAttDef::setValue(const XMLCh* const newValue)
519{
520 if (fValue)
521 fMemoryManager->deallocate(fValue);
522
523 fValue = XMLString::replicate(newValue, fMemoryManager);
524}
525
526 inline void
527 XMLAttDef::setCreateReason(const XMLAttDef::CreateReasons newReason)
528{
529 fCreateReason = newReason;
530}
531
532 inline void XMLAttDef::setExternalAttDeclaration(const bool aValue)
533{
534 fExternalAttribute = aValue;
535}
536
537 XERCES_CPP_NAMESPACE_END
538
539#endif
PlatformUtils.hpp
XMLString.hpp
XMemory.hpp
XMLPARSER_EXPORT
#define XMLPARSER_EXPORT
Definition: XercesDefs.hpp:163
XERCES_CPP_NAMESPACE_BEGIN
#define XERCES_CPP_NAMESPACE_BEGIN
Definition: XercesDefs.hpp:112
XERCES_CPP_NAMESPACE_END
#define XERCES_CPP_NAMESPACE_END
Definition: XercesDefs.hpp:113
XMLCh
uint16_t XMLCh
Definition: Xerces_autoconf_config.hpp:120
XMLSize_t
size_t XMLSize_t
Definition: Xerces_autoconf_config.hpp:112
MemoryManager
Configurable memory manager.
Definition: MemoryManager.hpp:40
MemoryManager::deallocate
virtual void deallocate(void *p)=0
This method deallocates memory.
XMLAttDef
Represents the core information of an attribute definition.
Definition: XMLAttDef.hpp:53
XMLAttDef::getType
AttTypes getType() const
Get the type of this attribute.
Definition: XMLAttDef.hpp:467
XMLAttDef::setDefaultType
void setDefaultType(const XMLAttDef::DefAttTypes newValue)
Set the default attribute type.
Definition: XMLAttDef.hpp:495
XMLAttDef::getMemoryManager
MemoryManager * getMemoryManager() const
Get the plugged-in memory manager.
Definition: XMLAttDef.hpp:487
XMLAttDef::getFullName
virtual const XMLCh * getFullName() const =0
Get the full name of this attribute type.
XMLAttDef::getEnumeration
const XMLCh * getEnumeration() const
Get the enumeration value (if any) of this attribute type.
Definition: XMLAttDef.hpp:457
XMLAttDef::setType
void setType(const XMLAttDef::AttTypes newValue)
Set the type of this attribute type.
Definition: XMLAttDef.hpp:513
XMLAttDef::XMLAttDef
XMLAttDef(const AttTypes type=CData, const DefAttTypes defType=Implied, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
XMLAttDef::getDefaultType
DefAttTypes getDefaultType() const
Get the default type of this attribute type.
Definition: XMLAttDef.hpp:452
XMLAttDef::getValue
const XMLCh * getValue() const
Get the default/fixed value of this attribute (if any.)
Definition: XMLAttDef.hpp:472
XMLAttDef::setExternalAttDeclaration
void setExternalAttDeclaration(const bool aValue)
Set the attribute decl to indicate external declaration.
Definition: XMLAttDef.hpp:532
XMLAttDef::setId
void setId(const XMLSize_t newId)
Set the pool id for this attribute type.
Definition: XMLAttDef.hpp:508
XMLAttDef::getAttTypeString
static const XMLCh * getAttTypeString(const AttTypes attrType, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Get a string representation of the passed attribute type enum.
XMLAttDef::setCreateReason
void setCreateReason(const CreateReasons newReason)
Update the create reason for this attribute type.
Definition: XMLAttDef.hpp:527
XMLAttDef::~XMLAttDef
virtual ~XMLAttDef()
Destructor.
XMLAttDef::CreateReasons
CreateReasons
Definition: XMLAttDef.hpp:113
XMLAttDef::setEnumeration
void setEnumeration(const XMLCh *const newValue)
Set the enumerated value of this attribute type.
Definition: XMLAttDef.hpp:500
XMLAttDef::fgInvalidAttrId
static const unsigned int fgInvalidAttrId
Definition: XMLAttDef.hpp:121
XMLAttDef::getId
XMLSize_t getId() const
Get the pool id of this attribute type.
Definition: XMLAttDef.hpp:462
XMLAttDef::isExternal
bool isExternal() const
Indicate whether this attribute has been declared externally.
Definition: XMLAttDef.hpp:482
XMLAttDef::setValue
void setValue(const XMLCh *const newValue)
Set the default/fixed value of this attribute type.
Definition: XMLAttDef.hpp:518
XMLAttDef::reset
virtual void reset()=0
The derived class should implement any cleaning up required between each use of an instance of this c...
XMLAttDef::getDefAttTypeString
static const XMLCh * getDefAttTypeString(const DefAttTypes attrType, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Get a string representation of the passed def attribute type enum.
XMLAttDef::getCreateReason
CreateReasons getCreateReason() const
Get the create reason for this attribute.
Definition: XMLAttDef.hpp:477
XMLAttDef::AttTypes
AttTypes
Definition: XMLAttDef.hpp:72
XMLAttDef::DefAttTypes
DefAttTypes
Definition: XMLAttDef.hpp:95
XMLAttDef::XMLAttDef
XMLAttDef(const XMLCh *const attValue, const AttTypes type, const DefAttTypes defType, const XMLCh *const enumValues=0, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
XMLAttr
This class defines the information about an attribute that will come out of the scanner during parsin...
Definition: XMLAttr.hpp:54
XMLPlatformUtils::fgMemoryManager
static MemoryManager * fgMemoryManager
The configurable memory manager.
Definition: PlatformUtils.hpp:121
XMLString::replicate
static char * replicate(const char *const toRep, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Replicates a string NOTE: The returned buffer is allocated with the MemoryManager.
XMemory
This class makes it possible to override the C++ memory management by adding new/delete operators to ...
Definition: XMemory.hpp:41