3 /** Shown to a human (does not need to be unserializable) */
5 /** Passed internally to this process (i.e. for /RELOADMODULE) */
7 /** Passed to other servers on the network (i.e. METADATA s2s command) */
9 /** Stored on disk (i.e. permchannel database) */
13 /** Class represnting an extension of some object
15 class CoreExport ExtensionItem : public usecountbase
18 const std::string key;
20 ExtensionItem(const std::string& key, Module* owner);
21 virtual ~ExtensionItem();
22 /** Serialize this item into a string
24 * @param format The format to serialize to
25 * @param container The object containing this item
26 * @param item The item itself
28 virtual std::string serialize(SerializeFormat format, const Extensible* container, void* item) const = 0;
29 /** Convert the string form back into an item
30 * @param format The format to serialize from (not FORMAT_USER)
31 * @param container The object that this item applies to
32 * @param value The return from a serialize() call that was run elsewhere with this key
34 virtual void unserialize(SerializeFormat format, Extensible* container, const std::string& value) = 0;
36 virtual void free(void* item) = 0;
39 /** Get the item from the internal map */
40 void* get_raw(const Extensible* container) const;
41 /** Set the item in the internal map; returns old value */
42 void* set_raw(Extensible* container, void* value);
43 /** Remove the item from the internal map; returns old value */
44 void* unset_raw(Extensible* container);
47 /** class Extensible is the parent class of many classes such as User and Channel.
48 * class Extensible implements a system which allows modules to 'extend' the class by attaching data within
49 * a map associated with the object. In this way modules can store their own custom information within user
50 * objects, channel objects and server objects, without breaking other modules (this is more sensible than using
51 * a flags variable, and each module defining bits within the flag as 'theirs' as it is less prone to conflict and
52 * supports arbitary data storage).
54 class CoreExport Extensible : public classbase
57 typedef std::map<reference<ExtensionItem>,void*> ExtensibleStore;
59 // Friend access for the protected getter/setter
60 friend class ExtensionItem;
62 /** Private data store.
63 * Holds all extensible metadata for the class.
65 ExtensibleStore extensions;
68 * Get the extension items for iteraton (i.e. for metadata sync during netburst)
70 inline const ExtensibleStore& GetExtList() const { return extensions; }
73 virtual CullResult cull();
74 virtual ~Extensible();
75 void doUnhookExtensions(const std::vector<reference<ExtensionItem> >& toRemove);
78 class CoreExport ExtensionManager
80 std::map<std::string, reference<ExtensionItem> > types;
82 void Register(ExtensionItem* item);
83 void BeginUnregister(Module* module, std::vector<reference<ExtensionItem> >& list);
84 ExtensionItem* GetItem(const std::string& name);
87 /** Base class for items that are NOT synchronized between servers */
88 class CoreExport LocalExtItem : public ExtensionItem
91 LocalExtItem(const std::string& key, Module* owner);
92 virtual ~LocalExtItem();
93 virtual std::string serialize(SerializeFormat format, const Extensible* container, void* item) const;
94 virtual void unserialize(SerializeFormat format, Extensible* container, const std::string& value);
95 virtual void free(void* item) = 0;
99 class SimpleExtItem : public LocalExtItem
102 SimpleExtItem(const std::string& Key, Module* parent) : LocalExtItem(Key, parent)
106 virtual ~SimpleExtItem()
110 inline T* get(const Extensible* container) const
112 return static_cast<T*>(get_raw(container));
115 inline void set(Extensible* container, const T& value)
117 T* ptr = new T(value);
118 T* old = static_cast<T*>(set_raw(container, ptr));
122 inline void set(Extensible* container, T* value)
124 T* old = static_cast<T*>(set_raw(container, value));
128 inline void unset(Extensible* container)
130 T* old = static_cast<T*>(unset_raw(container));
134 virtual void free(void* item)
136 delete static_cast<T*>(item);
140 class CoreExport LocalStringExt : public SimpleExtItem<std::string>
143 LocalStringExt(const std::string& key, Module* owner);
144 virtual ~LocalStringExt();
145 std::string serialize(SerializeFormat format, const Extensible* container, void* item) const;
148 class CoreExport LocalIntExt : public LocalExtItem
151 LocalIntExt(const std::string& key, Module* owner);
152 virtual ~LocalIntExt();
153 std::string serialize(SerializeFormat format, const Extensible* container, void* item) const;
154 intptr_t get(const Extensible* container) const;
155 intptr_t set(Extensible* container, intptr_t value);
156 void free(void* item);
159 class CoreExport StringExtItem : public ExtensionItem
162 StringExtItem(const std::string& key, Module* owner);
163 virtual ~StringExtItem();
164 std::string* get(const Extensible* container) const;
165 std::string serialize(SerializeFormat format, const Extensible* container, void* item) const;
166 void unserialize(SerializeFormat format, Extensible* container, const std::string& value);
167 void set(Extensible* container, const std::string& value);
168 void unset(Extensible* container);
169 void free(void* item);