6 /** Shown to a human (does not need to be unserializable) */
8 /** Passed internally to this process (i.e. for /RELOADMODULE) */
10 /** Passed to other servers on the network (i.e. METADATA s2s command) */
12 /** Stored on disk (i.e. permchannel database) */
16 /** Class represnting an extension of some object
18 class CoreExport ExtensionItem : public refcountbase
21 const std::string key;
23 ExtensionItem(const std::string& key, Module* owner);
24 virtual ~ExtensionItem();
25 /** Serialize this item into a string
27 * @param format The format to serialize to
28 * @param container The object containing this item
29 * @param item The item itself
31 virtual std::string serialize(SerializeFormat format, const Extensible* container, void* item) const = 0;
32 /** Convert the string form back into an item
33 * @param format The format to serialize from (not FORMAT_USER)
34 * @param container The object that this item applies to
35 * @param value The return from a serialize() call that was run elsewhere with this key
37 virtual void unserialize(SerializeFormat format, Extensible* container, const std::string& value) = 0;
39 virtual void free(void* item) = 0;
42 /** Get the item from the internal map */
43 void* get_raw(const Extensible* container) const;
44 /** Set the item in the internal map; returns old value */
45 void* set_raw(Extensible* container, void* value);
46 /** Remove the item from the internal map; returns old value */
47 void* unset_raw(Extensible* container);
50 /** class Extensible is the parent class of many classes such as User and Channel.
51 * class Extensible implements a system which allows modules to 'extend' the class by attaching data within
52 * a map associated with the object. In this way modules can store their own custom information within user
53 * objects, channel objects and server objects, without breaking other modules (this is more sensible than using
54 * a flags variable, and each module defining bits within the flag as 'theirs' as it is less prone to conflict and
55 * supports arbitary data storage).
57 class CoreExport Extensible : public classbase
60 typedef std::map<reference<ExtensionItem>,void*> ExtensibleStore;
62 // Friend access for the protected getter/setter
63 friend class ExtensionItem;
65 /** Private data store.
66 * Holds all extensible metadata for the class.
68 ExtensibleStore extensions;
71 * Get the extension items for iteraton (i.e. for metadata sync during netburst)
73 inline const ExtensibleStore& GetExtList() const { return extensions; }
76 virtual CullResult cull();
77 virtual ~Extensible();
78 void doUnhookExtensions(const std::vector<reference<ExtensionItem> >& toRemove);
81 class CoreExport ExtensionManager
83 std::map<std::string, reference<ExtensionItem> > types;
85 void Register(ExtensionItem* item);
86 void BeginUnregister(Module* module, std::vector<reference<ExtensionItem> >& list);
87 ExtensionItem* GetItem(const std::string& name);
90 /** Base class for items that are NOT synchronized between servers */
91 class CoreExport LocalExtItem : public ExtensionItem
94 LocalExtItem(const std::string& key, Module* owner);
95 virtual ~LocalExtItem();
96 virtual std::string serialize(SerializeFormat format, const Extensible* container, void* item) const;
97 virtual void unserialize(SerializeFormat format, Extensible* container, const std::string& value);
98 virtual void free(void* item) = 0;
102 class SimpleExtItem : public LocalExtItem
105 SimpleExtItem(const std::string& Key, Module* parent) : LocalExtItem(Key, parent)
109 virtual ~SimpleExtItem()
113 inline T* get(const Extensible* container) const
115 return static_cast<T*>(get_raw(container));
118 inline void set(Extensible* container, const T& value)
120 T* ptr = new T(value);
121 T* old = static_cast<T*>(set_raw(container, ptr));
125 inline void set(Extensible* container, T* value)
127 T* old = static_cast<T*>(set_raw(container, value));
131 inline void unset(Extensible* container)
133 T* old = static_cast<T*>(unset_raw(container));
137 virtual void free(void* item)
139 delete static_cast<T*>(item);
143 class CoreExport LocalStringExt : public SimpleExtItem<std::string>
146 LocalStringExt(const std::string& key, Module* owner);
147 virtual ~LocalStringExt();
148 std::string serialize(SerializeFormat format, const Extensible* container, void* item) const;
151 class CoreExport LocalIntExt : public LocalExtItem
154 LocalIntExt(const std::string& key, Module* owner);
155 virtual ~LocalIntExt();
156 std::string serialize(SerializeFormat format, const Extensible* container, void* item) const;
157 intptr_t get(const Extensible* container) const;
158 intptr_t set(Extensible* container, intptr_t value);
159 void free(void* item);
162 class CoreExport StringExtItem : public ExtensionItem
165 StringExtItem(const std::string& key, Module* owner);
166 virtual ~StringExtItem();
167 std::string* get(const Extensible* container) const;
168 std::string serialize(SerializeFormat format, const Extensible* container, void* item) const;
169 void unserialize(SerializeFormat format, Extensible* container, const std::string& value);
170 void set(Extensible* container, const std::string& value);
171 void unset(Extensible* container);
172 void free(void* item);