attaching schema nodes progress
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
#include "matador/object/foreign_node_completer.hpp"
|
||||
|
||||
#include "matador/object/schema.hpp"
|
||||
|
||||
#include "matador/logger/logger.hpp"
|
||||
|
||||
namespace matador::object {
|
||||
foreign_node_completer::foreign_node_completer(internal::shadow_schema &shadow)
|
||||
: schema_(shadow)
|
||||
, log_(logger::create_logger("node_completer")) {}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
#include "matador/object/internal/shadow_schema.hpp"
|
||||
|
||||
#include "matador/object/schema.hpp"
|
||||
#include "matador/object/schema_node.hpp"
|
||||
|
||||
namespace matador::object::internal {
|
||||
shadow_schema::shadow_schema( object::schema& s )
|
||||
: schema_(s) {}
|
||||
|
||||
schema& shadow_schema::schema() const {
|
||||
return schema_;
|
||||
}
|
||||
|
||||
bool shadow_schema::schema_contains( const std::type_index& ti ) const {
|
||||
return schema_.contains(ti);
|
||||
}
|
||||
|
||||
utils::result<shadow_schema::node_ptr, utils::error> shadow_schema::find_node( const std::type_index& type_index ) const {
|
||||
return schema_.find_node(type_index);
|
||||
}
|
||||
|
||||
utils::result<shadow_schema::node_ptr, utils::error> shadow_schema::attach_node( const std::shared_ptr<schema_node>& node ) const {
|
||||
return schema_.attach_node(node, "");
|
||||
}
|
||||
|
||||
utils::result<void, utils::error> shadow_schema::detach_node( const std::shared_ptr<schema_node>& node ) const {
|
||||
return schema_.detach(node);
|
||||
}
|
||||
}
|
||||
@@ -25,25 +25,6 @@ utils::result<void, utils::error> schema::detach(const node_ptr &node) {
|
||||
return utils::ok<void>();
|
||||
}
|
||||
|
||||
// utils::result<void, utils::error> schema::detach(const std::string& name) {
|
||||
// const auto nit = nodes_by_name_.find(name);
|
||||
// if (nit == nodes_by_name_.end()) {
|
||||
// return utils::failure(make_error(error_code::NodeNotFound, "Node '" + name + "' not found."));
|
||||
// }
|
||||
//
|
||||
// const auto ti = nit->second->type_index();
|
||||
// nodes_by_name_.erase(nit);
|
||||
//
|
||||
// const auto it = nodes_by_type_.find(ti);
|
||||
// if (it == nodes_by_type_.end()) {
|
||||
// return utils::failure(make_error(error_code::NodeNotFound, "Node '" + name + "' not found."));
|
||||
// }
|
||||
//
|
||||
// nodes_by_type_.erase(it);
|
||||
//
|
||||
// return utils::ok<void>();
|
||||
// }
|
||||
|
||||
schema::const_iterator schema::begin() const {
|
||||
return const_iterator(root_->first_child_->next_sibling_);
|
||||
}
|
||||
@@ -64,6 +45,14 @@ std::string schema::name() const {
|
||||
return name_;
|
||||
}
|
||||
|
||||
bool schema::contains( const std::string& name ) const {
|
||||
return nodes_by_name_.count(name) > 0;
|
||||
}
|
||||
|
||||
bool schema::contains( const std::type_index& index ) const {
|
||||
return nodes_by_type_.count(index) > 0;
|
||||
}
|
||||
|
||||
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) {
|
||||
@@ -93,7 +82,7 @@ utils::result<schema::node_ptr, utils::error> schema::attach_node(const std::sha
|
||||
return utils::failure(make_error(error_code::NodeAlreadyExists, "Node '" + node->name() + "' already exists."));
|
||||
}
|
||||
|
||||
log_.info("attach node '%s' (type: %s)", node->name().c_str(), node->type_index().name());
|
||||
log_.info("attach: insert node '%s' (type: %s)", node->name().c_str(), node->type_index().name());
|
||||
|
||||
// set node to root node
|
||||
auto parent_node = root_;
|
||||
@@ -114,24 +103,24 @@ utils::result<schema::node_ptr, utils::error> schema::attach_node(const std::sha
|
||||
return utils::ok(node);
|
||||
}
|
||||
|
||||
utils::result<schema::node_ptr, utils::error> schema::attach_node(const std::shared_ptr<schema_node> &node,
|
||||
const std::type_index &type_index) {
|
||||
if (has_node(node)) {
|
||||
return utils::failure(make_error(error_code::NodeAlreadyExists, "Node '" + node->name() + "' already exists."));
|
||||
}
|
||||
auto result = find_node(type_index);
|
||||
if (!result.is_ok() && result.err().ec() != error_code::NodeNotFound) {
|
||||
return result;
|
||||
}
|
||||
|
||||
insert_node(*result, node);
|
||||
|
||||
// Todo: check return value
|
||||
nodes_by_name_.insert({node->name(), node})/*.first*/;
|
||||
nodes_by_type_.insert({node->type_index(), node});
|
||||
|
||||
return utils::ok(node);
|
||||
}
|
||||
// utils::result<schema::node_ptr, utils::error> schema::attach_node(const std::shared_ptr<schema_node> &node,
|
||||
// const std::type_index &type_index) {
|
||||
// if (has_node(node)) {
|
||||
// return utils::failure(make_error(error_code::NodeAlreadyExists, "Node '" + node->name() + "' already exists."));
|
||||
// }
|
||||
// auto result = find_node(type_index);
|
||||
// if (!result.is_ok() && result.err().ec() != error_code::NodeNotFound) {
|
||||
// return result;
|
||||
// }
|
||||
//
|
||||
// insert_node(*result, node);
|
||||
//
|
||||
// // Todo: check return value
|
||||
// nodes_by_name_.insert({node->name(), node})/*.first*/;
|
||||
// nodes_by_type_.insert({node->type_index(), node});
|
||||
//
|
||||
// return utils::ok(node);
|
||||
// }
|
||||
|
||||
utils::result<schema::node_ptr, utils::error> schema::find_node(const std::string &name) const {
|
||||
// first search in the prototype map
|
||||
|
||||
Reference in New Issue
Block a user