add list parsing
Change-Id: Id4be03cedd687892b6f4ae45d90afee8e2a4a43c
diff --git a/src/CTree.hpp b/src/CTree.hpp
index fa99df6..3e95066 100644
--- a/src/CTree.hpp
+++ b/src/CTree.hpp
@@ -8,20 +8,22 @@
#pragma once
+#include <boost/variant.hpp>
+#include <set>
#include <stdexcept>
#include <unordered_map>
-enum NODE_TYPE {
- TYPE_CONTAINER,
- TYPE_LIST,
- TYPE_LIST_ELEMENT
-};
+namespace schema {
+ struct container {
+ };
+ struct list {
+ std::set<std::string> m_keys;
+ };
+}
-struct TreeNode {
- bool operator<(const TreeNode& b) const;
- std::string m_name;
- NODE_TYPE m_type;
-};
+
+using NodeType = boost::variant<schema::container, schema::list>;
+
class InvalidNodeException : public std::invalid_argument {
public:
@@ -38,16 +40,20 @@
class CTree {
public:
CTree();
- bool nodeExists(const std::string& location, const std::string& node) const;
+ bool nodeExists(const std::string& location, const std::string& name) const;
- bool isContainer(const std::string& location, const std::string& node) const;
- void addContainer(const std::string& location, const std::string& node);
- void changeNode(const std::string& node);
+ bool isContainer(const std::string& location, const std::string& name) const;
+ void addContainer(const std::string& location, const std::string& name);
+ const std::set<std::string>& listKeys(const std::string& location, const std::string& name) const;
+ bool listHasKey(const std::string& location, const std::string& name, const std::string& key) const;
+ bool isList(const std::string& location, const std::string& name) const;
+ void addList(const std::string& location, const std::string& name, const std::set<std::string>& keys);
+ void changeNode(const std::string& name);
std::string currentNode() const;
private:
- const std::unordered_map<std::string, NODE_TYPE>& children(const std::string& node) const;
+ const std::unordered_map<std::string, NodeType>& children(const std::string& name) const;
- std::unordered_map<std::string, std::unordered_map<std::string, NODE_TYPE>> m_nodes;
+ std::unordered_map<std::string, std::unordered_map<std::string, NodeType>> m_nodes;
std::string m_curDir;
};