inspircd/include/extensible.h

114 lines
3.5 KiB
C
Raw Permalink Normal View History

/*
* InspIRCd -- Internet Relay Chat Daemon
*
2024-06-07 10:37:56 +01:00
* Copyright (C) 2013, 2019, 2021-2022 Sadie Powell <sadie@witchery.services>
2020-01-11 22:02:47 +00:00
* Copyright (C) 2012, 2014-2015 Attila Molnar <attilamolnar@hush.com>
* Copyright (C) 2012 Robby <robby@chatbelgie.be>
* Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
*
* This file is part of InspIRCd. InspIRCd is free software: you can
* redistribute it and/or modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation, version 2.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
class ExtensionItem;
/** Types of extensible that an extension can extend. */
enum class ExtensionType
: uint8_t
{
/** The extension extends the User class. */
USER = 0,
/** The extension extends the Channel class. */
CHANNEL = 1,
/** The extension extends the Membership class. */
MEMBERSHIP = 2,
};
/** Base class for types which can be extended with additional data. */
class CoreExport Extensible
: public Cullable
{
public:
/** The container which extension values are stored in. */
typedef insp::flat_map<ExtensionItem*, void*> ExtensibleStore;
/** Allows extensions to access the extension store. */
friend class ExtensionItem;
2022-01-31 02:04:43 +00:00
/** The type of extensible that this is. */
const ExtensionType extype:2;
~Extensible() override;
/** @copydoc Cullable::Cull */
Cullable::Result Cull() override;
/** Frees all extensions attached to this extensible. */
void FreeAllExtItems();
/** Retrieves the values for extensions which are set on this extensible. */
const ExtensibleStore& GetExtList() const { return extensions; }
/** Unhooks the specifies extensions from this extensible.
* @param items The items to unhook.
*/
void UnhookExtensions(const std::vector<ExtensionItem*>& items);
protected:
2022-01-31 02:04:43 +00:00
Extensible(ExtensionType exttype);
private:
/** The values for extensions which are set on this extensible. */
ExtensibleStore extensions;
/** Whether this extensible has been culled yet. */
bool culled:1;
};
/** Manager for the extension system */
class CoreExport ExtensionManager final
{
public:
/** The container which registered extensions are stored in. */
2022-01-31 02:10:40 +00:00
typedef std::map<std::string, ExtensionItem*, irc::insensitive_swo> ExtMap;
2015-11-26 13:39:56 +01:00
/** Begins unregistering extensions belonging to the specified module.
* @param module The module to unregister extensions for.
* @param list The list to add unregistered extensions to.
*/
void BeginUnregister(Module* module, std::vector<ExtensionItem*>& list);
/** Retrieves registered extensions keyed by their names. */
const ExtMap& GetExts() const { return types; }
/** Retrieves an extension by name.
* @param name The name of the extension to retrieve.
* @return Either the value of this extension or nullptr if it does not exist.
*/
ExtensionItem* GetItem(const std::string& name);
2015-11-26 13:39:56 +01:00
/** Registers an extension with the manager.
* @return Either true if the extension was registered or false if an extension with the same
* name already exists.
2015-11-26 13:40:44 +01:00
*/
bool Register(ExtensionItem* item);
2015-11-26 13:40:44 +01:00
private:
/** Registered extensions keyed by their names. */
2015-11-26 13:39:56 +01:00
ExtMap types;
};