summaryrefslogtreecommitdiff
path: root/src/syncevo/SingleFileConfigTree.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/syncevo/SingleFileConfigTree.h')
-rw-r--r--src/syncevo/SingleFileConfigTree.h94
1 files changed, 94 insertions, 0 deletions
diff --git a/src/syncevo/SingleFileConfigTree.h b/src/syncevo/SingleFileConfigTree.h
new file mode 100644
index 00000000..7e1581a7
--- /dev/null
+++ b/src/syncevo/SingleFileConfigTree.h
@@ -0,0 +1,94 @@
+/*
+ * 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(""));
+ 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