2018-03-24 05:40:20 +01:00
|
|
|
// Matrix Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2018 Jason Volk <jason@zemos.net>
|
|
|
|
//
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ircd::mods::module
|
|
|
|
:std::shared_ptr<mod>
|
|
|
|
{
|
2018-03-26 00:25:32 +02:00
|
|
|
explicit operator const mod &() const;
|
|
|
|
explicit operator mod &();
|
2018-03-24 05:40:20 +01:00
|
|
|
|
2018-03-25 23:32:24 +02:00
|
|
|
string_view name() const;
|
|
|
|
string_view path() const;
|
2018-03-24 05:40:20 +01:00
|
|
|
|
2018-03-25 23:32:24 +02:00
|
|
|
bool has(const string_view &sym) const;
|
2018-03-24 05:40:20 +01:00
|
|
|
|
2018-03-25 23:32:24 +02:00
|
|
|
template<class T = uint8_t> const T *ptr(const string_view &sym) const;
|
|
|
|
template<class T = uint8_t> T *ptr(const string_view &sym);
|
2018-03-24 05:40:20 +01:00
|
|
|
|
2018-03-25 23:32:24 +02:00
|
|
|
template<class T> const T &get(const string_view &sym) const;
|
|
|
|
template<class T> T &get(const string_view &sym);
|
2018-03-24 05:40:20 +01:00
|
|
|
|
2018-03-25 23:32:24 +02:00
|
|
|
module(std::shared_ptr<mod> ptr = {});
|
|
|
|
module(const string_view &name);
|
2018-03-24 05:40:20 +01:00
|
|
|
};
|
|
|
|
|
2018-03-25 23:32:24 +02:00
|
|
|
inline
|
|
|
|
ircd::mods::module::module(std::shared_ptr<mod> ptr)
|
|
|
|
:std::shared_ptr<mod>{std::move(ptr)}
|
|
|
|
{}
|
2018-03-24 05:40:20 +01:00
|
|
|
|
|
|
|
template<class T>
|
|
|
|
T &
|
2018-03-25 23:32:24 +02:00
|
|
|
ircd::mods::module::get(const string_view &sym)
|
2018-03-24 05:40:20 +01:00
|
|
|
{
|
2018-03-26 11:28:02 +02:00
|
|
|
mod &mod(*this);
|
2018-03-26 00:25:32 +02:00
|
|
|
return mods::get<T>(mod, sym);
|
2018-03-24 05:40:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
const T &
|
2018-03-25 23:32:24 +02:00
|
|
|
ircd::mods::module::get(const string_view &sym)
|
2018-03-24 05:40:20 +01:00
|
|
|
const
|
|
|
|
{
|
2018-03-26 11:28:02 +02:00
|
|
|
const mod &mod(*this);
|
2018-03-26 00:25:32 +02:00
|
|
|
return mods::get<T>(mod, sym);
|
2018-03-24 05:40:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
T *
|
2018-03-25 23:32:24 +02:00
|
|
|
ircd::mods::module::ptr(const string_view &sym)
|
2018-03-24 05:40:20 +01:00
|
|
|
{
|
2018-03-26 11:28:02 +02:00
|
|
|
mod &mod(*this);
|
2018-03-26 00:25:32 +02:00
|
|
|
return mods::ptr<T>(mod, sym);
|
2018-03-24 05:40:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
const T *
|
2018-03-25 23:32:24 +02:00
|
|
|
ircd::mods::module::ptr(const string_view &sym)
|
|
|
|
const
|
|
|
|
{
|
2018-03-26 11:28:02 +02:00
|
|
|
const mod &mod(*this);
|
2018-03-26 00:25:32 +02:00
|
|
|
return mods::ptr<T>(mod, sym);
|
2018-03-25 23:32:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
inline ircd::mods::module::operator
|
|
|
|
mod &()
|
|
|
|
{
|
|
|
|
assert(bool(*this));
|
|
|
|
return std::shared_ptr<mod>::operator*();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline ircd::mods::module::operator
|
|
|
|
const mod &()
|
2018-03-24 05:40:20 +01:00
|
|
|
const
|
|
|
|
{
|
2018-03-25 23:32:24 +02:00
|
|
|
assert(bool(*this));
|
|
|
|
return std::shared_ptr<mod>::operator*();
|
2018-03-24 05:40:20 +01:00
|
|
|
}
|