mirror of
https://github.com/anope/anope.git
synced 2026-07-07 12:43:13 +02:00
Move serialization from Serializable to a Serialize::Type child.
This commit is contained in:
+17
-10
@@ -158,19 +158,26 @@ NickCore *ChanAccess::GetAccount() const
|
||||
return nc;
|
||||
}
|
||||
|
||||
void ChanAccess::Serialize(Serialize::Data &data) const
|
||||
|
||||
ChanAccess::Type::Type()
|
||||
: Serialize::Type("ChanAccess")
|
||||
{
|
||||
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());
|
||||
}
|
||||
|
||||
Serializable *ChanAccess::Unserialize(Serializable *obj, Serialize::Data &data)
|
||||
void ChanAccess::Type::Serialize(const Serializable *obj, Serialize::Data &data) const
|
||||
{
|
||||
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::Type::Unserialize(Serializable *obj, Serialize::Data &data) const
|
||||
{
|
||||
Anope::string provider, chan;
|
||||
|
||||
|
||||
+16
-10
@@ -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;
|
||||
|
||||
|
||||
+14
-8
@@ -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;
|
||||
|
||||
|
||||
+26
-20
@@ -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())
|
||||
{
|
||||
data.Store("vhost_ident", this->GetVHostIdent());
|
||||
data.Store("vhost_host", this->GetVHostHost());
|
||||
data.Store("vhost_creator", this->GetVHostCreator());
|
||||
data.Store("vhost_time", this->GetVHostCreated());
|
||||
}
|
||||
|
||||
Extensible::ExtensibleSerialize(this, this, data);
|
||||
}
|
||||
|
||||
Serializable *NickAlias::Unserialize(Serializable *obj, Serialize::Data &data)
|
||||
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", na->GetVHostIdent());
|
||||
data.Store("vhost_host", na->GetVHostHost());
|
||||
data.Store("vhost_creator", na->GetVHostCreator());
|
||||
data.Store("vhost_time", na->GetVHostCreated());
|
||||
}
|
||||
|
||||
Extensible::ExtensibleSerialize(na, na, data);
|
||||
}
|
||||
|
||||
Serializable *NickAlias::Type::Unserialize(Serializable *obj, Serialize::Data &data) const
|
||||
{
|
||||
Anope::string snc, snick;
|
||||
|
||||
|
||||
+18
-12
@@ -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;
|
||||
|
||||
|
||||
+45
-32
@@ -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);
|
||||
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);
|
||||
}
|
||||
|
||||
Serializable *AutoKick::Unserialize(Serializable *obj, Serialize::Data &data)
|
||||
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", 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::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;
|
||||
|
||||
|
||||
+11
-9
@@ -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));
|
||||
|
||||
+17
-10
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user