X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=include%2Fdynref.h;h=44829164b270552a96b3c3919944ab76d05aa7b7;hb=20fa9e1038ee3d5c2d0c89bf7e8e6dcda0644aa6;hp=02474b67e50753251c01cff48b5078bf76ccb05f;hpb=f62654a6859998f9d63eb22702c572d5ebcff15c;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/include/dynref.h b/include/dynref.h index 02474b67e..44829164b 100644 --- a/include/dynref.h +++ b/include/dynref.h @@ -22,10 +22,20 @@ #include "base.h" -class CoreExport dynamic_reference_base : public interfacebase, public intrusive_list_node +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; @@ -33,8 +43,14 @@ class CoreExport dynamic_reference_base : public interfacebase, public intrusive ModuleRef creator; dynamic_reference_base(Module* Creator, const std::string& Name); ~dynamic_reference_base(); - inline const std::string& GetProvider() { return name; } + inline const std::string& GetProvider() const { 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;