// Matrix Construct // // Copyright (C) Matrix Construct Developers, Authors & Contributors // Copyright (C) 2016-2018 Jason Volk // // Permission to use, copy, modify, and/or distribute this software for any // purpose with or without fee is hereby granted, provided that the above // copyright notice and this permission notice is present in all copies. The // full license for this software is available in the LICENSE file. #pragma once #define HAVE_IRCD_MODS_MODULE_H namespace ircd::mods { struct module; bool operator<(const module &a, const module &b) noexcept; bool operator==(const module &a, const module &b) noexcept; } struct ircd::mods::module :std::shared_ptr { operator const mod &() const; operator mod &(); string_view name() const; string_view path() const; bool has(const string_view &sym) const; template const T *ptr(const string_view &sym) const noexcept; template T *ptr(const string_view &sym) noexcept; template const T &get(const string_view &sym) const; template T &get(const string_view &sym); module(std::shared_ptr ptr = {}); module(const string_view &name); }; inline bool ircd::mods::operator==(const module &a, const module &b) noexcept { return a.name() == b.name(); } inline bool ircd::mods::operator<(const module &a, const module &b) noexcept { return a.name() < b.name(); } inline ircd::mods::module::module(std::shared_ptr ptr) :std::shared_ptr{std::move(ptr)} {} template T & ircd::mods::module::get(const string_view &sym) { mod &mod(*this); return mods::get(mod, sym); } template const T & ircd::mods::module::get(const string_view &sym) const { const mod &mod(*this); return mods::get(mod, sym); } template T * ircd::mods::module::ptr(const string_view &sym) noexcept { mod &mod(*this); return mods::ptr(mod, sym); } template const T * ircd::mods::module::ptr(const string_view &sym) const noexcept { const mod &mod(*this); return mods::ptr(mod, sym); } inline ircd::mods::module::operator mod &() { assert(bool(*this)); return std::shared_ptr::operator*(); } inline ircd::mods::module::operator const mod &() const { assert(bool(*this)); return std::shared_ptr::operator*(); }