From cdcf0e2f9a8fb0e1c363fc65f71f3131fc6c5ea5 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Wed, 12 Mar 2025 10:29:11 +0000 Subject: Move serialization from Serializable to a Serialize::Type child. --- modules/botserv/bs_badwords.cpp | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'modules/botserv') diff --git a/modules/botserv/bs_badwords.cpp b/modules/botserv/bs_badwords.cpp index e1a283eb7..946549713 100644 --- a/modules/botserv/bs_badwords.cpp +++ b/modules/botserv/bs_badwords.cpp @@ -18,15 +18,25 @@ struct BadWordImpl final { BadWordImpl() : Serializable("BadWord") { } ~BadWordImpl() override; +}; + +struct BadWordTypeImpl final + : Serialize::Type +{ + BadWordTypeImpl() + : Serialize::Type("BadWord") + { + } - void Serialize(Serialize::Data &data) const override + void Serialize(const Serializable *obj, Serialize::Data &data) const override { - data.Store("ci", this->chan); - data.Store("word", this->word); - data.Store("type", this->type); + const auto *bw = static_cast(obj); + data.Store("ci", bw->chan); + data.Store("word", bw->word); + data.Store("type", bw->type); } - static Serializable *Unserialize(Serializable *obj, Serialize::Data &); + Serializable *Unserialize(Serializable *obj, Serialize::Data &) const override; }; struct BadWordsImpl final @@ -117,7 +127,7 @@ BadWordImpl::~BadWordImpl() } } -Serializable *BadWordImpl::Unserialize(Serializable *obj, Serialize::Data &data) +Serializable *BadWordTypeImpl::Unserialize(Serializable *obj, Serialize::Data &data) const { Anope::string sci, sword; @@ -464,11 +474,13 @@ class BSBadwords final { CommandBSBadwords commandbsbadwords; ExtensibleItem badwords; - Serialize::Type badword_type; + BadWordTypeImpl badword_type; public: - BSBadwords(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - commandbsbadwords(this), badwords(this, "badwords"), badword_type("BadWord", BadWordImpl::Unserialize) + BSBadwords(const Anope::string &modname, const Anope::string &creator) + : Module(modname, creator, VENDOR) + , commandbsbadwords(this) + , badwords(this, "badwords") { } }; -- cgit