00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "PrefixConfigNode.h"
00021 #include "EvolutionSyncClient.h"
00022
00023 #include <boost/foreach.hpp>
00024 #include <boost/algorithm/string/predicate.hpp>
00025
00026 PrefixConfigNode::PrefixConfigNode(const string prefix,
00027 const boost::shared_ptr<ConfigNode> &node) :
00028 m_prefix(prefix),
00029 m_node(node),
00030 m_readOnlyNode(node)
00031 {
00032 }
00033
00034 PrefixConfigNode::PrefixConfigNode(const string prefix,
00035 const boost::shared_ptr<const ConfigNode> &node) :
00036 m_prefix(prefix),
00037 m_readOnlyNode(node)
00038 {
00039 }
00040
00041 string PrefixConfigNode::readProperty(const string &property) const
00042 {
00043 return m_readOnlyNode->readProperty(m_prefix + property);
00044 }
00045
00046 void PrefixConfigNode::setProperty(const string &property,
00047 const string &value,
00048 const string &comment,
00049 const string *defValue)
00050 {
00051 m_node->setProperty(m_prefix + property,
00052 value,
00053 comment,
00054 defValue);
00055 }
00056
00057 void PrefixConfigNode::readProperties(map<string, string> &props) const
00058 {
00059 map<string, string> original;
00060 m_readOnlyNode->readProperties(original);
00061
00062 BOOST_FOREACH(const StringPair &prop, original) {
00063 string key = prop.first;
00064 string value = prop.second;
00065
00066 if (boost::starts_with(key, m_prefix)) {
00067 props[key.substr(m_prefix.size())] = value;
00068 }
00069 }
00070 }
00071
00072 void PrefixConfigNode::removeProperty(const string &property)
00073 {
00074 m_node->removeProperty(m_prefix + property);
00075 }
00076
00077 void PrefixConfigNode::flush()
00078 {
00079 if (!m_node.get()) {
00080 EvolutionSyncClient::throwError(getName() + ": read-only, flushing not allowed");
00081 }
00082 m_node->flush();
00083 }