2 Copyright (C) 2011 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include <boost/variant/static_visitor.hpp>
26 #include "gui_object.h"
31 const string GUIObjectState::xml_node_name (X_("GUIObjectState"));
33 GUIObjectState::~GUIObjectState ()
39 GUIObjectState::clear_maps ()
41 _property_maps.clear ();
44 class gos_string_vistor : public boost::static_visitor<> {
46 gos_string_vistor (std::ostream& o)
49 void operator() (const int64_t& i) {
53 void operator() (const double& d) {
54 stream << std::setprecision (12) << d;
58 void operator() (const std::string& s) {
67 GUIObjectState::get_state () const
69 XMLNode* root = new XMLNode (xml_node_name);
71 for (StringPropertyMap::const_iterator i = _property_maps.begin(); i != _property_maps.end(); ++i) {
73 const PropertyMap& pmap (i->second);
74 XMLNode* id_node = new XMLNode (X_("Object"));
76 id_node->add_property ("id", i->first);
78 for (PropertyMap::const_iterator p = pmap.begin(); p != pmap.end(); ++p) {
80 gos_string_vistor gsv (ss);
81 boost::apply_visitor (gsv, p->second);
82 id_node->add_property (p->first.c_str(), ss.str());
85 root->add_child_nocopy (*id_node);
93 GUIObjectState::set_state (const XMLNode& node)
95 if (node.name() != xml_node_name) {
101 for (XMLNodeList::const_iterator i = node.children().begin(); i != node.children().end(); ++i) {
102 if ((*i)->name() == X_("Object")) {
104 XMLNode* child = (*i);
105 const XMLProperty* idp = child->property (X_("id"));
111 string id (idp->value());
113 for (XMLPropertyList::const_iterator p = child->properties().begin(); p != child->properties().end(); ++p) {
114 /* note that this always sets the property with
115 a string value, and so is not equivalent to
116 a call made by the program that passed a
119 if ((*p)->name() != X_("id")) {
120 set (id, (*p)->name(), (*p)->value());
131 GUIObjectState::load (const XMLNode& node)
133 (void) set_state (node);
137 GUIObjectState::operator= (const GUIObjectState& other)
139 _property_maps = other._property_maps;