progress on relation completer
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
#include "matador/object/schema_node.hpp"
|
||||
|
||||
namespace matador::object {
|
||||
relation_endpoint::relation_endpoint(std::string field_name, relation_type type, const std::shared_ptr<schema_node> &node)
|
||||
relation_endpoint::relation_endpoint(std::string field_name, const relation_type type, const std::shared_ptr<schema_node> &node)
|
||||
: field_name_(std::move(field_name))
|
||||
, type_(type)
|
||||
, node_(node) {
|
||||
|
||||
@@ -40,11 +40,11 @@ std::string schema::name() const {
|
||||
utils::result<std::shared_ptr<attribute_definition>, utils::error> schema::reference(const std::type_index &type_index) const {
|
||||
const auto result = find_node(type_index);
|
||||
if (result) {
|
||||
return utils::ok((*result)->basic_info().reference_column());
|
||||
return utils::ok((*result)->info().reference_column());
|
||||
}
|
||||
|
||||
if (const auto it = expected_node_map_.find(type_index); it != expected_node_map_.end()) {
|
||||
return utils::ok(it->second->basic_info().reference_column());
|
||||
return utils::ok(it->second->info().reference_column());
|
||||
}
|
||||
|
||||
return utils::failure(result.err());
|
||||
@@ -69,8 +69,8 @@ utils::result<std::shared_ptr<schema_node>, utils::error> schema::attach_node(co
|
||||
push_back_child(parent_node, node);
|
||||
|
||||
// Todo: check return value
|
||||
node_map_.insert({node->name(), node})/*.first*/;
|
||||
type_index_node_map_.insert({node->type_index(), node});
|
||||
nodes_by_name_.insert({node->name(), node})/*.first*/;
|
||||
nodes_by_type_.insert({node->type_index(), node});
|
||||
|
||||
return utils::ok(node);
|
||||
}
|
||||
@@ -88,24 +88,24 @@ utils::result<std::shared_ptr<schema_node>, utils::error> schema::attach_node(co
|
||||
push_back_child(*result, node);
|
||||
|
||||
// Todo: check return value
|
||||
node_map_.insert({node->name(), node})/*.first*/;
|
||||
type_index_node_map_.insert({node->type_index(), node});
|
||||
nodes_by_name_.insert({node->name(), node})/*.first*/;
|
||||
nodes_by_type_.insert({node->type_index(), node});
|
||||
|
||||
return utils::ok(node);
|
||||
}
|
||||
|
||||
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()) {
|
||||
const auto i = nodes_by_name_.find(name);
|
||||
if (i == nodes_by_name_.end()) {
|
||||
return utils::failure(make_error(error_code::NodeNotFound, "Couldn't find node by name '" + name + "'"));
|
||||
}
|
||||
return utils::ok(i->second);
|
||||
}
|
||||
|
||||
utils::result<std::shared_ptr<schema_node>, utils::error> schema::find_node(const std::type_index &type_index) const {
|
||||
const auto i = type_index_node_map_.find(type_index);
|
||||
if (i == type_index_node_map_.end()) {
|
||||
const auto i = nodes_by_type_.find(type_index);
|
||||
if (i == nodes_by_type_.end()) {
|
||||
return utils::failure(make_error(error_code::NodeNotFound,
|
||||
"Couldn't find node by type '" + std::string(type_index.name()) + "'"));
|
||||
}
|
||||
@@ -129,14 +129,14 @@ void schema::push_back_child(const node_ptr &parent, const node_ptr &child) {
|
||||
}
|
||||
|
||||
bool schema::has_node(const std::string &name) const {
|
||||
return node_map_.count(name) > 0;
|
||||
return nodes_by_name_.count(name) > 0;
|
||||
}
|
||||
|
||||
bool schema::has_node(const std::type_index &index) const {
|
||||
return type_index_node_map_.count(index) > 0;
|
||||
return nodes_by_type_.count(index) > 0;
|
||||
}
|
||||
|
||||
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;
|
||||
return nodes_by_name_.count(name) > 0 || nodes_by_type_.count(index) > 0;
|
||||
}
|
||||
} // namespace matador::object
|
||||
|
||||
@@ -31,7 +31,7 @@ std::type_index schema_node::type_index() const {
|
||||
return info_->type_index();
|
||||
}
|
||||
|
||||
const basic_object_info &schema_node::basic_info() const {
|
||||
const basic_object_info &schema_node::info() const {
|
||||
return *info_;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user