query/include/matador/object/object_info.hpp

51 lines
1.4 KiB
C++

#ifndef OBJECT_INFO_HPP
#define OBJECT_INFO_HPP
#include "matador/object/basic_object_info.hpp"
namespace matador::object {
class repository_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<repository_node>& node,
const std::vector<attribute> &attributes,
utils::identifier &&pk,
const std::shared_ptr<attribute> &ref_column,
create_func&& creator)
: basic_object_info(node, attributes, std::move(pk), ref_column)
, creator_(std::move(creator)){
}
object_info(const std::shared_ptr<repository_node>& node,
const std::vector<attribute> &attributes,
create_func&& creator)
: basic_object_info(node, attributes)
, creator_(std::move(creator)){
}
explicit object_info(const std::shared_ptr<repository_node>& node)
: basic_object_info(node, {}) {
}
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