62 lines
2.0 KiB
C++
62 lines
2.0 KiB
C++
#ifndef OBJECT_INFO_HPP
|
|
#define OBJECT_INFO_HPP
|
|
|
|
#include "matador/object/basic_object_info.hpp"
|
|
#include "matador/object/object_definition.hpp"
|
|
|
|
namespace matador::object {
|
|
class schema_node;
|
|
|
|
template<typename Type>
|
|
class object_info final : public basic_object_info {
|
|
public:
|
|
using create_func = std::function<std::unique_ptr<Type>()>;
|
|
|
|
object_info(const std::shared_ptr<schema_node>& node,
|
|
std::shared_ptr<attribute_definition> &&ref_column)
|
|
: basic_object_info(node, typeid(Type), {}, std::move(ref_column), {})
|
|
, creator_([]{return std::make_unique<Type>(); }){
|
|
}
|
|
object_info(const std::shared_ptr<schema_node>& node,
|
|
utils::identifier &&pk,
|
|
std::shared_ptr<attribute_definition> &&ref_column,
|
|
object_definition &&definition)
|
|
: basic_object_info(node, typeid(Type), std::move(pk), std::move(ref_column), std::move(definition))
|
|
, creator_([]{return std::make_unique<Type>(); }){
|
|
}
|
|
object_info(const std::shared_ptr<schema_node>& node,
|
|
utils::identifier &&pk,
|
|
std::shared_ptr<attribute_definition> &&ref_column,
|
|
object_definition &&definition,
|
|
create_func&& creator)
|
|
: basic_object_info(node, typeid(Type), std::move(pk), std::move(ref_column), std::move(definition))
|
|
, creator_(std::move(creator)){
|
|
}
|
|
object_info(const std::shared_ptr<schema_node>& node,
|
|
object_definition &&definition,
|
|
create_func&& creator)
|
|
: basic_object_info(node, typeid(Type), std::move(definition))
|
|
, creator_(std::move(creator)){
|
|
}
|
|
|
|
const Type &prototype() const { return prototype_; }
|
|
std::unique_ptr<Type> create() const { return creator_(); }
|
|
|
|
private:
|
|
Type prototype_;
|
|
create_func creator_{[]{ return std::make_unique<Type>(); }};
|
|
};
|
|
|
|
template<typename Type>
|
|
using object_info_ref = std::reference_wrapper<const object_info<Type>>;
|
|
|
|
namespace detail {
|
|
struct null_type {
|
|
};
|
|
}
|
|
|
|
using null_info = object_info<detail::null_type>;
|
|
}
|
|
|
|
#endif //OBJECT_INFO_HPP
|