801f831531
This is necessary for local sync, which has to add per-peer file config nodes in a location which is outside of the non-peer context accessed by the ConfigTree. Adding these instances is necessary for two reasons: - ConfigTree::flush() must also flush these additional nodes. - Temporary settings made for sources are only found if the corresponding nodes can be found via the ConfigTree.
96 lines
3 KiB
C++
96 lines
3 KiB
C++
/*
|
|
* Copyright (C) 2008-2009 Patrick Ohly <patrick.ohly@gmx.de>
|
|
*
|
|
* 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
|
|
*/
|
|
|
|
#ifndef INCL_EVOLUTION_SINGLE_FILE_CONFIG_TREE
|
|
# define INCL_EVOLUTION_SINGLE_FILE_CONFIG_TREE
|
|
|
|
#include <ConfigTree.h>
|
|
#include <DataBlob.h>
|
|
#include <util.h>
|
|
|
|
#include <string>
|
|
#include <map>
|
|
|
|
#include <syncevo/declarations.h>
|
|
SE_BEGIN_CXX
|
|
|
|
/**
|
|
* This class handles data blobs which contain multiple .ini files, using
|
|
* the following format:
|
|
* @verbatim
|
|
# comment
|
|
# ...
|
|
=== <first path>/[.internal.ini|config.ini|template.ini|...] ===
|
|
<file content>
|
|
=== <second file name> ===
|
|
...
|
|
* @endverbatim
|
|
*
|
|
* This is based on the assumption that the === ... === file separator
|
|
* is not part of valid .ini file content.
|
|
*
|
|
* Right now, only reading such a single data blob is implemented.
|
|
*/
|
|
class SingleFileConfigTree : public ConfigTree {
|
|
public:
|
|
/**
|
|
* @param data access to complete file data
|
|
*/
|
|
SingleFileConfigTree(const boost::shared_ptr<DataBlob> &data);
|
|
SingleFileConfigTree(const std::string &fullpath);
|
|
|
|
/**
|
|
* same as open(), with full file name (like sources/addressbook/config.ini)
|
|
* instead of path + type
|
|
*/
|
|
boost::shared_ptr<ConfigNode> open(const std::string &filename);
|
|
|
|
/* ConfigTree API */
|
|
virtual string getRootPath() const { return m_data->getName(); }
|
|
virtual void flush();
|
|
virtual void remove(const std::string &path);
|
|
virtual void reset();
|
|
virtual boost::shared_ptr<ConfigNode> open(const std::string &path,
|
|
PropertyType type,
|
|
const std::string &otherId = std::string(""));
|
|
virtual boost::shared_ptr<ConfigNode> add(const string &path,
|
|
const boost::shared_ptr<ConfigNode> &bode);
|
|
list<string> getChildren(const std::string &path);
|
|
|
|
private:
|
|
boost::shared_ptr<DataBlob> m_data;
|
|
|
|
/**
|
|
* maps from normalized file name (see normalizePath()) to content for that name
|
|
*/
|
|
typedef std::map<std::string, boost::shared_ptr<std::string> > FileContent_t;
|
|
FileContent_t m_content;
|
|
|
|
/** cache of all nodes ever accessed */
|
|
typedef map< string, boost::shared_ptr<ConfigNode> > NodeCache_t;
|
|
NodeCache_t m_nodes;
|
|
|
|
/**
|
|
* populate m_content from m_data
|
|
*/
|
|
void readFile();
|
|
};
|
|
|
|
SE_END_CXX
|
|
#endif
|