query/include/matador/object/object_generator.hpp

67 lines
1.9 KiB
C++

#ifndef MATADOR_OBJECT_GENERATOR_HPP
#define MATADOR_OBJECT_GENERATOR_HPP
#include "matador/object/attribute.hpp"
#include "matador/object/attribute_generator.hpp"
#include "matador/object/constraint.hpp"
namespace matador::object {
class object_generator;
class object {
public:
explicit object(std::string name, std::string alias = "");
void add_attribute(attribute attr) {
auto &ref = attributes_.emplace_back(std::move(attr));
ref.owner_ = this;
}
static const attribute& create_attribute(std::string name, object& obj) {
attribute attr{std::move(name)};
attr.owner_ = &obj;
return obj.attributes_.emplace_back(std::move(attr));
}
void add_constraint(class constraint c) {
auto &ref = constraints_.emplace_back(std::move(c));
ref.owner_ = this;
}
[[nodiscard]] const std::string& name() const { return name_; }
[[nodiscard]] const std::string& alias() const { return alias_; }
[[nodiscard]] bool has_attributes() const { return attributes_.empty(); }
[[nodiscard]] size_t attribute_count() const { return attributes_.size(); }
[[nodiscard]] const std::vector<attribute>& attributes() const { return attributes_; }
[[nodiscard]] bool has_constraints() const { return constraints_.empty(); }
[[nodiscard]] size_t constraint_count() const { return constraints_.size(); }
[[nodiscard]] const std::vector<class constraint>& constraints() const { return constraints_; }
private:
friend class object_generator;
std::string name_;
std::string alias_;
std::vector<attribute> attributes_;
std::vector<class constraint> constraints_;
};
class object_generator {
public:
template<typename Type>
object generate(std::string name, std::string alias = "") {
object obj{std::move(name), std::move(alias)};
attribute_generator::generate<Type>(*this);
Type obj2;
access::process(gen, obj2);
return obj;
}
private:
};
}
#endif //MATADOR_OBJECT_GENERATOR_HPP