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 ServiceProvider, public usecountbase
18 ExtensionItem(const std::string& key, Module* owner);
19 virtual ~ExtensionItem();
20 /** Serialize this item into a string
22 * @param format The format to serialize to
23 * @param container The object containing this item
24 * @param item The item itself
26 virtual std::string serialize(SerializeFormat format, const Extensible* container, void* item) const = 0;
27 /** Convert the string form back into an item
28 * @param format The format to serialize from (not FORMAT_USER)
29 * @param container The object that this item applies to
30 * @param value The return from a serialize() call that was run elsewhere with this key
32 virtual void unserialize(SerializeFormat format, Extensible* container, const std::string& value) = 0;
34 virtual void free(void* item) = 0;
37 /** Get the item from the internal map */
38 void* get_raw(const Extensible* container) const;
39 /** Set the item in the internal map; returns old value */
40 void* set_raw(Extensible* container, void* value);
41 /** Remove the item from the internal map; returns old value */
42 void* unset_raw(Extensible* container);
45 /** class Extensible is the parent class of many classes such as User and Channel.
46 * class Extensible implements a system which allows modules to 'extend' the class by attaching data within
47 * a map associated with the object. In this way modules can store their own custom information within user
48 * objects, channel objects and server objects, without breaking other modules (this is more sensible than using
49 * a flags variable, and each module defining bits within the flag as 'theirs' as it is less prone to conflict and
50 * supports arbitary data storage).
52 class CoreExport Extensible : public classbase
55 typedef std::map<reference<ExtensionItem>,void*> ExtensibleStore;
57 // Friend access for the protected getter/setter
58 friend class ExtensionItem;
60 /** Private data store.
61 * Holds all extensible metadata for the class.
63 ExtensibleStore extensions;
66 * Get the extension items for iteraton (i.e. for metadata sync during netburst)
68 inline const ExtensibleStore& GetExtList() const { return extensions; }
71 virtual CullResult cull();
72 virtual ~Extensible();
73 void doUnhookExtensions(const std::vector<reference<ExtensionItem> >& toRemove);
76 class CoreExport ExtensionManager
78 std::map<std::string, reference<ExtensionItem> > types;
80 void Register(ExtensionItem* item);
81 void BeginUnregister(Module* module, std::vector<reference<ExtensionItem> >& list);
82 ExtensionItem* GetItem(const std::string& name);
85 /** Base class for items that are NOT synchronized between servers */
86 class CoreExport LocalExtItem : public ExtensionItem
89 LocalExtItem(const std::string& key, Module* owner);
90 virtual ~LocalExtItem();
91 virtual std::string serialize(SerializeFormat format, const Extensible* container, void* item) const;
92 virtual void unserialize(SerializeFormat format, Extensible* container, const std::string& value);
93 virtual void free(void* item) = 0;
97 class SimpleExtItem : public LocalExtItem
100 SimpleExtItem(const std::string& Key, Module* parent) : LocalExtItem(Key, parent)
104 virtual ~SimpleExtItem()
108 inline T* get(const Extensible* container) const
110 return static_cast<T*>(get_raw(container));
113 inline void set(Extensible* container, const T& value)
115 T* ptr = new T(value);
116 T* old = static_cast<T*>(set_raw(container, ptr));
120 inline void set(Extensible* container, T* value)
122 T* old = static_cast<T*>(set_raw(container, value));
126 inline void unset(Extensible* container)
128 T* old = static_cast<T*>(unset_raw(container));
132 virtual void free(void* item)
134 delete static_cast<T*>(item);
138 class CoreExport LocalStringExt : public SimpleExtItem<std::string>
141 LocalStringExt(const std::string& key, Module* owner);
142 virtual ~LocalStringExt();
143 std::string serialize(SerializeFormat format, const Extensible* container, void* item) const;
146 class CoreExport LocalIntExt : public LocalExtItem
149 LocalIntExt(const std::string& key, Module* owner);
150 virtual ~LocalIntExt();
151 std::string serialize(SerializeFormat format, const Extensible* container, void* item) const;
152 intptr_t get(const Extensible* container) const;
153 intptr_t set(Extensible* container, intptr_t value);
154 void free(void* item);
157 class CoreExport StringExtItem : public ExtensionItem
160 StringExtItem(const std::string& key, Module* owner);
161 virtual ~StringExtItem();
162 std::string* get(const Extensible* container) const;
163 std::string serialize(SerializeFormat format, const Extensible* container, void* item) const;
164 void unserialize(SerializeFormat format, Extensible* container, const std::string& value);
165 void set(Extensible* container, const std::string& value);
166 void unset(Extensible* container);
167 void free(void* item);