summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSadie Powell <sadie@witchery.services>2025-03-12 10:29:11 +0000
committerSadie Powell <sadie@witchery.services>2025-03-12 15:53:52 +0000
commitcdcf0e2f9a8fb0e1c363fc65f71f3131fc6c5ea5 (patch)
tree3a665673235bb4dea58b99474492d90e0f711697 /src
parent718f2e922a6e1113d66fc6e96131213942d507b2 (diff)
Move serialization from Serializable to a Serialize::Type child.
Diffstat (limited to 'src')
-rw-r--r--src/access.cpp27
-rw-r--r--src/bots.cpp26
-rw-r--r--src/memos.cpp22
-rw-r--r--src/nickalias.cpp40
-rw-r--r--src/nickcore.cpp30
-rw-r--r--src/regchannel.cpp75
-rw-r--r--src/serialize.cpp20
-rw-r--r--src/xline.cpp27
8 files changed, 160 insertions, 107 deletions
diff --git a/src/access.cpp b/src/access.cpp
index d1c7f59c6..b31a4106a 100644
--- a/src/access.cpp
+++ b/src/access.cpp
@@ -158,19 +158,26 @@ NickCore *ChanAccess::GetAccount() const
return nc;
}
-void ChanAccess::Serialize(Serialize::Data &data) const
+
+ChanAccess::Type::Type()
+ : Serialize::Type("ChanAccess")
+{
+}
+
+void ChanAccess::Type::Serialize(const Serializable *obj, Serialize::Data &data) const
{
- data.Store("provider", this->provider->name);
- data.Store("ci", this->ci->name);
- data.Store("mask", this->Mask());
- data.Store("creator", this->creator);
- data.Store("description", this->description);
- data.Store("last_seen", this->last_seen);
- data.Store("created", this->created);
- data.Store("data", this->AccessSerialize());
+ const auto *access = static_cast<const ChanAccess *>(obj);
+ data.Store("provider", access->provider->name);
+ data.Store("ci", access->ci->name);
+ data.Store("mask", access->Mask());
+ data.Store("creator", access->creator);
+ data.Store("description", access->description);
+ data.Store("last_seen", access->last_seen);
+ data.Store("created", access->created);
+ data.Store("data", access->AccessSerialize());
}
-Serializable *ChanAccess::Unserialize(Serializable *obj, Serialize::Data &data)
+Serializable *ChanAccess::Type::Unserialize(Serializable *obj, Serialize::Data &data) const
{
Anope::string provider, chan;
diff --git a/src/bots.cpp b/src/bots.cpp
index 35a4ccb05..fa9042733 100644
--- a/src/bots.cpp
+++ b/src/bots.cpp
@@ -84,19 +84,25 @@ BotInfo::~BotInfo()
BotListByUID->erase(this->uid);
}
-void BotInfo::Serialize(Serialize::Data &data) const
+BotInfo::Type::Type()
+ : Serialize::Type("BotInfo")
{
- data.Store("nick", this->nick);
- data.Store("user", this->ident);
- data.Store("host", this->host);
- data.Store("realname", this->realname);
- data.Store("created", this->created);
- data.Store("oper_only", this->oper_only);
-
- Extensible::ExtensibleSerialize(this, this, data);
}
-Serializable *BotInfo::Unserialize(Serializable *obj, Serialize::Data &data)
+void BotInfo::Type::Serialize(const Serializable *obj, Serialize::Data &data) const
+{
+ const auto *bi = static_cast<const BotInfo *>(obj);
+ data.Store("nick", bi->nick);
+ data.Store("user", bi->ident);
+ data.Store("host", bi->host);
+ data.Store("realname", bi->realname);
+ data.Store("created", bi->created);
+ data.Store("oper_only", bi->oper_only);
+
+ Extensible::ExtensibleSerialize(bi, bi, data);
+}
+
+Serializable *BotInfo::Type::Unserialize(Serializable *obj, Serialize::Data &data) const
{
Anope::string nick, user, host, realname, flags;
diff --git a/src/memos.cpp b/src/memos.cpp
index 809c05383..00b60325a 100644
--- a/src/memos.cpp
+++ b/src/memos.cpp
@@ -34,17 +34,23 @@ Memo::~Memo()
}
}
-void Memo::Serialize(Serialize::Data &data) const
+Memo::Type::Type()
+ : Serialize::Type("Memo")
{
- data.Store("owner", this->owner);
- data.Store("time", this->time);
- data.Store("sender", this->sender);
- data.Store("text", this->text);
- data.Store("unread", this->unread);
- data.Store("receipt", this->receipt);
}
-Serializable *Memo::Unserialize(Serializable *obj, Serialize::Data &data)
+void Memo::Type::Serialize(const Serializable *obj, Serialize::Data &data) const
+{
+ const auto *m = static_cast<const Memo *>(obj);
+ data.Store("owner", m->owner);
+ data.Store("time", m->time);
+ data.Store("sender", m->sender);
+ data.Store("text", m->text);
+ data.Store("unread", m->unread);
+ data.Store("receipt", m->receipt);
+}
+
+Serializable *Memo::Type::Unserialize(Serializable *obj, Serialize::Data &data) const
{
Anope::string owner;
diff --git a/src/nickalias.cpp b/src/nickalias.cpp
index ca311166e..66e67cde2 100644
--- a/src/nickalias.cpp
+++ b/src/nickalias.cpp
@@ -139,29 +139,35 @@ NickAlias *NickAlias::Find(const Anope::string &nick)
return NULL;
}
-void NickAlias::Serialize(Serialize::Data &data) const
+NickAlias::Type::Type()
+ : Serialize::Type("NickAlias")
{
- data.Store("nick", this->nick);
- data.Store("last_quit", this->last_quit);
- data.Store("last_realname", this->last_realname);
- data.Store("last_usermask", this->last_usermask);
- data.Store("last_realhost", this->last_realhost);
- data.Store("time_registered", this->time_registered);
- data.Store("last_seen", this->last_seen);
- data.Store("nc", this->nc->display);
-
- if (this->HasVHost())
+}
+
+void NickAlias::Type::Serialize(const Serializable *obj, Serialize::Data &data) const
+{
+ const auto *na = static_cast<const NickAlias *>(obj);
+ data.Store("nick", na->nick);
+ data.Store("last_quit", na->last_quit);
+ data.Store("last_realname", na->last_realname);
+ data.Store("last_usermask", na->last_usermask);
+ data.Store("last_realhost", na->last_realhost);
+ data.Store("time_registered", na->time_registered);
+ data.Store("last_seen", na->last_seen);
+ data.Store("nc", na->nc->display);
+
+ if (na->HasVHost())
{
- data.Store("vhost_ident", this->GetVHostIdent());
- data.Store("vhost_host", this->GetVHostHost());
- data.Store("vhost_creator", this->GetVHostCreator());
- data.Store("vhost_time", this->GetVHostCreated());
+ data.Store("vhost_ident", na->GetVHostIdent());
+ data.Store("vhost_host", na->GetVHostHost());
+ data.Store("vhost_creator", na->GetVHostCreator());
+ data.Store("vhost_time", na->GetVHostCreated());
}
- Extensible::ExtensibleSerialize(this, this, data);
+ Extensible::ExtensibleSerialize(na, na, data);
}
-Serializable *NickAlias::Unserialize(Serializable *obj, Serialize::Data &data)
+Serializable *NickAlias::Type::Unserialize(Serializable *obj, Serialize::Data &data) const
{
Anope::string snc, snick;
diff --git a/src/nickcore.cpp b/src/nickcore.cpp
index 9b44dc61a..372c8751d 100644
--- a/src/nickcore.cpp
+++ b/src/nickcore.cpp
@@ -66,26 +66,32 @@ NickCore::~NickCore()
}
}
-void NickCore::Serialize(Serialize::Data &data) const
+NickCore::Type::Type()
+ : Serialize::Type("NickCore")
{
- data.Store("display", this->display);
- data.Store("uniqueid", this->id);
- data.Store("pass", this->pass);
- data.Store("email", this->email);
- data.Store("language", this->language);
- data.Store("lastmail", this->lastmail);
- data.Store("time_registered", this->time_registered);
- data.Store("memomax", this->memos.memomax);
+}
+
+void NickCore::Type::Serialize(const Serializable *obj, Serialize::Data &data) const
+{
+ const auto *nc = static_cast<const NickCore *>(obj);
+ data.Store("display", nc->display);
+ data.Store("uniqueid", nc->id);
+ data.Store("pass", nc->pass);
+ data.Store("email", nc->email);
+ data.Store("language", nc->language);
+ data.Store("lastmail", nc->lastmail);
+ data.Store("time_registered", nc->time_registered);
+ data.Store("memomax", nc->memos.memomax);
std::ostringstream oss;
- for (const auto &ignore : this->memos.ignores)
+ for (const auto &ignore : nc->memos.ignores)
oss << ignore << " ";
data.Store("memoignores", oss.str());
- Extensible::ExtensibleSerialize(this, this, data);
+ Extensible::ExtensibleSerialize(nc, nc, data);
}
-Serializable *NickCore::Unserialize(Serializable *obj, Serialize::Data &data)
+Serializable *NickCore::Type::Unserialize(Serializable *obj, Serialize::Data &data) const
{
NickCore *nc;
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;
diff --git a/src/serialize.cpp b/src/serialize.cpp
index a90c0e7a8..e365ba01c 100644
--- a/src/serialize.cpp
+++ b/src/serialize.cpp
@@ -27,9 +27,14 @@ std::list<Serializable *> *Serializable::SerializableItems;
void Serialize::RegisterTypes()
{
- static Type nc("NickCore", NickCore::Unserialize), na("NickAlias", NickAlias::Unserialize), bi("BotInfo", BotInfo::Unserialize),
- ci("ChannelInfo", ChannelInfo::Unserialize), access("ChanAccess", ChanAccess::Unserialize),
- akick("AutoKick", AutoKick::Unserialize), memo("Memo", Memo::Unserialize), xline("XLine", XLine::Unserialize);
+ static NickCore::Type nc;
+ static NickAlias::Type na;
+ static BotInfo::Type bi;
+ static ChannelInfo::Type ci;
+ static ChanAccess::Type access;
+ static AutoKick::Type akick;
+ static Memo::Type memo;
+ static XLine::Type xline;
}
void Serialize::CheckTypes()
@@ -124,7 +129,9 @@ void Serialize::Data::SetType(const Anope::string &key, Serialize::DataType dt)
this->types[key] = dt;
}
-Type::Type(const Anope::string &n, unserialize_func f, Module *o) : name(n), unserialize(f), owner(o)
+Type::Type(const Anope::string &n, Module *o)
+ : name(n)
+ , owner(o)
{
TypeOrder.push_back(this->name);
Types[this->name] = this;
@@ -150,11 +157,6 @@ Type::~Type()
Types.erase(this->name);
}
-Serializable *Type::Unserialize(Serializable *obj, Serialize::Data &data)
-{
- return this->unserialize(obj, data);
-}
-
void Type::Check()
{
FOREACH_MOD(OnSerializeCheck, (this));
diff --git a/src/xline.cpp b/src/xline.cpp
index 9e8dd41bf..eca34cda2 100644
--- a/src/xline.cpp
+++ b/src/xline.cpp
@@ -151,19 +151,26 @@ bool XLine::IsRegex() const
return !this->mask.empty() && this->mask[0] == '/' && this->mask[this->mask.length() - 1] == '/';
}
-void XLine::Serialize(Serialize::Data &data) const
+XLine::Type::Type()
+ : Serialize::Type("XLine")
{
- data.Store("mask", this->mask);
- data.Store("by", this->by);
- data.Store("created", this->created);
- data.Store("expires", this->expires);
- data.Store("reason", this->reason);
- data.Store("uid", this->id);
- if (this->manager)
- data.Store("manager", this->manager->name);
}
-Serializable *XLine::Unserialize(Serializable *obj, Serialize::Data &data)
+void XLine::Type::Serialize(const Serializable *obj, Serialize::Data &data) const
+{
+ const auto *xl = static_cast<const XLine *>(obj);
+
+ data.Store("mask", xl->mask);
+ data.Store("by", xl->by);
+ data.Store("created", xl->created);
+ data.Store("expires", xl->expires);
+ data.Store("reason", xl->reason);
+ data.Store("uid", xl->id);
+ if (xl->manager)
+ data.Store("manager", xl->manager->name);
+}
+
+Serializable *XLine::Type::Unserialize(Serializable *obj, Serialize::Data &data) const
{
Anope::string smanager;