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/PrefixConfigNode.h>
21 #include <syncevo/SyncContext.h>
23 #include <boost/foreach.hpp>
24 #include <boost/algorithm/string/predicate.hpp>
26 #include <syncevo/declarations.h>
29 PrefixConfigNode::PrefixConfigNode(const string prefix,
30 const boost::shared_ptr<ConfigNode> &node) :
37 PrefixConfigNode::PrefixConfigNode(const string prefix,
38 const boost::shared_ptr<const ConfigNode> &node) :
44 InitStateString PrefixConfigNode::readProperty(const string &property) const
46 return m_readOnlyNode->readProperty(m_prefix + property);
49 void PrefixConfigNode::writeProperty(const string &property,
50 const InitStateString &value,
51 const string &comment)
53 m_node->writeProperty(m_prefix + property,
58 void PrefixConfigNode::readProperties(ConfigProps &props) const
61 m_readOnlyNode->readProperties(original);
63 BOOST_FOREACH(const StringPair &prop, original) {
64 string key = prop.first;
65 string value = prop.second;
67 if (boost::starts_with(key, m_prefix)) {
68 props[key.substr(m_prefix.size())] = value;
73 void PrefixConfigNode::clear()
76 m_readOnlyNode->readProperties(original);
77 BOOST_FOREACH(const StringPair &prop, original) {
78 string key = prop.first;
79 if (boost::starts_with(key, m_prefix)) {
80 m_node->removeProperty(key);
85 void PrefixConfigNode::removeProperty(const string &property)
87 m_node->removeProperty(m_prefix + property);
90 void PrefixConfigNode::flush()
93 SyncContext::throwError(getName() + ": read-only, flushing not allowed");