0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-26 08:42:34 +01:00
construct/include/ircd/mods/module.h
2018-03-23 22:52:36 -07:00

76 lines
1.8 KiB
C++

// 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>
{
const std::string &name() const;
const std::string &path() const;
const std::string &mangle(const std::string &) const;
bool has(const std::string &name) const;
template<class T = uint8_t> const T *ptr(const std::string &name) const;
template<class T = uint8_t> T *ptr(const std::string &name);
template<class T> const T &get(const std::string &name) const;
template<class T> T &get(const std::string &name);
module(std::shared_ptr<mod> ptr = {})
:std::shared_ptr<mod>{std::move(ptr)}
{}
module(const std::string &name);
~module() noexcept;
};
namespace ircd::mods
{
template<> const uint8_t *module::ptr<const uint8_t>(const std::string &name) const;
template<> uint8_t *module::ptr<uint8_t>(const std::string &name);
}
template<class T>
T &
ircd::mods::module::get(const std::string &name)
{
return *ptr<T>(name);
}
template<class T>
const T &
ircd::mods::module::get(const std::string &name)
const
{
return *ptr<T>(name);
}
template<class T>
T *
ircd::mods::module::ptr(const std::string &name)
{
return reinterpret_cast<T *>(ptr<uint8_t>(name));
}
template<class T>
const T *
ircd::mods::module::ptr(const std::string &name)
const
{
return reinterpret_cast<const T *>(ptr<const uint8_t>(name));
}