22 #define TIXML_USE_TICPP 23 #ifdef TIXML_USE_TICPP 30 using namespace ticpp;
44 if (0 != firstAttribute) {
45 Attribute attribute(const_cast< TiXmlAttribute* >(firstAttribute));
66 return Visit(
Text(const_cast< TiXmlText* >(&text)));
70 return Visit(
Comment(const_cast< TiXmlComment* >(&comment)));
81 SetTiXmlPointer(attribute);
92 this->m_impRC->DecRef();
98 this->m_impRC->IncRef();
129 if (0 == attribute) {
130 if (throwIfNoAttribute) {
147 if (0 == attribute) {
148 if (throwIfNoAttribute) {
183 bool rememberSpawnedWrapper)
const {
184 if (0 == tiXmlNode) {
194 switch (tiXmlNode->
Type()) {
223 if (rememberSpawnedWrapper) {
230 std::string
Node::Value()
const {
return GetTiXmlPointer()->ValueStr(); }
237 if ((0 == parent) && throwIfNoParent) {
241 return NodeFactory(parent,
false);
245 return FirstChild(
"", throwIfNoChildren);
249 return FirstChild(value.c_str(), throwIfNoChildren);
255 if (0 == strlen(value)) {
258 childNode = GetTiXmlPointer()->
FirstChild(value);
261 if ((0 == childNode) && throwIfNoChildren) {
262 TICPPTHROW(
"Child with the value of \"" << value <<
"\" not found");
265 return NodeFactory(childNode,
false);
269 return LastChild(
"", throwIfNoChildren);
273 return LastChild(value.c_str(), throwIfNoChildren);
279 if (0 == strlen(value)) {
280 childNode = GetTiXmlPointer()->
LastChild();
282 childNode = GetTiXmlPointer()->
LastChild(value);
285 if ((0 == childNode) && throwIfNoChildren) {
286 TICPPTHROW(
"Child with the value of \"" << value <<
"\" not found");
289 return NodeFactory(childNode,
false);
301 return NodeFactory(pointer,
false);
314 return NodeFactory(pointer,
false);
319 TICPPTHROW(
"Node is a Document and can't be inserted");
329 return NodeFactory(pointer);
334 TICPPTHROW(
"Node is a Document and can't be linked");
340 if (0 == GetTiXmlPointer()->LinkEndChild(childNode->
GetTiXmlPointer())) {
349 TICPPTHROW(
"Node is a Document and can't be inserted");
362 return NodeFactory(pointer);
367 TICPPTHROW(
"Node is a Document and can't be inserted");
380 return NodeFactory(pointer);
385 TICPPTHROW(
"Node is a Document and can't be inserted");
398 return NodeFactory(pointer);
404 <<
") is not a child of this Node (" 411 return PreviousSibling(
"", throwIfNoSiblings);
415 bool throwIfNoSiblings)
const {
416 return PreviousSibling(value.c_str(), throwIfNoSiblings);
422 if (0 == strlen(value)) {
428 if ((0 == sibling) && throwIfNoSiblings) {
429 TICPPTHROW(
"No Siblings found with value, '" << value
430 <<
"', Prior to this Node (" 435 return NodeFactory(sibling,
false);
439 return NextSibling(
"", throwIfNoSiblings);
443 return NextSibling(value.c_str(), throwIfNoSiblings);
449 if (0 == strlen(value)) {
455 if ((0 == sibling) && throwIfNoSiblings) {
456 TICPPTHROW(
"No Siblings found with value, '" << value <<
"', After this Node (" 461 return NodeFactory(sibling,
false);
465 return NextSiblingElement(
"", throwIfNoSiblings);
469 bool throwIfNoSiblings)
const {
470 return NextSiblingElement(value.c_str(), throwIfNoSiblings);
474 bool throwIfNoSiblings)
const {
477 if (0 == strlen(value)) {
484 if (throwIfNoSiblings) {
485 TICPPTHROW(
"No Element Siblings found with value, '" 487 <<
"', After this Node (" 502 return FirstChildElement(
"", throwIfNoChildren);
506 bool throwIfNoChildren)
const {
507 return FirstChildElement(value.c_str(), throwIfNoChildren);
513 if (0 == strlen(value)) {
520 if (throwIfNoChildren) {
522 <<
") does NOT contain a child with the value of '" 542 if (throwIfNoDocument) {
543 TICPPTHROW(
"This node (" <<
Value() <<
") is not linked under a document")
626 TICPPTHROW(
"This node (" <<
Value() <<
") is not a StylesheetReference")
642 std::unique_ptr< Node > temp(NodeFactory(node,
false,
false));
651 return GetTiXmlPointer()->Accept(visitor);
736 bool throwIfParseError,
749 "DefaultValueCausedByCreatingAnElementWithNoParameters")) {
770 if ((0 == attribute) && throwIfNoAttributes) {
774 if (0 == attribute) {
775 if (throwIfNoAttributes) {
792 if ((0 == attribute) && throwIfNoAttributes) {
796 if (0 == attribute) {
797 if (throwIfNoAttributes) {
811 const std::string& defaultValue)
const {
876 const std::string& encoding,
877 const std::string& standalone)
903 const std::string& href)
916 : m_details(details) {}
930 std::vector< Base* >::reverse_iterator wrapper;
932 for (wrapper = m_spawnedWrappers.rbegin(); wrapper != m_spawnedWrappers.rend();
937 m_spawnedWrappers.clear();
941 DeleteSpawnedWrappers();
944 this->m_tiRC->Nullify();
947 this->m_tiRC->DecRef();
954 , m_tiCppRC(tiCppRC) {}
975 #endif // TIXML_USE_TICPP
Wrapper around TiXmlNode.
std::unique_ptr< Node > Clone() const
Create an exact duplicate of this node and return it.
void RemoveChild(Node *removeThis)
Delete a child of this node.
An attribute is a name-value pair.
void operator=(const Attribute ©)
If you call the Accept() method, it requires being passed a TiXmlVisitor class to handle callbacks...
virtual const TiXmlElement * ToElement() const
Cast to a more defined type. Will return null not of the requested type.
Node * PreviousSibling(bool throwIfNoSiblings=true) const
Navigate to a sibling node.
void Clear()
Clear all Nodes below this.
const char * Type() const
Type. Will return an empty string if none was found.
std::vector< ticpp::Base *> m_spawnedWrappers
Remember all wrappers that we've created with 'new' - ( e.g.
Wrapper around TiXmlElement.
void IteratePrevious(const std::string &, Attribute **previous) const
const TiXmlNode * LastChild() const
Comment * ToComment() const
Pointer conversion - replaces TiXmlNode::ToComment.
Document * ToDocument() const
Pointer conversion - replaces TiXmlNode::ToDocument.
virtual const TiXmlDocument * ToDocument() const
Cast to a more defined type. Will return null not of the requested type.
const char * Name() const
Return the name of this attribute.
virtual bool Visit(const TiXmlDeclaration &declaration)
Visit a declaration.
#define TICPPTHROW(message)
This allows you to stream your exceptions in.
void GetAttributeOrDefault(const std::string &name, T *value, const DefaulT &defaultValue) const
Gets an attribute of name from an element, if it doesn't exist it will return the defaultValue...
StylesheetReference()
Default Constructor.
virtual const TiXmlElement * ToElement() const
Cast to a more defined type. Will return null if not of the requested type.
bool Accept(TiXmlVisitor *visitor) const
Accept a hierchical visit the nodes in the TinyXML DOM.
TiCppRC * Get()
Get internal pointer to the TiCppRC object - not reference counted, use at your own risk...
virtual ~TiCppRC()
Destructor Nullifies the pointer to this held by the reference counter Decrements reference count...
bool NoChildren() const
Check if this node has no children.
const char * GetText() const
Convenience function for easy access to the text inside an element.
virtual const TiXmlText * ToText() const
Cast to a more defined type. Will return null if not of the requested type.
TiCppRC * m_tiCppRC
Holds pointer to an object inheriting TiCppRC.
bool Error() const
If an error occurs, Error will be set to true.
Attribute * Previous(bool throwIfNoAttribute=true) const
Get the previous sibling attribute in the DOM.
void ValidatePointer() const
void Nullify()
Allows the TiCppRC object to set the pointer to itself ( m_tiCppRc ) to nullptr when the TiCppRC obje...
void SetTiXmlPointer(TiXmlAttribute *newPointer)
TiXmlNode * ReplaceChild(TiXmlNode *replaceThis, const TiXmlNode &withThis)
Replace a child of this node.
Declaration()
Default Constructor.
Document()
Default Constructor.
const char * Standalone() const
Is this a standalone document?
bool GetTextImp(std::string *value) const
Node * LastChild(bool throwIfNoChildren=true) const
The last child of this node.
Implementation of Node wrapper.
virtual void Print(FILE *cfile, int depth) const
All TinyXml classes can print themselves to a filestream or the string class (TiXmlString in non-STL ...
const char * Href() const
Href. Will return an empty string if none was found.
bool LoadFile(TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
Load a file using the current document value.
void SetValue(const char *_value)
Changes the value of the node.
TiXmlNode * InsertEndChild(const TiXmlNode &addThis)
Add a new node related to this.
TiXmlNode * InsertBeforeChild(TiXmlNode *beforeThis, const TiXmlNode &addThis)
Add a new node related to this.
void LoadFile(TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
Load a file using the current document value.
bool IsNull()
Returns state of internal pointer - will be null if the object was deleted.
Wrapper around TiXmlText.
const std::string & ValueStr() const
Return the value of this attribute.
StylesheetReference * ToStylesheetReference() const
Pointer conversion - replaces TiXmlNode::ToStylesheetReference.
std::string Standalone() const
StandAlone.
bool SaveFile() const
Save a file using the current document value. Returns true if successful.
void SaveFile() const
Save a file using the current document value.
const TiXmlElement * FirstChildElement() const
Convenience function to get through elements.
const char * Encoding() const
Encoding. Will return an empty string if none was found.
virtual TiXmlNode * GetTiXmlPointer() const =0
A stylesheet reference looks like this:
In correct XML the declaration is the first entry in the file.
Element * ToElement() const
Pointer conversion - replaces TiXmlNode::ToElement.
std::string Value() const
Get the value of this node.
const TiXmlNode * PreviousSibling() const
Navigate to a sibling node.
virtual const TiXmlDocument * ToDocument() const
Cast to a more defined type. Will return null if not of the requested type.
std::string Href() const
Href.
void Parse(const std::string &xml, bool throwIfParseError=true, TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
Parse the given xml data.
Element()
Default Constructor.
Any tag that tinyXml doesn't recognize is saved as an unknown.
void IterateNext(const std::string &, Attribute **next) const
virtual const TiXmlText * ToText() const
Cast to a more defined type. Will return null not of the requested type.
virtual const TiXmlComment * ToComment() const
Cast to a more defined type. Will return null if not of the requested type.
int Type() const
Query the type (as TiXmlNode::NodeType ) of this node.
const char * Version() const
Version. Will return an empty string if none was found.
Node * ReplaceChild(Node *replaceThis, Node &withThis)
Replace a child of this node.
const char * Value() const
The meaning of 'value' changes for the specific type of TiXmlNode.
const TiXmlAttribute * LastAttribute() const
Access the last attribute in this element.
bool GetAttributeImp(const std::string &name, std::string *value) const
const char * what() const
Override std::exception::what() to return m_details.
void RemoveAttribute(const std::string &name)
Removes attribute from element.
void RemoveAttribute(const char *name)
Deletes an attribute with the given name.
void IncRef()
Increment Reference Count.
Node * IterateChildren(Node *previous) const
An alternate way to walk the children of a node.
Attribute * FirstAttribute(bool throwIfNoAttributes=true) const
Access the first attribute in this element.
Wrapper around TiXmlDeclaration.
Wrapper around TiXmlBase.
const TiXmlElement * NextSiblingElement() const
Convenience function to get through elements.
Always the top level node.
int m_count
Holds reference count to me, and to the node I point to.
std::string Type() const
Type.
TiXmlNode * InsertAfterChild(TiXmlNode *afterThis, const TiXmlNode &addThis)
Add a new node related to this.
std::string Name() const
Get the value of this attribute.
const TiXmlAttribute * Next() const
Get the next sibling attribute in the DOM. Returns null at end.
Node * Parent(bool throwIfNoParent=true) const
The Parent of this Node.
const TiXmlDocument * GetDocument() const
Return a pointer to the Document this node lives in.
void SetImpRC(TiXmlBase *nodeBase)
virtual bool VisitExit(const TiXmlDocument &doc)
Visit a document.
std::string Encoding() const
Encoding.
TiXmlNode * Parent()
One step up the DOM.
int Type() const
Query the type (as an enumerated value, above) of this node.
std::string m_details
Exception Details.
TiXmlAttribute * m_tiXmlPointer
Element * NextSiblingElement(bool throwIfNoSiblings=true) const
Navigate to a sibling element.
const TiXmlNode * FirstChild() const
The first child of this node. Will be null if there are no children.
virtual const char * Parse(const char *p, TiXmlParsingData *data=0, TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
Parse the given null terminated block of xml data.
virtual const TiXmlDeclaration * ToDeclaration() const
Cast to a more defined type. Will return null if not of the requested type.
Base class for reference counting functionality.
The parent class for everything in the Document Object Model.
TiXmlComment * m_tiXmlPointer
Internal pointer to the TiXml Class which is being wrapped.
std::string Version() const
Version.
void InitRef()
Set Reference Count to 1 - dangerous! - Use only if you are sure of the consequences.
TiCppRCImp(TiCppRC *tiCppRC)
Initializes m_tiCppRC pointer, and set reference count to 1.
Node * NextSibling(bool throwIfNoSiblings=true) const
Navigate to a sibling node.
const char * Attribute(const char *name) const
Given an attribute name, Attribute() returns the value for the attribute of that name, or null if none exists.
Node * InsertEndChild(Node &addThis)
Adds a child past the LastChild.
virtual const TiXmlStylesheetReference * ToStylesheetReference() const
Cast to a more defined type. Will return null if not of the requested type.
virtual const TiXmlDeclaration * ToDeclaration() const
Cast to a more defined type. Will return null not of the requested type.
virtual void Print(FILE *file, int depth) const
All TinyXml classes can print themselves to a filestream.
Text * ToText() const
Pointer conversion - replaces TiXmlNode::ToText.
Node * InsertAfterChild(Node *afterThis, Node &addThis)
Adds a child after the specified child.
virtual const TiXmlStylesheetReference * ToStylesheetReference() const
Cast to a more defined type. Will return null not of the requested type.
Wrapper around TiXmlDocument.
std::string Value() const
Get the value of this attribute.
Attribute * Next(bool throwIfNoAttribute=true) const
Get the next sibling attribute in the DOM.
TiCppRCImp * m_impRC
Holds status of internal TiXmlPointer - use this to determine if object has been deleted already...
Attribute()
Construct an empty attribute.
Node * LinkEndChild(Node *childNode)
Adds a child past the LastChild.
T GetAttribute(const std::string &name, bool throwIfNotFound=true) const
Returns an attribute of name from an element.
virtual bool VisitEnter(const TiXmlDocument &doc)
Visit a document.
Element * FirstChildElement(bool throwIfNoChildren=true) const
The first child element of this node.
void DecRef()
Decrement Reference Count.
const TiXmlAttribute * Previous() const
Get the previous sibling attribute in the DOM. Returns null at beginning.
Node * FirstChild(bool throwIfNoChildren=true) const
The first child of this node.
const TiXmlNode * IterateChildren(const TiXmlNode *previous) const
An alternate way to walk the children of a node.
Wrapper around TiXmlStylesheetReference.
Node * InsertBeforeChild(Node *beforeThis, Node &addThis)
Adds a child before the specified child.
Attribute * LastAttribute(bool throwIfNoAttributes=true) const
Access the last attribute in this element.
Exception(const std::string &details)
Construct an exception with a message.
TiCppRC()
Constructor Spawns new reference counter with a pointer to this.
virtual TiXmlNode * Clone() const =0
Create an exact duplicate of this node and return it.
Node * NodeFactory(TiXmlNode *tiXmlNode, bool throwIfNull=true, bool rememberSpawnedWrapper=true) const
Declaration * ToDeclaration() const
Pointer conversion - replaces TiXmlNode::ToDeclaration.
const TiXmlNode * NextSibling(const std::string &_value) const
STL std::string form.
Wrapper around TiXmlAttribute.
Document * GetDocument(bool throwIfNoDocument=true) const
Return a pointer to the Document this node lives in.
The element is a container class.
bool HasAttribute(const std::string &name) const
Returns true, if attribute exists.
void DeleteSpawnedWrappers()
Delete all container objects we've spawned with 'new'.
virtual bool Visit(const TiXmlDeclaration &)
Visit a declaration.
const TiXmlAttribute * FirstAttribute() const
Access the first attribute in this element.