2 * Copyright (C) 2008 Patrick Ohly
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
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, TITLE, NONINFRINGEMENT or FITNESS FOR A PARTICULAR
12 * PURPOSE. See the 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., 59 Temple Place, Suite 330, Boston, MA
20 #include "PrefixConfigNode.h"
21 #include "EvolutionSyncClient.h"
23 #include <boost/foreach.hpp>
24 #include <boost/algorithm/string/predicate.hpp>
26 PrefixConfigNode::PrefixConfigNode(const string prefix,
27 const boost::shared_ptr<ConfigNode> &node) :
34 PrefixConfigNode::PrefixConfigNode(const string prefix,
35 const boost::shared_ptr<const ConfigNode> &node) :
41 string PrefixConfigNode::readProperty(const string &property) const
43 return m_readOnlyNode->readProperty(m_prefix + property);
46 void PrefixConfigNode::setProperty(const string &property,
48 const string &comment,
49 const string *defValue)
51 m_node->setProperty(m_prefix + property,
57 void PrefixConfigNode::readProperties(map<string, string> &props) const
59 map<string, string> original;
60 m_readOnlyNode->readProperties(original);
62 BOOST_FOREACH(const StringPair &prop, original) {
63 string key = prop.first;
64 string value = prop.second;
66 if (boost::starts_with(key, m_prefix)) {
67 props[key.substr(m_prefix.size())] = value;
72 void PrefixConfigNode::removeProperty(const string &property)
74 m_node->removeProperty(m_prefix + property);
77 void PrefixConfigNode::flush()
80 EvolutionSyncClient::throwError(getName() + ": read-only, flushing not allowed");