From 0ed3ef9dee2cb8f4b0c37da218a2fd1eee8c31f6 Mon Sep 17 00:00:00 2001 From: danieldg Date: Sun, 13 Sep 2009 20:32:03 +0000 Subject: Add SerializeFormat for easier metadata formatting git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11704 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/base.cpp | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'src/base.cpp') 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(Key, Owner) { } + +std::string LocalStringExt::serialize(SerializeFormat format, const Extensible* container, void* item) +{ + if (item && format == FORMAT_USER) + return *static_cast(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(item)); +} + intptr_t LocalIntExt::get(const Extensible* container) { return reinterpret_cast(get_raw(container)); @@ -186,12 +203,12 @@ std::string* StringExtItem::get(const Extensible* container) return static_cast(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(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); -- cgit v1.2.3