2 * Copyright (C) 2008-2009 Patrick Ohly <patrick.ohly@gmx.de>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) version 3.
9 * This library 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 GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 #include <syncevo/SafeConfigNode.h>
21 #include <syncevo/SyncContext.h>
23 #include <boost/foreach.hpp>
25 #include <syncevo/declarations.h>
28 SafeConfigNode::SafeConfigNode(const boost::shared_ptr<ConfigNode> &node) :
35 SafeConfigNode::SafeConfigNode(const boost::shared_ptr<const ConfigNode> &node) :
41 InitStateString SafeConfigNode::readProperty(const string &property) const
43 InitStateString res = m_readOnlyNode->readProperty(escape(property));
44 return InitStateString(unescape(res.get()), res.wasSet());
47 void SafeConfigNode::writeProperty(const string &property,
48 const InitStateString &value,
49 const string &comment)
51 m_node->writeProperty(escape(property),
52 InitStateString(escape(value.get()), value.wasSet()),
56 void SafeConfigNode::readProperties(ConfigProps &props) const
59 m_readOnlyNode->readProperties(original);
61 BOOST_FOREACH(const StringPair &prop, original) {
62 string key = unescape(prop.first);
63 string value = unescape(prop.second);
69 void SafeConfigNode::removeProperty(const string &property)
71 m_node->removeProperty(escape(property));
74 void SafeConfigNode::flush()
77 SyncContext::throwError(getName() + ": read-only, flushing not allowed");