proxy lazy resolve progress

This commit is contained in:
Sascha Kühl
2025-08-18 16:21:24 +02:00
parent 466977b620
commit 1370eafac4
5 changed files with 15 additions and 45 deletions
+15 -8
View File
@@ -2,6 +2,7 @@
#define OBJECT_PROXY_HPP
#include <memory>
#include <functional>
namespace matador::object {
@@ -13,7 +14,7 @@ public:
};
template<class Type>
class object_proxy : public basic_object_proxy {
class object_proxy final : public basic_object_proxy {
public:
object_proxy() = default;
explicit object_proxy(Type* obj)
@@ -21,20 +22,26 @@ public:
explicit object_proxy(std::unique_ptr<Type> obj)
: obj_(std::move(obj)) {}
[[nodiscard]] void *get() const override { return static_cast<void*>(obj_.get()); }
[[nodiscard]] void *get() const override { return static_cast<void*>(pointer()); }
Type* operator->() const { return obj_.get(); }
Type& operator*() { return *obj_; }
const Type& operator*() const { return *obj_; }
Type* operator->() const { return pointer(); }
Type& operator*() { return *pointer(); }
const Type& operator*() const { return *pointer(); }
Type* pointer() const { return obj_.get(); }
Type* pointer() const { return resolve(); }
Type& ref() { return *obj_; }
const Type& ref() const { return *obj_; }
Type& ref() { return *pointer(); }
const Type& ref() const { return *pointer(); }
void reset(Type* obj) { obj_.reset(obj); }
private:
Type* resolve() const {
return resolver_(*this);
}
private:
std::function<Type*(const object_proxy&)> resolver_{[](const object_proxy &proxy){ return proxy.obj_.get();}};
std::unique_ptr<Type> obj_{};
};
@@ -9,8 +9,6 @@
#include <cstdint>
#include <string>
#include <type_traits>
namespace matador::object {