00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "FilterConfigNode.h"
00021 #include "EvolutionSyncClient.h"
00022
00023 #include <boost/foreach.hpp>
00024
00025 FilterConfigNode::FilterConfigNode(const boost::shared_ptr<ConfigNode> &node,
00026 const ConfigFilter &filter) :
00027 m_filter(filter),
00028 m_node(node),
00029 m_readOnlyNode(node)
00030 {
00031 }
00032
00033 FilterConfigNode::FilterConfigNode(const boost::shared_ptr<const ConfigNode> &node,
00034 const ConfigFilter &filter) :
00035 m_filter(filter),
00036 m_readOnlyNode(node)
00037 {
00038 }
00039
00040 void FilterConfigNode::addFilter(const string &property,
00041 const string &value)
00042 {
00043 m_filter[property] = value;
00044 }
00045
00046 void FilterConfigNode::setFilter(const ConfigFilter &filter)
00047 {
00048 m_filter = filter;
00049 }
00050
00051 string FilterConfigNode::readProperty(const string &property) const
00052 {
00053 ConfigFilter::const_iterator it = m_filter.find(property);
00054
00055 if (it != m_filter.end()) {
00056 return it->second;
00057 } else {
00058 return m_readOnlyNode->readProperty(property);
00059 }
00060 }
00061
00062 void FilterConfigNode::setProperty(const string &property,
00063 const string &value,
00064 const string &comment,
00065 const string *defValue)
00066 {
00067 ConfigFilter::iterator it = m_filter.find(property);
00068
00069 if (!m_node.get()) {
00070 EvolutionSyncClient::throwError(getName() + ": read-only, setting properties not allowed");
00071 }
00072
00073 if (it != m_filter.end()) {
00074 m_filter.erase(it);
00075 }
00076 m_node->setProperty(property, value, comment, defValue);
00077 }
00078
00079 void FilterConfigNode::readProperties(map<string, string> &props) const
00080 {
00081 m_readOnlyNode->readProperties(props);
00082
00083 BOOST_FOREACH(const StringPair &filter, m_filter) {
00084 props.insert(filter);
00085 }
00086 }
00087
00088 void FilterConfigNode::removeProperty(const string &property)
00089 {
00090 ConfigFilter::iterator it = m_filter.find(property);
00091
00092 if (!m_node.get()) {
00093 EvolutionSyncClient::throwError(getName() + ": read-only, removing properties not allowed");
00094 }
00095
00096 if (it != m_filter.end()) {
00097 m_filter.erase(it);
00098 }
00099 m_node->removeProperty(property);
00100 }
00101
00102 void FilterConfigNode::flush()
00103 {
00104 if (!m_node.get()) {
00105 EvolutionSyncClient::throwError(getName() + ": read-only, flushing not allowed");
00106 }
00107 m_node->flush();
00108 }
00109
00110 FilterConfigNode::ConfigFilter::operator string () const {
00111 vector<string> res;
00112
00113 BOOST_FOREACH(const StringPair &filter, *this) {
00114 res.push_back(filter.first + " = " + filter.second);
00115 }
00116 sort(res.begin(), res.end());
00117 return boost::join(res, "\n");
00118 }