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 /include | |
parent | 718f2e922a6e1113d66fc6e96131213942d507b2 (diff) |
Move serialization from Serializable to a Serialize::Type child.
Diffstat (limited to 'include')
-rw-r--r-- | include/access.h | 13 | ||||
-rw-r--r-- | include/account.h | 26 | ||||
-rw-r--r-- | include/bots.h | 10 | ||||
-rw-r--r-- | include/memo.h | 11 | ||||
-rw-r--r-- | include/modules/operserv/oper.h | 30 | ||||
-rw-r--r-- | include/modules/operserv/session.h | 34 | ||||
-rw-r--r-- | include/regchannel.h | 24 | ||||
-rw-r--r-- | include/serialize.h | 13 | ||||
-rw-r--r-- | include/xline.h | 13 |
9 files changed, 80 insertions, 94 deletions
diff --git a/include/access.h b/include/access.h index ad420d785..aa1430b7e 100644 --- a/include/access.h +++ b/include/access.h @@ -74,6 +74,16 @@ public: class CoreExport ChanAccess : public Serializable { +public: + struct Type final + : public Serialize::Type + { + Type(); + void Serialize(const Serializable *obj, Serialize::Data &data) const override; + Serializable *Unserialize(Serializable *obj, Serialize::Data &data) const override; + }; + +private: Anope::string mask; /* account this access entry is for, if any */ Serialize::Reference<NickCore> nc; @@ -97,9 +107,6 @@ public: const Anope::string &Mask() const; NickCore *GetAccount() const; - void Serialize(Serialize::Data &data) const override; - static Serializable *Unserialize(Serializable *obj, Serialize::Data &); - static const unsigned int MAX_DEPTH = 4; /** Check if this access entry matches the given user or account diff --git a/include/account.h b/include/account.h index 5c2e52fd2..02e71ac38 100644 --- a/include/account.h +++ b/include/account.h @@ -32,6 +32,16 @@ class CoreExport NickAlias final : public Serializable , public Extensible { +public: + struct Type final + : public Serialize::Type + { + Type(); + void Serialize(const Serializable *obj, Serialize::Data &data) const override; + Serializable *Unserialize(Serializable *obj, Serialize::Data &data) const override; + }; + +private: Anope::string vhost_ident, vhost_host, vhost_creator; time_t vhost_created = 0; @@ -56,9 +66,6 @@ public: NickAlias(const Anope::string &nickname, NickCore *nickcore); ~NickAlias(); - void Serialize(Serialize::Data &data) const override; - static Serializable *Unserialize(Serializable *obj, Serialize::Data &); - /** Set a vhost for the user * @param ident The ident * @param host The host @@ -116,6 +123,16 @@ class CoreExport NickCore final : public Serializable , public Extensible { +public: + struct Type final + : public Serialize::Type + { + Type(); + void Serialize(const Serializable *obj, Serialize::Data &data) const override; + Serializable *Unserialize(Serializable *obj, Serialize::Data &data) const override; + }; + +private: /* Channels which reference this core in some way (this is on their access list, akick list, is founder, successor, etc) */ Serialize::Checker<std::map<ChannelInfo *, int> > chanaccess; /* Unique identifier for the account. */ @@ -159,9 +176,6 @@ public: NickCore(const Anope::string &nickdisplay, uint64_t nickid = 0); ~NickCore(); - void Serialize(Serialize::Data &data) const override; - static Serializable *Unserialize(Serializable *obj, Serialize::Data &); - /** Changes the display for this account * @param na The new display, must be grouped to this account. */ diff --git a/include/bots.h b/include/bots.h index 5a9c54a3e..d5e935d14 100644 --- a/include/bots.h +++ b/include/bots.h @@ -23,6 +23,16 @@ class CoreExport BotInfo final : public User , public Serializable { +public: + struct Type final + : public Serialize::Type + { + Type(); + void Serialize(const Serializable *obj, Serialize::Data &data) const override; + Serializable *Unserialize(Serializable *obj, Serialize::Data &data) const override; + }; + +private: /* Channels this bot is assigned to */ Serialize::Checker<std::set<ChannelInfo *> > channels; public: diff --git a/include/memo.h b/include/memo.h index dca35ea8e..4d5a43af2 100644 --- a/include/memo.h +++ b/include/memo.h @@ -18,15 +18,20 @@ class CoreExport Memo final : public Serializable { public: + struct Type final + : public Serialize::Type + { + Type(); + void Serialize(const Serializable *obj, Serialize::Data &data) const override; + Serializable *Unserialize(Serializable *obj, Serialize::Data &data) const override; + }; + MemoInfo *mi; bool unread; bool receipt; Memo(); ~Memo(); - void Serialize(Serialize::Data &data) const override; - static Serializable *Unserialize(Serializable *obj, Serialize::Data &); - Anope::string owner; /* When it was sent */ time_t time; diff --git a/include/modules/operserv/oper.h b/include/modules/operserv/oper.h index 154b6af08..60511d7b5 100644 --- a/include/modules/operserv/oper.h +++ b/include/modules/operserv/oper.h @@ -13,34 +13,4 @@ struct MyOper final , Serializable { MyOper(const Anope::string &n, OperType *o) : Oper(n, o), Serializable("Oper") { } - - void Serialize(Serialize::Data &data) const override - { - data.Store("name", this->name); - data.Store("type", this->ot->GetName()); - } - - static Serializable *Unserialize(Serializable *obj, Serialize::Data &data) - { - Anope::string stype, sname; - - data["type"] >> stype; - data["name"] >> sname; - - OperType *ot = OperType::Find(stype); - if (ot == NULL) - return NULL; - NickCore *nc = NickCore::Find(sname); - if (nc == NULL) - return NULL; - - MyOper *myo; - if (obj) - myo = anope_dynamic_static_cast<MyOper *>(obj); - else - myo = new MyOper(nc->display, ot); - nc->o = myo; - Log(LOG_NORMAL, "operserv/oper") << "Tied oper " << nc->display << " to type " << ot->GetName(); - return myo; - } }; diff --git a/include/modules/operserv/session.h b/include/modules/operserv/session.h index 0f25f669e..c7f5a67e7 100644 --- a/include/modules/operserv/session.h +++ b/include/modules/operserv/session.h @@ -28,8 +28,6 @@ struct Exception final time_t expires; /* Time when it expires. 0 == no expiry */ Exception() : Serializable("Exception") { } - void Serialize(Serialize::Data &data) const override; - static Serializable *Unserialize(Serializable *obj, Serialize::Data &data); }; class SessionService @@ -59,35 +57,3 @@ public: }; static ServiceReference<SessionService> session_service("SessionService", "session"); - -void Exception::Serialize(Serialize::Data &data) const -{ - data.Store("mask", this->mask); - data.Store("limit", this->limit); - data.Store("who", this->who); - data.Store("reason", this->reason); - data.Store("time", this->time); - data.Store("expires", this->expires); -} - -Serializable *Exception::Unserialize(Serializable *obj, Serialize::Data &data) -{ - if (!session_service) - return NULL; - - Exception *ex; - if (obj) - ex = anope_dynamic_static_cast<Exception *>(obj); - else - ex = new Exception; - data["mask"] >> ex->mask; - data["limit"] >> ex->limit; - data["who"] >> ex->who; - data["reason"] >> ex->reason; - data["time"] >> ex->time; - data["expires"] >> ex->expires; - - if (!obj) - session_service->AddException(ex); - return ex; -} diff --git a/include/regchannel.h b/include/regchannel.h index 9a7bf9880..22e3a0474 100644 --- a/include/regchannel.h +++ b/include/regchannel.h @@ -25,6 +25,14 @@ class CoreExport AutoKick final : public Serializable { public: + struct Type final + : public Serialize::Type + { + Type(); + void Serialize(const Serializable *obj, Serialize::Data &data) const override; + Serializable *Unserialize(Serializable *obj, Serialize::Data &data) const override; + }; + /* Channel this autokick is on */ Serialize::Reference<ChannelInfo> ci; @@ -38,8 +46,6 @@ public: AutoKick(); ~AutoKick(); - void Serialize(Serialize::Data &data) const override; - static Serializable *Unserialize(Serializable *obj, Serialize::Data &); }; /* It matters that Base is here before Extensible (it is inherited by Serializable) @@ -48,9 +54,18 @@ class CoreExport ChannelInfo final : public Serializable , public Extensible { +public: + struct Type final + : public Serialize::Type + { + Type(); + void Serialize(const Serializable *obj, Serialize::Data &data) const override; + Serializable *Unserialize(Serializable *obj, Serialize::Data &data) const override; + }; + +private: /* channels who reference this one */ Anope::map<int> references; -private: Serialize::Reference<NickCore> founder; /* Channel founder */ Serialize::Reference<NickCore> successor; /* Who gets the channel if the founder nick is dropped or expires */ Serialize::Checker<std::vector<ChanAccess *> > access; /* List of authorized users */ @@ -97,9 +112,6 @@ public: ~ChannelInfo(); ChannelInfo &operator=(const ChannelInfo &) = default; - void Serialize(Serialize::Data &data) const override; - static Serializable *Unserialize(Serializable *obj, Serialize::Data &); - /** Change the founder of the channel * @params nc The new founder */ diff --git a/include/serialize.h b/include/serialize.h index dd721e693..c212f432f 100644 --- a/include/serialize.h +++ b/include/serialize.h @@ -123,8 +123,6 @@ public: */ Serialize::Type *GetSerializableType() const { return this->s_type; } - virtual void Serialize(Serialize::Data &data) const = 0; - static const std::list<Serializable *> &GetItems(); }; @@ -132,17 +130,14 @@ public: * of class that inherits from Serializable. Used for unserializing objects * of this type, as it requires a function pointer to a static member function. */ -class CoreExport Serialize::Type final +class CoreExport Serialize::Type : public Base { - typedef Serializable *(*unserialize_func)(Serializable *obj, Serialize::Data &); - static std::vector<Anope::string> TypeOrder; static std::map<Anope::string, Serialize::Type *> Types; /* The name of this type, should be a class name */ Anope::string name; - unserialize_func unserialize; /* Owner of this type. Used for placing objects of this type in separate databases * based on what module, if any, owns it. */ @@ -160,10 +155,9 @@ public: /** Creates a new serializable type * @param n Type name - * @param f Func to unserialize objects * @param owner Owner of this type. Leave NULL for the core. */ - Type(const Anope::string &n, unserialize_func f, Module *owner = NULL); + Type(const Anope::string &n, Module *owner = NULL); ~Type(); /** Gets the name for this type @@ -177,7 +171,8 @@ public: * @param data The data to unserialize * @return The unserialized object. If obj != NULL this should be obj. */ - Serializable *Unserialize(Serializable *obj, Serialize::Data &data); + virtual void Serialize(const Serializable *obj, Serialize::Data &data) const = 0; + virtual Serializable *Unserialize(Serializable *obj, Serialize::Data &data) const = 0; /** Check if this object type has any pending changes and update them. */ diff --git a/include/xline.h b/include/xline.h index ebd88e928..2db1d4b4a 100644 --- a/include/xline.h +++ b/include/xline.h @@ -16,6 +16,16 @@ class CoreExport XLine final : public Serializable { +public: + struct Type final + : public Serialize::Type + { + Type(); + void Serialize(const Serializable *obj, Serialize::Data &data) const override; + Serializable *Unserialize(Serializable *obj, Serialize::Data &data) const override; + }; + +private: void Init(); Anope::string nick, user, host, real; public: @@ -43,9 +53,6 @@ public: bool HasNickOrReal() const; bool IsRegex() const; - - void Serialize(Serialize::Data &data) const override; - static Serializable *Unserialize(Serializable *obj, Serialize::Data &data); }; /* Managers XLines. There is one XLineManager per type of XLine. */ |