diff options
author | danieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7> | 2009-09-13 20:32:03 +0000 |
---|---|---|
committer | danieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7> | 2009-09-13 20:32:03 +0000 |
commit | 0ed3ef9dee2cb8f4b0c37da218a2fd1eee8c31f6 (patch) | |
tree | 933fa0ba26a0113b0404ca52796440bc297a614c /src/base.cpp | |
parent | d9e3bb8d4343643504ab7ee6ab943a000065cc8a (diff) |
Add SerializeFormat for easier metadata formatting
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11704 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/base.cpp')
-rw-r--r-- | src/base.cpp | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/src/base.cpp b/src/base.cpp index 4d0c17077..1e4f746af 100644 --- a/src/base.cpp +++ b/src/base.cpp @@ -147,19 +147,36 @@ LocalExtItem::LocalExtItem(const std::string& Key, Module* mod) : ExtensionItem( { } -std::string LocalExtItem::serialize(Module* requestor, const Extensible* container, void* item) +std::string LocalExtItem::serialize(SerializeFormat format, const Extensible* container, void* item) { return ""; } -void LocalExtItem::unserialize(Module* requestor, Extensible* container, const std::string& value) +void LocalExtItem::unserialize(SerializeFormat format, Extensible* container, const std::string& value) { } +LocalStringExt::LocalStringExt(const std::string& Key, Module* Owner) + : SimpleExtItem<std::string>(Key, Owner) { } + +std::string LocalStringExt::serialize(SerializeFormat format, const Extensible* container, void* item) +{ + if (item && format == FORMAT_USER) + return *static_cast<std::string*>(item); + return ""; +} + LocalIntExt::LocalIntExt(const std::string& Key, Module* mod) : LocalExtItem(Key, mod) { } +std::string LocalIntExt::serialize(SerializeFormat format, const Extensible* container, void* item) +{ + if (format != FORMAT_USER) + return ""; + return ConvToStr(reinterpret_cast<intptr_t>(item)); +} + intptr_t LocalIntExt::get(const Extensible* container) { return reinterpret_cast<intptr_t>(get_raw(container)); @@ -186,12 +203,12 @@ std::string* StringExtItem::get(const Extensible* container) return static_cast<std::string*>(get_raw(container)); } -std::string StringExtItem::serialize(Module* requestor, const Extensible* container, void* item) +std::string StringExtItem::serialize(SerializeFormat format, const Extensible* container, void* item) { return item ? *static_cast<std::string*>(item) : ""; } -void StringExtItem::unserialize(Module* requestor, Extensible* container, const std::string& value) +void StringExtItem::unserialize(SerializeFormat format, Extensible* container, const std::string& value) { if (value.empty()) unset(container); |