|
@ -8,34 +8,34 @@ namespace internal |
|
|
runtime_node_t::~runtime_node_t() noexcept |
|
|
runtime_node_t::~runtime_node_t() noexcept |
|
|
{ |
|
|
{ |
|
|
if (parent) { |
|
|
if (parent) { |
|
|
if (parent->left_child == this) { |
|
|
if (parent->left_child.raw() == this) { |
|
|
parent->left_child = nullptr; |
|
|
parent->left_child.clear(); |
|
|
} else if (parent->right_child == this) { |
|
|
} else if (parent->right_child.raw() == this) { |
|
|
parent->right_child = nullptr; |
|
|
parent->right_child.clear(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
if (left_child) { left_child->parent = nullptr; } |
|
|
if (left_child) { left_child->parent.clear(); } |
|
|
if (right_child) { right_child->parent = nullptr; } |
|
|
if (right_child) { right_child->parent.clear(); } |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
bool runtime_node_t::is_operation_node() const noexcept { return std::holds_alternative<eNodeOperation>(node_data); } |
|
|
bool runtime_node_t::is_operation_node() const noexcept { return node_data.get_ptr() == nullptr; } |
|
|
|
|
|
|
|
|
bool runtime_node_t::is_primitive_node() const noexcept { return !is_operation_node(); } |
|
|
bool runtime_node_t::is_primitive_node() const noexcept { return !is_operation_node(); } |
|
|
|
|
|
|
|
|
bool runtime_node_t::is_parent_null() const noexcept { return parent == nullptr; } |
|
|
bool runtime_node_t::is_parent_null() const noexcept { return parent; } |
|
|
|
|
|
|
|
|
bool runtime_node_t::is_left_child_null() const noexcept { return left_child == nullptr; } |
|
|
bool runtime_node_t::is_left_child_null() const noexcept { return left_child; } |
|
|
|
|
|
|
|
|
bool runtime_node_t::is_right_child_null() const noexcept { return right_child == nullptr; } |
|
|
bool runtime_node_t::is_right_child_null() const noexcept { return right_child; } |
|
|
|
|
|
|
|
|
bool runtime_node_t::set_parent(runtime_node_t* _parent) noexcept |
|
|
bool runtime_node_t::set_parent(pointer_wrapper<runtime_node_t> _parent) noexcept |
|
|
{ |
|
|
{ |
|
|
if (_parent == nullptr) return false; |
|
|
if (_parent) return false; |
|
|
|
|
|
|
|
|
if (_parent->is_left_child_null()) |
|
|
if (_parent->is_left_child_null()) |
|
|
_parent->left_child = this; |
|
|
_parent->left_child = make_pointer_wrapper(this); |
|
|
else if (_parent->is_right_child_null()) |
|
|
else if (_parent->is_right_child_null()) |
|
|
_parent->right_child = this; |
|
|
_parent->right_child = make_pointer_wrapper(this); |
|
|
else |
|
|
else |
|
|
return false; |
|
|
return false; |
|
|
|
|
|
|
|
@ -44,45 +44,45 @@ bool runtime_node_t::set_parent(runtime_node_t* _parent) noexcept |
|
|
|
|
|
|
|
|
bool runtime_node_t::remove_parent() |
|
|
bool runtime_node_t::remove_parent() |
|
|
{ |
|
|
{ |
|
|
if (parent == nullptr) return false; |
|
|
if (parent) return false; |
|
|
|
|
|
|
|
|
if (parent->left_child == this) { |
|
|
if (parent->left_child.raw() == this) { |
|
|
parent->left_child = nullptr; |
|
|
parent->left_child.clear(); |
|
|
} else if (parent->right_child == this) { |
|
|
} else if (parent->right_child.raw() == this) { |
|
|
parent->right_child = nullptr; |
|
|
parent->right_child.clear(); |
|
|
} else { |
|
|
} else { |
|
|
throw std::logic_error("Illegal parent which does not have a child pointing to this."); |
|
|
throw std::logic_error("Illegal parent which does not have a child pointing to this."); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
parent = nullptr; |
|
|
parent.clear(); |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
bool runtime_node_t::set_left_child(runtime_node_t* child) noexcept |
|
|
bool runtime_node_t::set_left_child(pointer_wrapper<runtime_node_t> child) noexcept |
|
|
{ |
|
|
{ |
|
|
if (child == nullptr) return false; |
|
|
if (child) return false; |
|
|
|
|
|
|
|
|
if (!is_left_child_null() || !child->is_parent_null()) return false; |
|
|
if (!is_left_child_null() || !child->is_parent_null()) return false; |
|
|
|
|
|
|
|
|
left_child = child; |
|
|
left_child = child; |
|
|
child->parent = this; |
|
|
child->parent = make_pointer_wrapper(this); |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
bool runtime_node_t::set_right_child(runtime_node_t* child) noexcept |
|
|
bool runtime_node_t::set_right_child(pointer_wrapper<runtime_node_t> child) noexcept |
|
|
{ |
|
|
{ |
|
|
if (child == nullptr) return false; |
|
|
if (child) return false; |
|
|
|
|
|
|
|
|
if (!is_right_child_null() || !child->is_parent_null()) return false; |
|
|
if (!is_right_child_null() || !child->is_parent_null()) return false; |
|
|
|
|
|
|
|
|
right_child = child; |
|
|
right_child = child; |
|
|
child->parent = this; |
|
|
child->parent = make_pointer_wrapper(this); |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
bool runtime_node_t::add_child(runtime_node_t* child) noexcept |
|
|
bool runtime_node_t::add_child(pointer_wrapper<runtime_node_t> child) noexcept |
|
|
{ |
|
|
{ |
|
|
if (child == nullptr) return false; |
|
|
if (child) return false; |
|
|
|
|
|
|
|
|
if (!child->is_parent_null()) return false; |
|
|
if (!child->is_parent_null()) return false; |
|
|
|
|
|
|
|
@ -93,23 +93,23 @@ bool runtime_node_t::add_child(runtime_node_t* child) noexcept |
|
|
else |
|
|
else |
|
|
return false; |
|
|
return false; |
|
|
|
|
|
|
|
|
child->parent = this; |
|
|
child->parent = make_pointer_wrapper(this); |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
bool runtime_node_t::remove_child(runtime_node_t* child) |
|
|
bool runtime_node_t::remove_child(pointer_wrapper<runtime_node_t> child) |
|
|
{ |
|
|
{ |
|
|
if (child == nullptr) return false; |
|
|
if (child) return false; |
|
|
|
|
|
|
|
|
if (left_child == child) { |
|
|
if (left_child == child) { |
|
|
left_child = nullptr; |
|
|
left_child.clear(); |
|
|
} else if (right_child == child) { |
|
|
} else if (right_child == child) { |
|
|
right_child = nullptr; |
|
|
right_child.clear(); |
|
|
} else { |
|
|
} else { |
|
|
throw std::logic_error("Illegal child which does not have a parent pointing to this."); |
|
|
throw std::logic_error("Illegal child which does not have a parent pointing to this."); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
child->parent = nullptr; |
|
|
child->parent.clear(); |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|