2008-04-07 19:49:17 +02:00
|
|
|
/*
|
2009-03-25 15:21:04 +01:00
|
|
|
* Copyright (C) 2008-2009 Patrick Ohly <patrick.ohly@gmx.de>
|
2009-04-30 18:14:03 +02:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) version 3.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
|
|
* 02110-1301 USA
|
2008-04-07 19:49:17 +02:00
|
|
|
*/
|
|
|
|
|
2009-10-05 14:49:32 +02:00
|
|
|
#include <syncevo/SafeConfigNode.h>
|
|
|
|
#include <syncevo/SyncContext.h>
|
2008-04-07 19:49:17 +02:00
|
|
|
|
|
|
|
#include <boost/foreach.hpp>
|
|
|
|
|
2009-10-05 14:49:32 +02:00
|
|
|
#include <syncevo/declarations.h>
|
2009-10-02 17:23:53 +02:00
|
|
|
SE_BEGIN_CXX
|
|
|
|
|
2008-04-07 19:49:17 +02:00
|
|
|
SafeConfigNode::SafeConfigNode(const boost::shared_ptr<ConfigNode> &node) :
|
|
|
|
m_node(node),
|
2009-04-15 20:58:58 +02:00
|
|
|
m_readOnlyNode(node),
|
|
|
|
m_strictMode(true)
|
2008-04-07 19:49:17 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SafeConfigNode::SafeConfigNode(const boost::shared_ptr<const ConfigNode> &node) :
|
2009-04-15 20:58:58 +02:00
|
|
|
m_readOnlyNode(node),
|
|
|
|
m_strictMode(true)
|
2008-04-07 19:49:17 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
string SafeConfigNode::readProperty(const string &property) const
|
|
|
|
{
|
|
|
|
return unescape(m_readOnlyNode->readProperty(escape(property)));
|
|
|
|
}
|
|
|
|
|
|
|
|
void SafeConfigNode::setProperty(const string &property,
|
|
|
|
const string &value,
|
|
|
|
const string &comment,
|
|
|
|
const string *defValue)
|
|
|
|
{
|
|
|
|
m_node->setProperty(escape(property),
|
|
|
|
escape(value),
|
|
|
|
comment,
|
|
|
|
defValue);
|
|
|
|
}
|
|
|
|
|
2009-11-21 18:10:18 +01:00
|
|
|
void SafeConfigNode::readProperties(ConfigProps &props) const
|
2008-04-07 19:49:17 +02:00
|
|
|
{
|
2009-11-21 18:10:18 +01:00
|
|
|
ConfigProps original;
|
2008-04-10 21:54:02 +02:00
|
|
|
m_readOnlyNode->readProperties(original);
|
2008-04-07 19:49:17 +02:00
|
|
|
|
2008-07-11 22:25:02 +02:00
|
|
|
BOOST_FOREACH(const StringPair &prop, original) {
|
|
|
|
string key = unescape(prop.first);
|
|
|
|
string value = unescape(prop.second);
|
2008-04-07 19:49:17 +02:00
|
|
|
|
2008-07-06 22:36:29 +02:00
|
|
|
props[key] = value;
|
2008-04-07 19:49:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SafeConfigNode::removeProperty(const string &property)
|
|
|
|
{
|
|
|
|
m_node->removeProperty(escape(property));
|
|
|
|
}
|
|
|
|
|
|
|
|
void SafeConfigNode::flush()
|
|
|
|
{
|
|
|
|
if (!m_node.get()) {
|
2009-10-05 14:49:32 +02:00
|
|
|
SyncContext::throwError(getName() + ": read-only, flushing not allowed");
|
2008-04-07 19:49:17 +02:00
|
|
|
}
|
|
|
|
m_node->flush();
|
|
|
|
}
|
|
|
|
|
2009-10-02 17:23:53 +02:00
|
|
|
SE_END_CXX
|