2008-03-06 23:23:13 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2008 Patrick Ohly
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef INCL_EVOLUTION_FILTER_CONFIG_NODE
|
|
|
|
# define INCL_EVOLUTION_FILTER_CONFIG_NODE
|
|
|
|
|
|
|
|
#include <ConfigNode.h>
|
|
|
|
#include <boost/shared_ptr.hpp>
|
2008-03-30 15:41:56 +02:00
|
|
|
#include <boost/algorithm/string/case_conv.hpp>
|
2008-07-06 22:49:19 +02:00
|
|
|
#include <boost/algorithm/string.hpp>
|
2008-03-06 23:23:13 +01:00
|
|
|
|
2008-03-30 11:02:07 +02:00
|
|
|
#include "SyncEvolutionUtil.h"
|
|
|
|
|
2008-03-06 23:23:13 +01:00
|
|
|
#include <map>
|
|
|
|
#include <utility>
|
2008-03-30 11:02:07 +02:00
|
|
|
#include <vector>
|
2008-03-06 23:23:13 +01:00
|
|
|
#include <string>
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class acts as filter between a real config node and its user:
|
|
|
|
* reads which match properties which are set in the filter will
|
|
|
|
* return the value set in the filter. Writes will go to the underlying
|
|
|
|
* node and future reads will return the written value.
|
|
|
|
*
|
|
|
|
* The purpose of this class is temporarily overriding saved values
|
|
|
|
* during one run without having to modify the saved values.
|
|
|
|
*/
|
|
|
|
class FilterConfigNode : public ConfigNode {
|
|
|
|
public:
|
2008-07-06 22:26:23 +02:00
|
|
|
/** a case-insensitive string to string mapping */
|
|
|
|
class ConfigFilter : public map<string, string, Nocase<string> > {
|
2008-03-18 22:45:34 +01:00
|
|
|
public:
|
2008-07-06 22:26:23 +02:00
|
|
|
/** format as <key> = <value> lines */
|
2008-07-11 22:25:02 +02:00
|
|
|
operator string () const;
|
2008-03-18 22:45:34 +01:00
|
|
|
};
|
2008-03-06 23:23:13 +01:00
|
|
|
|
2008-03-20 22:59:59 +01:00
|
|
|
/** read-write access to underlying node */
|
2008-03-06 23:23:13 +01:00
|
|
|
FilterConfigNode(const boost::shared_ptr<ConfigNode> &node,
|
2008-03-20 22:59:59 +01:00
|
|
|
const ConfigFilter &filter = ConfigFilter());
|
2008-03-06 23:23:13 +01:00
|
|
|
|
2008-03-20 22:59:59 +01:00
|
|
|
/** read-only access to underlying node */
|
|
|
|
FilterConfigNode(const boost::shared_ptr<const ConfigNode> &node,
|
|
|
|
const ConfigFilter &filter = ConfigFilter());
|
|
|
|
|
|
|
|
virtual string getName() const { return m_readOnlyNode->getName(); }
|
2008-03-19 12:29:14 +01:00
|
|
|
|
2008-03-06 23:23:13 +01:00
|
|
|
/** add another entry to the list of filter properties */
|
|
|
|
void addFilter(const string &property,
|
|
|
|
const string &value);
|
|
|
|
|
|
|
|
/** replace current filter list with new one */
|
2008-03-18 22:45:34 +01:00
|
|
|
void setFilter(const ConfigFilter &filter);
|
2008-03-30 11:02:07 +02:00
|
|
|
const ConfigFilter &getFilter() const { return m_filter; }
|
2008-03-06 23:23:13 +01:00
|
|
|
|
|
|
|
/* ConfigNode API */
|
2008-03-20 22:59:59 +01:00
|
|
|
virtual void flush();
|
2008-03-06 23:23:13 +01:00
|
|
|
virtual string readProperty(const string &property) const;
|
|
|
|
virtual void setProperty(const string &property,
|
|
|
|
const string &value,
|
2008-03-30 23:50:51 +02:00
|
|
|
const string &comment = "",
|
|
|
|
const string *defValue = NULL);
|
2008-04-10 21:54:02 +02:00
|
|
|
virtual void readProperties(map<string, string> &props) const;
|
2008-03-06 23:23:13 +01:00
|
|
|
virtual void removeProperty(const string &property);
|
2008-03-24 22:42:47 +01:00
|
|
|
virtual bool exists() const { return m_readOnlyNode->exists(); }
|
2008-03-06 23:23:13 +01:00
|
|
|
|
|
|
|
private:
|
2008-03-18 22:45:34 +01:00
|
|
|
ConfigFilter m_filter;
|
2008-03-06 23:23:13 +01:00
|
|
|
boost::shared_ptr<ConfigNode> m_node;
|
2008-03-20 22:59:59 +01:00
|
|
|
boost::shared_ptr<const ConfigNode> m_readOnlyNode;
|
2008-03-06 23:23:13 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|