diff options
author | Sadie Powell <sadie@witchery.services> | 2025-03-12 10:29:11 +0000 |
---|---|---|
committer | Sadie Powell <sadie@witchery.services> | 2025-03-12 15:53:52 +0000 |
commit | cdcf0e2f9a8fb0e1c363fc65f71f3131fc6c5ea5 (patch) | |
tree | 3a665673235bb4dea58b99474492d90e0f711697 /src/regchannel.cpp | |
parent | 718f2e922a6e1113d66fc6e96131213942d507b2 (diff) |
Move serialization from Serializable to a Serialize::Type child.
Diffstat (limited to 'src/regchannel.cpp')
-rw-r--r-- | src/regchannel.cpp | 75 |
1 files changed, 44 insertions, 31 deletions
diff --git a/src/regchannel.cpp b/src/regchannel.cpp index 9e450830b..51b395399 100644 --- a/src/regchannel.cpp +++ b/src/regchannel.cpp @@ -38,20 +38,26 @@ AutoKick::~AutoKick() } } -void AutoKick::Serialize(Serialize::Data &data) const +AutoKick::Type::Type() + : Serialize::Type("AutoKick") { - data.Store("ci", this->ci->name); - if (this->nc) - data.Store("nc", this->nc->display); +} + +void AutoKick::Type::Serialize(const Serializable *obj, Serialize::Data &data) const +{ + const auto *ak = static_cast<const AutoKick *>(obj); + data.Store("ci", ak->ci->name); + if (ak->nc) + data.Store("nc", ak->nc->display); else - data.Store("mask", this->mask); - data.Store("reason", this->reason); - data.Store("creator", this->creator); - data.Store("addtime", this->addtime); - data.Store("last_used", this->last_used); + data.Store("mask", ak->mask); + data.Store("reason", ak->reason); + data.Store("creator", ak->creator); + data.Store("addtime", ak->addtime); + data.Store("last_used", ak->last_used); } -Serializable *AutoKick::Unserialize(Serializable *obj, Serialize::Data &data) +Serializable *AutoKick::Type::Unserialize(Serializable *obj, Serialize::Data &data) const { Anope::string sci, snc; @@ -178,40 +184,47 @@ ChannelInfo::~ChannelInfo() } } -void ChannelInfo::Serialize(Serialize::Data &data) const +ChannelInfo::Type::Type() + : Serialize::Type("ChannelInfo") { - data.Store("name", this->name); - if (this->founder) - data.Store("founder", this->founder->display); - if (this->successor) - data.Store("successor", this->successor->display); - data.Store("description", this->desc); - data.Store("time_registered", this->time_registered); - data.Store("last_used", this->last_used); - data.Store("last_topic", this->last_topic); - data.Store("last_topic_setter", this->last_topic_setter); - data.Store("last_topic_time", this->last_topic_time); - data.Store("bantype", this->bantype); +} + +void ChannelInfo::Type::Serialize(const Serializable *obj, Serialize::Data &data) const +{ + const auto *ci = static_cast<const ChannelInfo *>(obj); + + data.Store("name", ci->name); + if (ci->founder) + data.Store("founder", ci->founder->display); + if (ci->successor) + data.Store("successor", ci->successor->display); + data.Store("description", ci->desc); + data.Store("time_registered", ci->time_registered); + data.Store("last_used", ci->last_used); + data.Store("last_topic", ci->last_topic); + data.Store("last_topic_setter", ci->last_topic_setter); + data.Store("last_topic_time", ci->last_topic_time); + data.Store("bantype", ci->bantype); { Anope::string levels_buffer; - for (const auto &[name, level] : this->levels) + for (const auto &[name, level] : ci->levels) levels_buffer += name + " " + Anope::ToString(level) + " "; data.Store("levels", levels_buffer); } - if (this->bi) - data.Store("bi", this->bi->nick); - data.Store("banexpire", this->banexpire); - data.Store("memomax", this->memos.memomax); + if (ci->bi) + data.Store("bi", ci->bi->nick); + data.Store("banexpire", ci->banexpire); + data.Store("memomax", ci->memos.memomax); std::ostringstream oss; - for (const auto &ignore : this->memos.ignores) + for (const auto &ignore : ci->memos.ignores) oss << ignore << " "; data.Store("memoignores", oss.str()); - Extensible::ExtensibleSerialize(this, this, data); + Extensible::ExtensibleSerialize(ci, ci, data); } -Serializable *ChannelInfo::Unserialize(Serializable *obj, Serialize::Data &data) +Serializable *ChannelInfo::Type::Unserialize(Serializable *obj, Serialize::Data &data) const { Anope::string sname, sfounder, ssuccessor, slevels, sbi; |