#ifndef OBJECT_PTR_HPP #define OBJECT_PTR_HPP #include "matador/utils/identifier.hpp" #include "matador/object/object_proxy.hpp" #include namespace matador::object { template class object_ptr { public: object_ptr() : proxy_(std::make_shared>()) {} explicit object_ptr(std::shared_ptr obj) : proxy_(std::make_shared>(obj)) {} explicit object_ptr(std::shared_ptr> obj) : proxy_(std::move(obj)) {} object_ptr(const object_ptr &other) = default; object_ptr(object_ptr &&other) noexcept = default; object_ptr &operator=(const object_ptr &other) = default; object_ptr &operator=(object_ptr &&other) = default; bool operator==(const object_ptr &other) const { return get() == other.get(); } bool operator!=(const object_ptr &other) const { return !operator==(other); } using value_type = Type; Type *operator->() const { return get(); } Type &operator*() { return *get(); } const Type &operator*() const { return *get(); } [[nodiscard]] bool empty() const { return get() == nullptr; } Type *get() const { return proxy_ ? proxy_->pointer() : nullptr; } void reset() { proxy_.reset(); } operator bool() { return valid(); } bool valid() { return proxy_ != nullptr; } [[nodiscard]] bool has_primary_key() const { return proxy_->has_primary_key(); } [[nodiscard]] const utils::identifier &primary_key() const { return proxy_->primary_key(); } void primary_key(const utils::identifier &pk) { proxy_->primary_key(pk); } private: std::shared_ptr > proxy_{}; }; template struct is_object_ptr : std::false_type { }; template struct is_object_ptr > : std::true_type { }; } #endif //OBJECT_PTR_HPP