|
|
|
@@ -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
|
|
|
|
|