From 15d9b638f602075fcd56e3dc0cedcb1507bfab11 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Tue, 4 Apr 2017 16:07:31 -0700 Subject: [PATCH] ircd::mods: Better support for std::shared_ptr import between modules. --- include/ircd/mods.h | 43 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/include/ircd/mods.h b/include/ircd/mods.h index 7f776c04f..658abe37b 100644 --- a/include/ircd/mods.h +++ b/include/ircd/mods.h @@ -80,12 +80,11 @@ class sym_ptr bool operator!() const { return expired(); } template const T *get() const; - template T *get(); - template const T *operator->() const; - template T *operator->(); - template const T &operator*() const; + + template T *get(); + template T *operator->(); template T &operator*(); sym_ptr(const std::string &modname, const std::string &symname); @@ -97,17 +96,32 @@ struct import :sym_ptr { const T *operator->() const { return sym_ptr::operator->(); } - T *operator->() { return sym_ptr::operator->(); } - const T &operator*() const { return sym_ptr::operator*(); } - T &operator*() { return sym_ptr::operator*(); } - operator const T &() const { return sym_ptr::operator*(); } + + T *operator->() { return sym_ptr::operator->(); } + T &operator*() { return sym_ptr::operator*(); } operator T &() { return sym_ptr::operator*(); } using sym_ptr::sym_ptr; }; +template +struct import_shared +:import> +,std::shared_ptr +{ + using std::shared_ptr::get; + using std::shared_ptr::operator bool; + using std::shared_ptr::operator->; + using std::shared_ptr::operator*; + + operator const T &() const { return std::shared_ptr::operator*(); } + operator T &() { return std::shared_ptr::operator*(); } + + import_shared(const std::string &modname, const std::string &symname); +}; + std::vector symbols(const std::string &fullpath, const std::string §ion); std::vector symbols(const std::string &fullpath); std::vector sections(const std::string &fullpath); @@ -133,9 +147,22 @@ namespace ircd { using mods::module; // Bring struct module into main ircd:: using mods::import; +using mods::import_shared; } // namespace ircd +template +ircd::mods::import_shared::import_shared(const std::string &modname, + const std::string &symname) +:import> +{ + modname, symname +} +,std::shared_ptr +{ + import>::operator*() +}{} + template T & ircd::mods::sym_ptr::operator*()