campo-sirio/src/ps/xml_element.h
Simone Palacino f9a77b4736 Patch level : 12.0 no-patch
Files correlati     : ps6362.exe
Commento            :
- Personalizzazione Major:
- Migliorata leggibilita' codice
- Spostate classi in file separati
2020-03-05 10:44:33 +01:00

48 lines
2.3 KiB
C++

#ifndef __XMLELEMENT_H__
#define __XMLELEMENT_H__
#include <vector>
#include "strings.h"
#define XML_ROOT_TAG nullptr
/**
* \brief Elemento base xml.
*/
class TXML_element
{
vector<pair<TString, TString>> _attributes{};
vector<TXML_element*> _childs{};
TString _indent;
bool _info_xml;
TString _name;
TXML_element* _parent;
TString _value;
const wchar_t* _wvalue;
public:
void add_attribute(const char* _Tag, const char* _Val) { _attributes.insert(_attributes.end(), { _Tag, _Val }); }
void add_attribute(const char* _Tag, const TString& _Val) { _attributes.insert(_attributes.end(), { _Tag, _Val }); }
void add_attribute(const char* _Tag, const TDate& _Val) { _attributes.insert(_attributes.end(), { _Tag, TString((const TString&)_Val) }); }
void add_child(TXML_element& child) { child._parent = this; _childs.insert(_childs.end(), &child); }
bool print_on_file(ofstream* fout, int deep = 0, const char* indent = "");
/** Imposta tab (use_tab = true) o spazi (false). Se spazi indicare n_spazi (1 - 8): se non specificato o troppo grande sara' di 4; */
void set_indentation(bool use_tab, short n_spaces = -1);
void set_parent(TXML_element& parent) { parent.add_child(*this); }
void set_root() { _parent = XML_ROOT_TAG; }
void set_value(const TString& _Val);
bool is_root() const { return _parent == nullptr; }
TXML_element& operator<<(const char* _Val) { _value = _Val; return *this; }
explicit TXML_element(const char* name, const char* value = "", bool info_file = false) : _indent("\t"), _info_xml(info_file), _name(name), _parent(nullptr), _value(value), _wvalue(nullptr) { }
explicit TXML_element(const char* name, const wchar_t* value = L"", bool info_file = false) : _indent("\t"), _info_xml(info_file), _name(name), _parent(nullptr), _value(""), _wvalue(value) { }
explicit TXML_element(const TString& name, const TString& value = "", bool info_file = false) : _indent("\t"), _info_xml(info_file), _name(name), _parent(nullptr), _value(value), _wvalue(nullptr) { }
explicit TXML_element(const char* name, bool info_file) : TXML_element(name, "", info_file) { }
};
#endif // __XMLELEMENT_H__