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 #ifndef INCL_EVOLUTION_FILTER_CONFIG_NODE
21 # define INCL_EVOLUTION_FILTER_CONFIG_NODE
23 #include <syncevo/ConfigNode.h>
24 #include <boost/shared_ptr.hpp>
25 #include <boost/algorithm/string/case_conv.hpp>
26 #include <boost/algorithm/string.hpp>
33 #include <syncevo/declarations.h>
37 * This class acts as filter between a real config node and its user:
38 * reads which match properties which are set in the filter will
39 * return the value set in the filter. Writes will go to the underlying
40 * node and future reads will return the written value.
42 * The purpose of this class is temporarily overriding saved values
43 * during one run without having to modify the saved values.
45 class FilterConfigNode : public ConfigNode {
47 /** config filters are the same case-insensitive string to string mapping as property sets */
48 typedef ConfigProps ConfigFilter;
50 /** read-write access to underlying node */
51 FilterConfigNode(const boost::shared_ptr<ConfigNode> &node,
52 const ConfigFilter &filter = ConfigFilter());
54 /** read-only access to underlying node */
55 FilterConfigNode(const boost::shared_ptr<const ConfigNode> &node,
56 const ConfigFilter &filter = ConfigFilter());
58 virtual std::string getName() const { return m_readOnlyNode->getName(); }
60 /** add another entry to the list of filter properties */
61 virtual void addFilter(const std::string &property,
62 const InitStateString &value);
64 /** replace current filter list with new one */
65 virtual void setFilter(const ConfigFilter &filter);
66 virtual const ConfigFilter &getFilter() const { return m_filter; }
70 virtual InitStateString readProperty(const std::string &property) const;
71 virtual void writeProperty(const std::string &property,
72 const InitStateString &value,
73 const std::string &comment = "");
74 virtual void readProperties(ConfigProps &props) const;
75 virtual void removeProperty(const std::string &property);
76 virtual bool exists() const { return m_readOnlyNode->exists(); }
77 virtual bool isReadOnly() const { return !m_node || m_readOnlyNode->isReadOnly(); }
81 ConfigFilter m_filter;
82 boost::shared_ptr<ConfigNode> m_node;
83 boost::shared_ptr<const ConfigNode> m_readOnlyNode;