Changeset 42:6f97b6d207aa in rrlib_xml for tDocument.cpp
- Timestamp:
- 16.06.2012 19:08:32 (11 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
tDocument.cpp
r40 r42 20 20 // 21 21 //---------------------------------------------------------------------- 22 /*!\file t XMLDocument.cpp22 /*!\file tDocument.cpp 23 23 * 24 24 * \author Tobias Foehst … … 28 28 */ 29 29 //---------------------------------------------------------------------- 30 #include "rrlib/xml 2_wrapper/tXMLDocument.h"30 #include "rrlib/xml/tDocument.h" 31 31 32 32 //---------------------------------------------------------------------- … … 38 38 // Internal includes with "" 39 39 //---------------------------------------------------------------------- 40 #include "rrlib/xml 2_wrapper/tXML2WrapperException.h"41 #include "rrlib/xml 2_wrapper/tCleanupHandler.h"40 #include "rrlib/xml/tException.h" 41 #include "rrlib/xml/tCleanupHandler.h" 42 42 43 43 //---------------------------------------------------------------------- … … 55 55 namespace rrlib 56 56 { 57 namespace xml 257 namespace xml 58 58 { 59 59 … … 71 71 72 72 //---------------------------------------------------------------------- 73 // t XMLDocument constructors73 // tDocument constructors 74 74 //---------------------------------------------------------------------- 75 t XMLDocument::tXMLDocument()75 tDocument::tDocument() 76 76 : document(xmlNewDoc(reinterpret_cast<const xmlChar *>("1.0"))), 77 77 root_node(0) … … 81 81 } 82 82 83 t XMLDocument::tXMLDocument(const std::string &file_name, bool validate)83 tDocument::tDocument(const std::string &file_name, bool validate) 84 84 : document(xmlReadFile(file_name.c_str(), 0, validate ? XML_PARSE_DTDVALID : 0)), 85 root_node(reinterpret_cast<t XMLNode *>(xmlDocGetRootElement(this->document)))85 root_node(reinterpret_cast<tNode *>(xmlDocGetRootElement(this->document))) 86 86 { 87 87 assert(this->document); 88 88 if (!this->document) 89 89 { 90 throw t XML2WrapperException("Could not parse XML file `" + file_name + "'!");90 throw tException("Could not parse XML file `" + file_name + "'!"); 91 91 } 92 92 tCleanupHandler::Instance(); 93 93 } 94 94 95 t XMLDocument::tXMLDocument(const void *buffer, size_t size, bool validate)95 tDocument::tDocument(const void *buffer, size_t size, bool validate) 96 96 : document(xmlReadMemory(reinterpret_cast<const char *>(buffer), size, "noname.xml", 0, validate ? XML_PARSE_DTDVALID : 0)), 97 root_node(reinterpret_cast<t XMLNode *>(xmlDocGetRootElement(this->document)))97 root_node(reinterpret_cast<tNode *>(xmlDocGetRootElement(this->document))) 98 98 { 99 99 if (!this->document) 100 100 { 101 throw t XML2WrapperException("Could not parse XML from memory buffer `" + std::string(reinterpret_cast<const char *>(buffer)) + "'!");101 throw tException("Could not parse XML from memory buffer `" + std::string(reinterpret_cast<const char *>(buffer)) + "'!"); 102 102 } 103 103 tCleanupHandler::Instance(); 104 104 } 105 105 106 t XMLDocument::tXMLDocument(tXMLDocument && other)106 tDocument::tDocument(tDocument && other) 107 107 : document(0), 108 108 root_node(0) … … 113 113 114 114 //---------------------------------------------------------------------- 115 // t XMLDocument destructor115 // tDocument destructor 116 116 //---------------------------------------------------------------------- 117 t XMLDocument::~tXMLDocument()117 tDocument::~tDocument() 118 118 { 119 119 if (this->document) … … 124 124 125 125 //---------------------------------------------------------------------- 126 // t XMLDocument operator =126 // tDocument operator = 127 127 //---------------------------------------------------------------------- 128 t XMLDocument &tXMLDocument::operator = (const tXMLDocument & other)128 tDocument &tDocument::operator = (const tDocument & other) 129 129 { 130 130 if (this == &other) … … 134 134 xmlFreeDoc(this->document); 135 135 this->document = xmlCopyDoc(other.document, true); 136 this->root_node = reinterpret_cast<t XMLNode *>(xmlDocGetRootElement(this->document));136 this->root_node = reinterpret_cast<tNode *>(xmlDocGetRootElement(this->document)); 137 137 return *this; 138 138 } 139 139 140 140 //---------------------------------------------------------------------- 141 // t XMLDocument RootNode141 // tDocument RootNode 142 142 //---------------------------------------------------------------------- 143 t XMLNode &tXMLDocument::RootNode()143 tNode &tDocument::RootNode() 144 144 { 145 145 if (!this->root_node) 146 146 { 147 throw t XML2WrapperException("No root node defined for this document!");147 throw tException("No root node defined for this document!"); 148 148 } 149 149 return *this->root_node; … … 151 151 152 152 //---------------------------------------------------------------------- 153 // t XMLDocument AddRootNode153 // tDocument AddRootNode 154 154 //---------------------------------------------------------------------- 155 t XMLNode &tXMLDocument::AddRootNode(const std::string &name)155 tNode &tDocument::AddRootNode(const std::string &name) 156 156 { 157 157 if (this->root_node) 158 158 { 159 throw t XML2WrapperException("Root node already exists with name `" + name + "'!");159 throw tException("Root node already exists with name `" + name + "'!"); 160 160 } 161 this->root_node = reinterpret_cast<t XMLNode *>(xmlNewNode(0, reinterpret_cast<const xmlChar *>(name.c_str())));161 this->root_node = reinterpret_cast<tNode *>(xmlNewNode(0, reinterpret_cast<const xmlChar *>(name.c_str()))); 162 162 xmlDocSetRootElement(this->document, this->root_node); 163 163 return *this->root_node; … … 165 165 166 166 //---------------------------------------------------------------------- 167 // t XMLDocument WriteToFile167 // tDocument WriteToFile 168 168 //---------------------------------------------------------------------- 169 void t XMLDocument::WriteToFile(const std::string &file_name, int compression) const169 void tDocument::WriteToFile(const std::string &file_name, int compression) const 170 170 { 171 171 if (compression)
Note: See TracChangeset
for help on using the changeset viewer.