added date_type_t, time_type_t and timestamp, ensure allocated postgres resources are released, split repository into basic_repository and repository.
This commit is contained in:
@@ -1,34 +1,28 @@
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#include "matador/object/repository.hpp"
|
||||
#include "matador/object/basic_repository.hpp"
|
||||
#include "matador/object/repository_node.hpp"
|
||||
|
||||
namespace matador::object {
|
||||
repository_node::repository_node(repository &repo)
|
||||
repository_node::repository_node(basic_repository &repo)
|
||||
: repo_(repo)
|
||||
, type_index_(typeid(detail::null_type)){
|
||||
}
|
||||
|
||||
repository_node::repository_node(repository &repo, const std::type_index& ti)
|
||||
repository_node::repository_node(basic_repository &repo, const std::type_index& ti)
|
||||
: repo_(repo)
|
||||
, type_index_(ti) {
|
||||
}
|
||||
|
||||
repository_node::repository_node(repository &repo, std::string name, const std::type_index& ti)
|
||||
repository_node::repository_node(basic_repository &repo, std::string name, const std::type_index& ti)
|
||||
: repo_(repo)
|
||||
, type_index_(ti)
|
||||
, first_child_(std::shared_ptr<repository_node>(new repository_node(repo)))
|
||||
, last_child_(std::shared_ptr<repository_node>(new repository_node(repo)))
|
||||
, first_child_(std::make_unique<repository_node>(repo))
|
||||
, last_child_(std::make_unique<repository_node>(repo))
|
||||
, name_(std::move(name)) {
|
||||
first_child_->next_sibling_ = last_child_;
|
||||
last_child_->previous_sibling_ = first_child_;
|
||||
}
|
||||
|
||||
std::shared_ptr<repository_node> repository_node::make_null_node(repository &repo) {
|
||||
auto node = std::shared_ptr<repository_node>(new repository_node(repo));
|
||||
node->info_ = std::make_unique<null_info>(node);
|
||||
|
||||
return node;
|
||||
first_child_->next_sibling_ = last_child_.get();
|
||||
last_child_->previous_sibling_ = first_child_.get();
|
||||
}
|
||||
|
||||
std::string repository_node::name() const {
|
||||
@@ -48,32 +42,35 @@ void repository_node::update_name(const std::string& name) {
|
||||
info_->update_name(name);
|
||||
}
|
||||
|
||||
const repository& repository_node::schema() const {
|
||||
const basic_repository& repository_node::schema() const {
|
||||
return repo_;
|
||||
}
|
||||
|
||||
bool repository_node::has_children() const {
|
||||
return first_child_->next_sibling_ != last_child_;
|
||||
return first_child_->next_sibling_ != last_child_.get();
|
||||
}
|
||||
void repository_node::on_attach() const {
|
||||
info_->on_attach();
|
||||
}
|
||||
|
||||
void repository_node::on_detach() const {}
|
||||
void repository_node::on_detach() const {
|
||||
info_->on_detach();
|
||||
}
|
||||
|
||||
repository_node::node_ptr repository_node::next() const {
|
||||
// if we have a child, child is the next iterator to return
|
||||
// (if we don't iterate over the siblings)
|
||||
if (first_child_ && first_child_->next_sibling_ != last_child_) {
|
||||
if (first_child_ && first_child_->next_sibling_ != last_child_.get()) {
|
||||
return first_child_->next_sibling_;
|
||||
}
|
||||
// if there is no child, we check for sibling
|
||||
// if there is a sibling, this is our next iterator to return
|
||||
// if not, we go back to the parent
|
||||
auto *node = this;
|
||||
while (node->parent_ && node->next_sibling_ == node->parent_->last_child_) {
|
||||
node = node->parent_.get();
|
||||
while (node->parent_ && node->next_sibling_ == node->parent_->last_child_.get()) {
|
||||
node = node->parent_;
|
||||
}
|
||||
return node->parent_ ? node->next_sibling_ : node->last_child_;
|
||||
return node->parent_ ? node->next_sibling_ : node->last_child_.get();
|
||||
}
|
||||
|
||||
repository_node::node_ptr repository_node::prev() const {
|
||||
@@ -83,7 +80,7 @@ repository_node::node_ptr repository_node::prev() const {
|
||||
// child as our iterator
|
||||
if (previous_sibling_ && previous_sibling_->previous_sibling_) {
|
||||
auto node = previous_sibling_;
|
||||
while (node->last_child_ && node->first_child_->next_sibling_ != node->last_child_) {
|
||||
while (node->last_child_ && node->first_child_->next_sibling_ != node->last_child_.get()) {
|
||||
node = node->last_child_->previous_sibling_;
|
||||
}
|
||||
return node;
|
||||
@@ -96,7 +93,7 @@ repository_node::node_ptr repository_node::prev() const {
|
||||
void repository_node::unlink() {
|
||||
previous_sibling_->next_sibling_ = next_sibling_;
|
||||
next_sibling_->previous_sibling_ = previous_sibling_;
|
||||
next_sibling_.reset();
|
||||
previous_sibling_.reset();
|
||||
next_sibling_ = nullptr;
|
||||
previous_sibling_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user