initial matador ng commit

This commit is contained in:
2025-02-02 20:37:12 +01:00
parent 19de5714f4
commit ded3daceb3
378 changed files with 14913 additions and 13431 deletions
+13
View File
@@ -0,0 +1,13 @@
#include "matador/object/basic_object_info.hpp"
#include <algorithm>
namespace matador::object {
basic_object_info::basic_object_info(schema_node &node, const std::type_index type_index)
: node_(node)
, type_index_(type_index) {}
std::type_index basic_object_info::type_index() const { return type_index_; }
} // namespace matador::object
+37
View File
@@ -0,0 +1,37 @@
#include "matador/object/error_code.hpp"
namespace matador::object {
const char * object_category_impl::name() const noexcept {
return "sql";
}
std::string object_category_impl::message(const int ev) const {
switch (static_cast<error_code>(ev)) {
case error_code::OK:
return "OK";
case error_code::NodeNotFound:
return "Node not found";
case error_code::NodeAlreadyExists:
return "Node already exists";
case error_code::Failure:
return "Failure";
default:
return "Unknown error";
}
}
const std::error_category & object_category() {
static object_category_impl instance;
return instance;
}
std::error_code make_error_code(error_code e) {
return {static_cast<int>(e), object_category()};
}
std::error_condition make_error_condition(error_code e) {
return {static_cast<int>(e), object_category()};
}
}
+98
View File
@@ -0,0 +1,98 @@
#include "matador/object/schema.hpp"
namespace matador::object {
utils::error make_error(const error_code ec, const std::string& msg) {
return utils::error(ec, msg);
}
schema::schema()
: root_(std::shared_ptr<schema_node>(new schema_node(*this))) {
root_->first_child_ = std::shared_ptr<schema_node>(new schema_node(*this));
root_->last_child_ = std::shared_ptr<schema_node>(new schema_node(*this));
root_->first_child_->next_sibling_ = root_->last_child_;
root_->last_child_->previous_sibling_ = root_->first_child_;
}
bool schema::empty() const {
return root_->first_child_ == root_->last_child_->previous_sibling_;
}
size_t schema::size() const { return 0; }
utils::result<std::shared_ptr<schema_node>, utils::error> schema::attach_node(const std::shared_ptr<schema_node> &node,
const std::string &parent) {
if (!has_node(node->type_index(), node->name())) {
return utils::failure(make_error(error_code::NodeAlreadyExists, "Node '" + node->name() + "' already exists."));
}
// set node to root node
auto parent_node = root_;
auto result = find_parent(parent);
if (!result.is_ok() && result.err().ec() != error_code::NodeNotFound) {
return result;
}
parent_node = *result;
result = push_back_child(root_, node);
// if (!pk.is_null()) {
// node->primary_key_ = pk;
// }
// store prototype in map
// Todo: check return value
node_map_.insert(std::make_pair(node->name(), node))/*.first*/;
type_index_node_map_[node->type_index()].insert(std::make_pair(node->name(), node));
// return nptr.release();
return {};
}
utils::result<std::shared_ptr<schema_node>, utils::error> schema::find_parent(const std::string &name) const {
if (name.empty()) {
return utils::failure(make_error(error_code::Failure, "Name of parent cannot be empty"));
}
return find_node(name);
}
utils::result<std::shared_ptr<schema_node>, utils::error> schema::find_node(const std::string &name) const {
// first search in the prototype map
const auto i = node_map_.find(name);
if (i == node_map_.end()) {
// if not found search in the typeid to prototype map
// const auto j = type_index_node_map_.find(name);
// if (j == type_index_node_map_.end()) {
// return utils::failure(
// make_error(error_code::NodeNotFound, std::string("Could not find node with name '") + name + "'"));
// }
// const t_node_map &val = j->second;
/*
* if size is greater one (1) the name
* is a typeid and has more than one prototype
* node and therefor it is not unique and an
* exception is thrown
*/
// if (val.size() > 1) {
// return utils::failure(make_error(error_code::NodeNotFound, std::string("Type id '") + name + "' is not unique"));
// }
// // return the only prototype
// return utils::ok(val.begin()->second);
}
return utils::ok(i->second);
}
utils::result<std::shared_ptr<schema_node>, utils::error> schema::push_back_child(const node_ptr &parent, const node_ptr &child) {
child->parent_ = parent;
child->previous_sibling_ = parent->last_child_->previous_sibling_;
child->next_sibling_ = parent->last_child_;
parent->last_child_->previous_sibling_->next_sibling_ = child;
parent->last_child_->previous_sibling_ = child;
// set depth
// child->depth = depth + 1;
}
bool schema::has_node(const std::type_index &index, const std::string &name) const {
return node_map_.count(name) > 0 || type_index_node_map_.count(index) > 0;
}
} // namespace matador::object
+60
View File
@@ -0,0 +1,60 @@
#include <utility>
#include "matador/object/schema_node.hpp"
namespace matador::object {
schema_node::schema_node(schema &tree)
: schema_(tree)
, info_(std::make_unique<null_info>(*this))
{}
std::string schema_node::name() const {
return name_;
}
std::type_index schema_node::type_index() const {
return info_->type_index();
}
void schema_node::append(const std::shared_ptr<schema_node> &sibling) {
sibling->parent_ = parent_;
// sibling->previous_sibling_ = this;
// sibling->next_sibling_ = next_sibling_;
// next_sibling_ = sibling;
// sibling->next_sibling_->previous_sibling_ = sibling;
// sibling->depth = depth;
// if (!parent_) {
// sibling->op_first = new object_proxy();
// sibling->op_last = sibling->op_marker = new object_proxy();
// sibling->op_first->link(sibling->op_last);
// } else {
// throw object_exception("failed to add node as sibling: node has no parent");
// }
}
void schema_node::insert(const std::shared_ptr<schema_node> &child) {
// child->parent_ = this;
// child->previous_sibling_ = last_child_->previous_sibling_;
// child->next_sibling_ = last_child_;
// last_child_->previous_sibling_->next_sibling_ = child;
// last_child_->previous_sibling_ = child;
// set depth
// child->depth = depth + 1;
// set object proxy pointer
// 1. first
// if (op_first->next() == op_last) {
// // node hasn't any serializable (proxy)
// child->op_first = op_first;
// } else {
// // node has some objects (proxy)
// child->op_first = op_last->prev();
// }
// // 2. marker
// child->op_marker = op_last;
// // 3. last
// child->op_last = op_last;
}
}