X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=include%2Fdynref.h;h=6e2e1742397edf463f551d56a6365bae09a7866f;hb=384ef31bc01e4a1a2e59d082c9066002410ba54a;hp=1d05b35a0c410f58e6a7562c8db9c728544e8209;hpb=e244cb2c63b1ac1d85bdbb4691f7b1bd940ae804;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/include/dynref.h b/include/dynref.h index 1d05b35a0..6e2e17423 100644 --- a/include/dynref.h +++ b/include/dynref.h @@ -22,10 +22,20 @@ #include "base.h" -class CoreExport dynamic_reference_base : public interfacebase +class CoreExport dynamic_reference_base : public interfacebase, public insp::intrusive_list_node { + public: + class CaptureHook + { + public: + /** Called when the target of the dynamic_reference has been acquired + */ + virtual void OnCapture() = 0; + }; + private: std::string name; + CaptureHook* hook; void resolve(); protected: ServiceProvider* value; @@ -35,6 +45,12 @@ class CoreExport dynamic_reference_base : public interfacebase ~dynamic_reference_base(); inline const std::string& GetProvider() { return name; } void SetProvider(const std::string& newname); + + /** Set handler to call when the target object becomes available + * @param h Handler to call + */ + void SetCaptureHook(CaptureHook* h) { hook = h; } + void check(); operator bool() { return (value != NULL); } static void reset_all(); @@ -63,6 +79,16 @@ class dynamic_reference : public dynamic_reference_base { return operator->(); } + + const T* operator->() const + { + return static_cast(value); + } + + const T* operator*() const + { + return operator->(); + } }; template @@ -81,6 +107,16 @@ class dynamic_reference_nocheck : public dynamic_reference_base { return operator->(); } + + const T* operator->() const + { + return static_cast(value); + } + + const T* operator*() const + { + return operator->(); + } }; class ModeHandler;