I am currently writing some code that shall read data from an xml file. To this end I use the pugixml module that offes a class xml_document
providing methods to parse the file.
To store this data I have created a class tXmlDoc
that manages loading operations (like setting path, storing the parse result and so forth).
I now wanted to include a copy constructor to this tXmlDoc
but, alas, I cannot copy the pugi::xml_document
member as pugixml apparantly explicitely denies copying as far as I understand the code of this module.
What would be your advice how to handle this? I would not like to write a copy constructor for pugixml as I am certain that the author has good reasons to deny this and I would not like to fiddle with that.
BTW, I have a similiar issue with the assignment operator.
As it seems only a move constructor is implemented in pugixml.
Here's my current tXmlDoc
header.
#pragma once
#include <iostream>
#include <string>
#include <array>
#include "../../libs/pugixml-1.11/src/pugixml.hpp"
#include "XmlData_General.h"
#include "XmlNodes.h"
namespace nXml
{
/**
* This class provides methods and helper functions to:
* - read an xml file identified by its file name including suffix and the path to this file
* - load the root node of the xml document
* - to manage basic information of the root node
*/
class tXmlDoc
{
public:
tXmlDoc();
tXmlDoc(tXmlDoc&); //copy constructor
~tXmlDoc();
tXmlDoc& operator=(const tXmlDoc&);
void LoadXmlFile(const std::string& file_name, std::string& file_path);
pugi::xml_node GetRootNode();
std::string GetFileName();
std::string GetFilePath();
std::string GetFullPath(const std::string& file_name, std::string& file_path);
void SetFileName(const std::string& file_name);
void SetFilePath(const std::string& file_path);
bool GetFileLoaded();
bool GetNodeCorrect();
int GetErrorCode();
int GetChildNumber();
pugi::xml_parse_result GetXmlResult();
void LoadData();
void CheckNode();
protected:
std::string file_path = ""; //is set when calling LoadXmlFile
std::string file_name = ""; //is set when calling LoadXmlFile
bool file_loaded = false; //provides information is file was successfully loaded (file correctly loaded: true). Modified by method LoadXmlFile
bool node_correct = false; //indicating of node structure on its child level is correct
int error_code = 0; //provides information about occuring errors (no error: 0). Modified by method LoadXmlFile
int n_childs = 0;
pugi::xml_node root_node = pugi::xml_node(); //contains the root node of the xml document. Filled when calling LoadData (via calling GetRootNode inside LoadData)
pugi::xml_parse_result xml_result; //contains information about parsing result. Filled by method LoadXmlFile
pugi::xml_document xml_doc; //contains the entire document
//make sNodeNames known
sXmlNodeNames sNodeNames;
}
;
};