64 lines
1.9 KiB
C++
64 lines
1.9 KiB
C++
#ifndef SCHEMA_HPP
|
|
#define SCHEMA_HPP
|
|
|
|
#include "matador/object/error_code.hpp"
|
|
#include "matador/object/schema_node.hpp"
|
|
|
|
#include "matador/utils/result.hpp"
|
|
#include "matador/utils/error.hpp"
|
|
|
|
#include <memory>
|
|
#include <string>
|
|
#include <unordered_map>
|
|
|
|
namespace matador::object {
|
|
|
|
class schema {
|
|
public:
|
|
schema();
|
|
|
|
template <typename Type>
|
|
utils::result<void, utils::error> attach(const std::string name, const std::string &parent = "") {
|
|
auto node = schema_node::make_node<Type>(*this, name);
|
|
|
|
attach_node(node, parent);
|
|
return utils::ok<void>();
|
|
}
|
|
|
|
template <typename Type, typename ParentType>
|
|
utils::result<void, utils::error> attach(const std::string name) {
|
|
// auto node = std::make_unique<schema_node>(*this);
|
|
|
|
return utils::ok<void>();
|
|
}
|
|
|
|
[[nodiscard]] bool empty() const;
|
|
|
|
[[nodiscard]] size_t size() const;
|
|
|
|
private:
|
|
using t_node_map = std::unordered_map<std::string, std::shared_ptr<schema_node>>;
|
|
// type_index -> [name -> prototype]
|
|
using t_type_index_node_map = std::unordered_map<std::type_index, t_node_map>;
|
|
using node_ptr = std::shared_ptr<schema_node>;
|
|
|
|
utils::result<std::shared_ptr<schema_node>, utils::error> attach_node(const std::shared_ptr<schema_node> &node,
|
|
const std::string &parent);
|
|
utils::result<std::shared_ptr<schema_node>, utils::error> find_parent(const std::string &name) const;
|
|
utils::result<std::shared_ptr<schema_node>, utils::error> find_node(const std::string &name) const;
|
|
|
|
utils::result<std::shared_ptr<schema_node>, utils::error> push_back_child(const node_ptr &parent, const node_ptr &child);
|
|
|
|
bool has_node(const std::type_index& index, const std::string &name) const;
|
|
|
|
private:
|
|
std::shared_ptr<schema_node> root_;
|
|
|
|
t_node_map node_map_;
|
|
t_type_index_node_map type_index_node_map_;
|
|
};
|
|
|
|
}
|
|
|
|
#endif //SCHEMA_HPP
|