object generation progress
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
|
||||
#include "matador/utils/identifier.hpp"
|
||||
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include <typeindex>
|
||||
|
||||
@@ -24,8 +25,7 @@ public:
|
||||
|
||||
[[nodiscard]] std::type_index type_index() const;
|
||||
[[nodiscard]] std::string name() const;
|
||||
[[nodiscard]] const std::vector<attribute>& attributes() const;
|
||||
// [[nodiscard]] std::shared_ptr<attribute> reference_column() const;
|
||||
[[nodiscard]] const std::list<attribute>& attributes() const;
|
||||
|
||||
[[nodiscard]] bool has_primary_key() const;
|
||||
[[nodiscard]] const utils::identifier& primary_key() const;
|
||||
@@ -50,8 +50,6 @@ public:
|
||||
[[nodiscard]] bool endpoints_empty() const;
|
||||
|
||||
protected:
|
||||
// basic_object_info(std::shared_ptr<repository_node> node, const std::vector<attribute> &attributes, utils::identifier &&pk, const std::shared_ptr<attribute> &pk_as_fk_column);
|
||||
// basic_object_info(std::shared_ptr<repository_node> node, const std::vector<attribute> &attributes);
|
||||
basic_object_info(std::shared_ptr<repository_node> node, std::unique_ptr<object> &&obj);
|
||||
|
||||
protected:
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
#include "matador/utils/field_attributes.hpp"
|
||||
#include "matador/utils/primary_key_attribute.hpp"
|
||||
|
||||
#include <list>
|
||||
#include <typeindex>
|
||||
#include <vector>
|
||||
|
||||
namespace matador::object {
|
||||
class object;
|
||||
@@ -17,20 +17,20 @@ class repository;
|
||||
|
||||
class constraints_generator final {
|
||||
private:
|
||||
constraints_generator(std::vector<class constraint> &constraints, const repository &repo, object &obj);
|
||||
constraints_generator(std::list<class constraint> &constraints, const repository &repo, object &obj);
|
||||
|
||||
public:
|
||||
constraints_generator() = delete;
|
||||
|
||||
template < typename Type >
|
||||
static std::vector<class constraint> generate(const repository &repo, object &obj) {
|
||||
static std::list<class constraint> generate(const repository &repo, object &obj) {
|
||||
Type t;
|
||||
return generate(t, repo, obj);
|
||||
}
|
||||
|
||||
template < typename Type >
|
||||
static std::vector<class constraint> generate(const Type& t, const repository &repo, object &obj) {
|
||||
std::vector<class constraint> constraints;
|
||||
static std::list<class constraint> generate(const Type& t, const repository &repo, object &obj) {
|
||||
std::list<class constraint> constraints;
|
||||
constraints_generator gen(constraints, repo, obj);
|
||||
access::process(gen, t);
|
||||
return constraints;
|
||||
@@ -66,10 +66,10 @@ private:
|
||||
void create_fk_constraint(const std::type_index& ti, const std::string& name) const;
|
||||
void create_unique_constraint(const std::string& name) const;
|
||||
|
||||
[[nodiscard]] std::vector<attribute>::iterator find_attribute_by_name(const std::string &name) const;
|
||||
[[nodiscard]] std::list<attribute>::iterator find_attribute_by_name(const std::string &name) const;
|
||||
|
||||
private:
|
||||
std::vector<class constraint> &constraints_;
|
||||
std::list<class constraint> &constraints_;
|
||||
const repository &repo_;
|
||||
object &obj_;
|
||||
};
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
|
||||
#include "matador/utils/identifier.hpp"
|
||||
|
||||
#include <list>
|
||||
|
||||
namespace matador::object {
|
||||
|
||||
class repository;
|
||||
@@ -16,22 +18,6 @@ class object {
|
||||
public:
|
||||
explicit object(std::string name, std::string alias = "");
|
||||
|
||||
// template<typename Type>
|
||||
// static std::unique_ptr<object> generate(const repository& repo, std::string name, std::string alias = "") {
|
||||
// auto obj = std::make_unique<object>(std::move(name), std::move(alias));
|
||||
// obj->attributes_ = std::move(attribute_generator::generate<Type>(repo, *obj));
|
||||
// obj->constraints_ = std::move(constraints_generator::generate<Type>(repo, *obj));
|
||||
// return obj;
|
||||
// }
|
||||
//
|
||||
// template<typename Type>
|
||||
// static std::unique_ptr<object> generate(const std::unique_ptr<Type>& ptr, const repository& repo, std::string name, std::string alias = "") {
|
||||
// auto obj = std::make_unique<object>(std::move(name), std::move(alias));
|
||||
// obj->attributes_ = std::move(attribute_generator::generate(*ptr, repo, *obj));
|
||||
// obj->constraints_ = std::move(constraints_generator::generate(*ptr, repo, *obj));
|
||||
// return obj;
|
||||
// }
|
||||
|
||||
static const attribute& create_attribute(std::string name, object& obj);
|
||||
|
||||
void add_attribute(attribute attr);
|
||||
@@ -48,11 +34,11 @@ public:
|
||||
|
||||
[[nodiscard]] bool has_attributes() const;
|
||||
[[nodiscard]] size_t attribute_count() const;
|
||||
[[nodiscard]] const std::vector<attribute>& attributes() const;
|
||||
[[nodiscard]] const std::list<attribute>& attributes() const;
|
||||
|
||||
[[nodiscard]] bool has_constraints() const;
|
||||
[[nodiscard]] size_t constraint_count() const;
|
||||
[[nodiscard]] const std::vector<class constraint>& constraints() const;
|
||||
[[nodiscard]] const std::list<class constraint>& constraints() const;
|
||||
|
||||
private:
|
||||
friend class constraints_generator;
|
||||
@@ -64,8 +50,8 @@ private:
|
||||
|
||||
attribute* pk_attribute_{nullptr};
|
||||
utils::identifier pk_identifier_;
|
||||
std::vector<attribute> attributes_;
|
||||
std::vector<class constraint> constraints_;
|
||||
std::list<attribute> attributes_;
|
||||
std::list<class constraint> constraints_;
|
||||
};
|
||||
}
|
||||
#endif //MATADOR_OBJECT_HPP
|
||||
@@ -86,12 +86,10 @@ public:
|
||||
static void on_has_one(const char * /*id*/, Pointer &/*x*/, const utils::foreign_attributes &/*attr*/) {}
|
||||
|
||||
template <class Pointer>
|
||||
void on_foreign_key(const char *id, Pointer &x) {
|
||||
void on_foreign_key(const char *id, Pointer &/*x*/) {
|
||||
const auto type = pk_type_determinator::determine<typename Pointer::value_type>();
|
||||
auto &ref = object_->attributes_.emplace_back(id, type, utils::constraints::ForeignKey, null_option_type::NOT_NULL);
|
||||
ref.owner_ = object_.get();
|
||||
|
||||
create_fk_constraint(typeid(typename Pointer::value_type), id);
|
||||
}
|
||||
template<class ContainerType>
|
||||
static void on_has_many(const char * /*id*/, ContainerType &, const char *, const utils::foreign_attributes &/*attr*/) {}
|
||||
@@ -112,7 +110,7 @@ private:
|
||||
void create_fk_constraint(const std::type_index& ti, const std::string& name) const;
|
||||
void create_unique_constraint(const std::string& name) const;
|
||||
|
||||
[[nodiscard]] std::vector<attribute>::iterator find_attribute_by_name(const std::string &name) const;
|
||||
[[nodiscard]] std::list<attribute>::iterator find_attribute_by_name(const std::string &name) const;
|
||||
|
||||
void prepare_primary_key(attribute &ref, utils::identifier &&pk) const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user