XMLAttDef.hpp
Go to the documentation of this file.
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id$
*/
#if !defined(XERCESC_INCLUDE_GUARD_XMLATTDEF_HPP)
#define XERCESC_INCLUDE_GUARD_XMLATTDEF_HPP
#include <xercesc/util/PlatformUtils.hpp>
#include <xercesc/util/XMLString.hpp>
#include <xercesc/util/XMemory.hpp>
#include <xercesc/internal/XSerializable.hpp>
XERCES_CPP_NAMESPACE_BEGIN
class XMLAttr;
class XMLPARSER_EXPORT XMLAttDef : public XSerializable, public XMemory
{
public:
// -----------------------------------------------------------------------
// Class specific types
//
// AttTypes
// The list of possible types that an attribute can have, according
// to the XML 1.0 spec and schema.
//
// DefAttTypes
// The modifiers that an attribute decl can have, which indicates
// whether instances of that attributes are required, implied, etc..
//
// CreateReasons
// This type is used to store how an attribute declaration got into
// the elementdecl's attribute pool.
//
// -----------------------------------------------------------------------
enum AttTypes
{
CData = 0
, ID = 1
, IDRef = 2
, IDRefs = 3
, Entity = 4
, Entities = 5
, NmToken = 6
, NmTokens = 7
, Notation = 8
, Enumeration = 9
, Simple = 10
, Any_Any = 11
, Any_Other = 12
, Any_List = 13
, AttTypes_Count
, AttTypes_Min = 0
, AttTypes_Max = 13
, AttTypes_Unknown = -1
};
enum DefAttTypes
{
Default = 0
, Fixed = 1
, Required = 2
, Required_And_Fixed = 3
, Implied = 4
, ProcessContents_Skip = 5
, ProcessContents_Lax = 6
, ProcessContents_Strict = 7
, Prohibited = 8
, DefAttTypes_Count
, DefAttTypes_Min = 0
, DefAttTypes_Max = 8
, DefAttTypes_Unknown = -1
};
enum CreateReasons
{
NoReason
, JustFaultIn
};
// -----------------------------------------------------------------------
// Public static data members
// -----------------------------------------------------------------------
static const unsigned int fgInvalidAttrId;
// -----------------------------------------------------------------------
// Public, static methods
// -----------------------------------------------------------------------
static const XMLCh* getAttTypeString(const AttTypes attrType
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
static const XMLCh* getDefAttTypeString(const DefAttTypes attrType
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
// -----------------------------------------------------------------------
// Destructor
// -----------------------------------------------------------------------
virtual ~XMLAttDef();
// -----------------------------------------------------------------------
// The virtual attribute def interface
// -----------------------------------------------------------------------
virtual const XMLCh* getFullName() const = 0;
virtual void reset() = 0;
// -----------------------------------------------------------------------
// Getter methods
// -----------------------------------------------------------------------
DefAttTypes getDefaultType() const;
const XMLCh* getEnumeration() const;
XMLSize_t getId() const;
AttTypes getType() const;
const XMLCh* getValue() const;
CreateReasons getCreateReason() const;
bool isExternal() const;
MemoryManager* getMemoryManager() const;
// -----------------------------------------------------------------------
// Setter methods
// -----------------------------------------------------------------------
void setDefaultType(const XMLAttDef::DefAttTypes newValue);
void setId(const XMLSize_t newId);
void setType(const XMLAttDef::AttTypes newValue);
void setValue(const XMLCh* const newValue);
void setEnumeration(const XMLCh* const newValue);
void setCreateReason(const CreateReasons newReason);
void setExternalAttDeclaration(const bool aValue);
/***
* Support for Serialization/De-serialization
***/
DECL_XSERIALIZABLE(XMLAttDef)
protected :
// -----------------------------------------------------------------------
// Hidden constructors
// -----------------------------------------------------------------------
XMLAttDef
(
const AttTypes type = CData
, const DefAttTypes defType= Implied
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
);
XMLAttDef
(
const XMLCh* const attValue
, const AttTypes type
, const DefAttTypes defType
, const XMLCh* const enumValues = 0
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
);
private :
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
XMLAttDef(const XMLAttDef&);
XMLAttDef& operator=(const XMLAttDef&);
// -----------------------------------------------------------------------
// Private helper methods
// -----------------------------------------------------------------------
void cleanUp();
// -----------------------------------------------------------------------
// Private data members
//
// fDefaultType
// Indicates what, if any, default stuff this attribute has.
//
// fEnumeration
// If its an enumeration, this is the list of values as space
// separated values.
//
// fId
// This is the unique id of this attribute, given to it when its put
// into the validator's attribute decl pool. It defaults to the
// special value XMLAttrDef::fgInvalidAttrId.
//
// fType
// The type of attribute, which is one of the AttTypes values.
//
// fValue
// This is the value of the attribute, which is the default value
// given in the attribute declaration.
//
// fCreateReason
// This flag tells us how this attribute got created. Sometimes even
// the attribute was not declared for the element, we want to fault
// fault it into the pool to avoid lots of redundant errors.
//
// fExternalAttribute
// This flag indicates whether or not the attribute was declared externally.
// -----------------------------------------------------------------------
DefAttTypes fDefaultType;
AttTypes fType;
CreateReasons fCreateReason;
bool fExternalAttribute;
XMLSize_t fId;
XMLCh* fValue;
XMLCh* fEnumeration;
MemoryManager* fMemoryManager;
};
// ---------------------------------------------------------------------------
// Getter methods
// ---------------------------------------------------------------------------
inline XMLAttDef::DefAttTypes XMLAttDef::getDefaultType() const
{
return fDefaultType;
}
inline const XMLCh* XMLAttDef::getEnumeration() const
{
return fEnumeration;
}
inline XMLSize_t XMLAttDef::getId() const
{
return fId;
}
inline XMLAttDef::AttTypes XMLAttDef::getType() const
{
return fType;
}
inline const XMLCh* XMLAttDef::getValue() const
{
return fValue;
}
inline XMLAttDef::CreateReasons XMLAttDef::getCreateReason() const
{
return fCreateReason;
}
inline bool XMLAttDef::isExternal() const
{
return fExternalAttribute;
}
inline MemoryManager* XMLAttDef::getMemoryManager() const
{
return fMemoryManager;
}
// ---------------------------------------------------------------------------
// XMLAttDef: Setter methods
// ---------------------------------------------------------------------------
inline void XMLAttDef::setDefaultType(const XMLAttDef::DefAttTypes newValue)
{
fDefaultType = newValue;
}
inline void XMLAttDef::setEnumeration(const XMLCh* const newValue)
{
if (fEnumeration)
fMemoryManager->deallocate(fEnumeration);
fEnumeration = XMLString::replicate(newValue, fMemoryManager);
}
inline void XMLAttDef::setId(const XMLSize_t newId)
{
fId = newId;
}
inline void XMLAttDef::setType(const XMLAttDef::AttTypes newValue)
{
fType = newValue;
}
inline void XMLAttDef::setValue(const XMLCh* const newValue)
{
if (fValue)
fMemoryManager->deallocate(fValue);
fValue = XMLString::replicate(newValue, fMemoryManager);
}
inline void
XMLAttDef::setCreateReason(const XMLAttDef::CreateReasons newReason)
{
fCreateReason = newReason;
}
inline void XMLAttDef::setExternalAttDeclaration(const bool aValue)
{
fExternalAttribute = aValue;
}
XERCES_CPP_NAMESPACE_END
#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
XMLSize_t
size_t XMLSize_t
Definition Xerces_autoconf_config.hpp:112
XMLCh
char16_t XMLCh
Definition Xerces_autoconf_config.hpp:120
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