diff options
| author | Oskari Timperi <oskari.timperi@iki.fi> | 2011-05-31 10:26:32 +0300 |
|---|---|---|
| committer | Oskari Timperi <oskari.timperi@iki.fi> | 2011-05-31 10:26:32 +0300 |
| commit | 5fb5bb1c7cc0ce266f60ab272915a48770d1443f (patch) | |
| tree | 83247683ff95ba11197e3a3d337df9a4579d745c /sxml.cpp | |
| parent | b7a61ba83cbfa0f9684ce9cf476d4c819d1f04ba (diff) | |
| download | sxml-5fb5bb1c7cc0ce266f60ab272915a48770d1443f.tar.gz sxml-5fb5bb1c7cc0ce266f60ab272915a48770d1443f.zip | |
More element::add_child() overloads, misc changes
Diffstat (limited to 'sxml.cpp')
| -rw-r--r-- | sxml.cpp | 47 |
1 files changed, 37 insertions, 10 deletions
@@ -25,15 +25,25 @@ #include "sxml.h" +#include <sstream> +//#include <iostream> + using std::string; using std::ostringstream; +//using std::cout; +//using std::endl; namespace sxml { element::element(element *parent) : m_parent(parent), m_modified(true) -{} +{ + if (parent != NULL) + { + parent->add_child(this); + } +} element::element(const element &elem) : m_parent(elem.m_parent), @@ -49,7 +59,12 @@ element::element(const string &name, element *parent) : m_parent(parent), m_name(name), m_modified(true) -{} +{ + if (parent != NULL) + { + parent->add_child(this); + } +} element::~element() { @@ -128,15 +143,27 @@ string element::to_string(bool nice, int indent) element *element::add_child(element *child) { + child->m_parent = this; m_children.push_back(child); - m_modified = true; - return this; + set_modified(true); + return child; +} + +element *element::add_child(const element &child) +{ + element *c = new element(child); + return add_child(c); +} + +element *element::add_child(const std::string &tag) +{ + return new element(tag, this); } template<> element *element::set_text<>(const string &text) { m_text = text; - m_modified = true; + set_modified(true); return this; } @@ -144,7 +171,7 @@ template<> element *element::set_attr<>(const string &name, const string &value) { m_attributes[name] = value; - m_modified = true; + set_modified(true); return this; } @@ -155,7 +182,8 @@ element_list element::clone_children() const element_list::const_iterator ei = m_children.begin(); for (; ei != m_children.end(); ++ei) { - element *clone = new element(*(*ei)); + element *orig = *ei; + element *clone = new element(*orig); clones.push_back(clone); } @@ -166,10 +194,9 @@ void element::set_modified(bool modified) { m_modified = modified; - if (modified) + if (modified && m_parent != NULL) { - if (m_parent != NULL) - m_parent->set_modified(true); + m_parent->set_modified(true); } } |
