summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/bots.h6
-rw-r--r--include/modules/chanserv/chanaccess.h10
-rw-r--r--include/modules/nickserv/account.h2
-rw-r--r--include/opertype.h4
-rw-r--r--include/serialize.h106
-rw-r--r--include/xline.h4
-rw-r--r--modules/botserv/badwords.cpp9
-rw-r--r--modules/botserv/kick.cpp67
-rw-r--r--modules/chanserv/access.cpp2
-rw-r--r--modules/chanserv/akick.cpp11
-rw-r--r--modules/chanserv/entrymsg.cpp9
-rw-r--r--modules/chanserv/flags.cpp2
-rw-r--r--modules/chanserv/log.cpp9
-rw-r--r--modules/chanserv/main/channel.h51
-rw-r--r--modules/chanserv/main/level.h9
-rw-r--r--modules/chanserv/main/mode.h7
-rw-r--r--modules/chanserv/mode.cpp11
-rw-r--r--modules/chanserv/set_misc.cpp7
-rw-r--r--modules/chanserv/suspend.cpp9
-rw-r--r--modules/chanserv/xop.cpp2
-rw-r--r--modules/database/sql.cpp24
-rw-r--r--modules/hostserv/main/vhost.h12
-rw-r--r--modules/hostserv/request.cpp9
-rw-r--r--modules/memoserv/main/ignore.h7
-rw-r--r--modules/memoserv/main/memo.h11
-rw-r--r--modules/memoserv/main/memoinfo.h9
-rw-r--r--modules/nickserv/access.cpp7
-rw-r--r--modules/nickserv/ajoin.cpp7
-rw-r--r--modules/nickserv/cert.cpp7
-rw-r--r--modules/nickserv/main/account.cpp5
-rw-r--r--modules/nickserv/main/account.h30
-rw-r--r--modules/nickserv/main/mode.h7
-rw-r--r--modules/nickserv/main/nick.h11
-rw-r--r--modules/nickserv/set_misc.cpp7
-rw-r--r--modules/nickserv/suspend.cpp9
-rw-r--r--modules/operserv/dns.cpp27
-rw-r--r--modules/operserv/forbid.cpp9
-rw-r--r--modules/operserv/ignore.cpp7
-rw-r--r--modules/operserv/info.cpp9
-rw-r--r--modules/operserv/news.cpp9
-rw-r--r--modules/operserv/session.cpp9
-rw-r--r--modules/operserv/stats.cpp5
-rw-r--r--src/serialize.cpp41
43 files changed, 308 insertions, 307 deletions
diff --git a/include/bots.h b/include/bots.h
index 0fa35e8a1..928107ef3 100644
--- a/include/bots.h
+++ b/include/bots.h
@@ -133,9 +133,9 @@ class BotInfo : public Serialize::Object
{
friend class BotInfoType;
- Anope::string nick, user, host, realname;
- time_t created = 0;
- bool operonly = false;
+ Serialize::Storage<Anope::string> nick, user, host, realname;
+ Serialize::Storage<time_t> created;
+ Serialize::Storage<bool> operonly;
public:
static constexpr const char *const NAME = "botinfo";
diff --git a/include/modules/chanserv/chanaccess.h b/include/modules/chanserv/chanaccess.h
index 2d3aec96b..faaf48175 100644
--- a/include/modules/chanserv/chanaccess.h
+++ b/include/modules/chanserv/chanaccess.h
@@ -34,10 +34,10 @@ class CoreExport ChanAccess : public Serialize::Object
public:
static constexpr const char *const NAME = "access";
- Channel *channel = nullptr;
- Serialize::Object *object = nullptr;
- Anope::string creator, mask;
- time_t last_seen = 0, created = 0;
+ Serialize::Storage<Channel *> channel;
+ Serialize::Storage<Serialize::Object *> object;
+ Serialize::Storage<Anope::string> creator, mask;
+ Serialize::Storage<time_t> last_seen, created;
using Serialize::Object::Object;
@@ -131,4 +131,4 @@ class CoreExport ChanAccess : public Serialize::Object
}
};
-} // namespace ChanServ \ No newline at end of file
+} // namespace ChanServ
diff --git a/include/modules/nickserv/account.h b/include/modules/nickserv/account.h
index 511b1220f..ebe1061b6 100644
--- a/include/modules/nickserv/account.h
+++ b/include/modules/nickserv/account.h
@@ -30,7 +30,7 @@ class CoreExport Account : public Serialize::Object
public:
static constexpr const char *const NAME = "account";
-#warning "this gets lost"
+#warning "move lastmail to a field"
/* Last time an email was sent to this user */
time_t lastmail = 0;
/* Users online now logged into this account */
diff --git a/include/opertype.h b/include/opertype.h
index 2d36dfad6..46361d576 100644
--- a/include/opertype.h
+++ b/include/opertype.h
@@ -27,8 +27,8 @@ class Oper : public Serialize::Object
{
friend class OperBlockType;
- Anope::string name, password, certfp, host, vhost, type;
- bool require_oper = false;
+ Serialize::Storage<Anope::string> name, password, certfp, host, vhost, type;
+ Serialize::Storage<bool> require_oper;
public:
static constexpr const char *const NAME = "oper";
diff --git a/include/serialize.h b/include/serialize.h
index 0b420bff0..67be96c0c 100644
--- a/include/serialize.h
+++ b/include/serialize.h
@@ -36,6 +36,8 @@ namespace Serialize
template<typename, typename> class Field;
template<typename, typename> class ObjectField;
+ template<typename> class Storage;
+
template<typename T, typename> class Type;
template<typename T> class Reference;
@@ -60,7 +62,7 @@ namespace Serialize
template<typename T>
inline T New();
- extern void Clear();
+ extern void GC();
extern void Unregister(Module *);
@@ -216,16 +218,21 @@ class CoreExport Serialize::Object : public Extensible, public virtual Base
* which can unset (vs set to the default value)
*/
bool HasFieldS(const Anope::string &name);
+
+ /** Whether or not the object can be garbage collected.
+ * Should be true unless your object holds in-memory only
+ * state.
+ */
+ virtual bool CanGC() { return true; }
+
+ void Wipe();
};
class CoreExport Serialize::TypeBase : public Service
{
Anope::string name;
- /* Owner of this type. Used for placing objects of this type in separate databases
- * based on what module, if any, owns it.
- */
- Module *owner;
+ Module *owner = nullptr;
public:
static constexpr const char *NAME = "typebase";
@@ -396,6 +403,8 @@ class Serialize::FieldBase : public Service
*/
virtual void UnsetS(Object *) anope_abstract;
+ virtual void Uncache(Object *) anope_abstract;
+
virtual Anope::string GetTypeName() { return ""; }
};
@@ -426,18 +435,21 @@ class Serialize::CommonFieldBase : public FieldTypeBase<T>
*/
ExtensibleItem<T> *ext = nullptr;
- /** Field pointer to storage in the TypeImpl object for
- * this field.
+ /** Storage pointer in the TypeImpl object for this field.
*/
- T TypeImpl::*field = nullptr;
+ Serialize::Storage<T> TypeImpl::*storage = nullptr;
protected:
/** Set the value of a field in storage
*/
void Set_(TypeImpl *object, const T &value)
{
- if (field != nullptr)
- object->*field = value;
+ if (storage != nullptr)
+ {
+ Serialize::Storage<T> &s = object->*storage;
+ s.t = value;
+ s.cached = true;
+ }
else if (ext != nullptr)
ext->Set(object, value);
else
@@ -448,8 +460,8 @@ class Serialize::CommonFieldBase : public FieldTypeBase<T>
*/
T* Get_(TypeImpl *object)
{
- if (field != nullptr)
- return &(object->*field);
+ if (storage != nullptr)
+ return &(object->*storage).t;
else if (ext != nullptr)
return ext->Get(object);
else
@@ -460,8 +472,12 @@ class Serialize::CommonFieldBase : public FieldTypeBase<T>
*/
void Unset_(TypeImpl *object)
{
- if (field != nullptr)
- object->*field = T();
+ if (storage != nullptr)
+ {
+ Serialize::Storage<T> &s = object->*storage;
+ s.t = T();
+ s.cached = false;
+ }
else if (ext != nullptr)
ext->Unset(object);
else
@@ -473,7 +489,7 @@ class Serialize::CommonFieldBase : public FieldTypeBase<T>
*/
bool HasField_(TypeImpl *object)
{
- if (field != nullptr)
+ if (storage != nullptr)
return true;
else if (ext != nullptr)
return ext->HasExt(object);
@@ -481,13 +497,17 @@ class Serialize::CommonFieldBase : public FieldTypeBase<T>
throw CoreException("No field or ext");
}
- public:
- CommonFieldBase(Serialize::TypeBase *t, const Anope::string &n, bool d)
- : FieldTypeBase<T>(t->GetOwner(), n, t->GetName(), d)
+ bool Cached_(TypeImpl *object)
{
- ext = new ExtensibleItem<T>(t->GetOwner(), t->GetName(), n);
+ if (storage != nullptr)
+ return (object->*storage).cached;
+ else if (ext != nullptr)
+ return ext->HasExt(object);
+ else
+ throw CoreException("No field or ext");
}
+ public:
CommonFieldBase(Module *creator, const Anope::string &n, bool d)
: FieldTypeBase<T>(creator, n, TypeImpl::NAME, d)
{
@@ -496,10 +516,10 @@ class Serialize::CommonFieldBase : public FieldTypeBase<T>
CommonFieldBase(Serialize::TypeBase *t,
const Anope::string &n,
- T TypeImpl::*f,
+ Serialize::Storage<T> TypeImpl::*s,
bool d)
: FieldTypeBase<T>(t->GetOwner(), n, t->GetName(), d)
- , field(f)
+ , storage(s)
{
}
@@ -547,6 +567,11 @@ class Serialize::CommonFieldBase : public FieldTypeBase<T>
return this->HasField_(s);
}
+
+ void Uncache(Object *s)
+ {
+ Unset_(Upcast(s));
+ }
};
/** Class for all fields that aren't to other serializable objects
@@ -555,15 +580,11 @@ template<typename TypeImpl, typename T>
class Serialize::Field : public CommonFieldBase<TypeImpl, T>
{
public:
- Field(TypeBase *t, const Anope::string &n) : CommonFieldBase<TypeImpl, T>(t, n, false)
- {
- }
-
Field(Module *creator, const Anope::string &n) : CommonFieldBase<TypeImpl, T>(creator, n, false)
{
}
- Field(TypeBase *t, const Anope::string &n, T TypeImpl::*f) : CommonFieldBase<TypeImpl, T>(t, n, f, false)
+ Field(TypeBase *t, const Anope::string &n, Serialize::Storage<T> TypeImpl::*f) : CommonFieldBase<TypeImpl, T>(t, n, f, false)
{
}
@@ -571,8 +592,8 @@ class Serialize::Field : public CommonFieldBase<TypeImpl, T>
{
T* t = this->Get_(s);
- // If we have a non-default value for this field it is up to date and cached
- if (t && *t != T())
+ // If this field is cached
+ if (t && this->Cached_(s))
return *t;
// Query modules
@@ -583,19 +604,14 @@ class Serialize::Field : public CommonFieldBase<TypeImpl, T>
// module returned us data, so we unserialize it
T t2 = this->Unserialize(value);
- // should cache the default value somehow, but can't differentiate not cached from cached and default
-
- // Cache
+ // set & cache
OnSet(s, t2);
this->Set_(s, t2);
return t2;
}
- if (t)
- return *t;
-
- return T();
+ return t ? *t : T();
}
void SetFieldS(Object *s, const T &value) override
@@ -696,12 +712,12 @@ template<typename TypeImpl, typename T>
class Serialize::ObjectField : public CommonFieldBase<TypeImpl, T>
{
public:
- ObjectField(TypeBase *t, const Anope::string &n, bool d = false) : CommonFieldBase<TypeImpl, T>(t, n, d)
+ ObjectField(Module *creator, const Anope::string &n) : CommonFieldBase<TypeImpl, T>(creator, n, false)
{
this->is_object = true;
}
- ObjectField(TypeBase *t, const Anope::string &n, T TypeImpl::*field, bool d = false) : CommonFieldBase<TypeImpl, T>(t, n, field, d)
+ ObjectField(TypeBase *t, const Anope::string &n, Serialize::Storage<T> TypeImpl::*field, bool d = false) : CommonFieldBase<TypeImpl, T>(t, n, field, d)
{
this->is_object = true;
}
@@ -709,7 +725,8 @@ class Serialize::ObjectField : public CommonFieldBase<TypeImpl, T>
T GetField(TypeImpl *s)
{
T *t = this->Get_(s);
- if (t && *t != nullptr)
+
+ if (t && this->Cached_(s))
return *t;
Anope::string type;
@@ -732,10 +749,7 @@ class Serialize::ObjectField : public CommonFieldBase<TypeImpl, T>
return t2;
}
- if (t)
- return *t;
-
- return T();
+ return t ? *t : T();
}
void SetFieldS(Object *s, const T &value) override
@@ -818,6 +832,14 @@ class Serialize::ObjectField : public CommonFieldBase<TypeImpl, T>
};
template<typename T>
+class Serialize::Storage
+{
+ public:
+ T t = T();
+ bool cached = false;
+};
+
+template<typename T>
T Serialize::GetObject()
{
std::vector<T> v = GetObjects<T>();
diff --git a/include/xline.h b/include/xline.h
index 05ddbe2d3..cc4a98d66 100644
--- a/include/xline.h
+++ b/include/xline.h
@@ -32,8 +32,8 @@ class CoreExport XLine : public Serialize::Object
friend class XLineType;
- Anope::string type, mask, by, reason, id;
- time_t created = 0, expires = 0;
+ Serialize::Storage<Anope::string> type, mask, by, reason, id;
+ Serialize::Storage<time_t> created, expires;
public:
static constexpr const char *const NAME = "xline";
diff --git a/modules/botserv/badwords.cpp b/modules/botserv/badwords.cpp
index 914e89ea9..754e202a7 100644
--- a/modules/botserv/badwords.cpp
+++ b/modules/botserv/badwords.cpp
@@ -24,13 +24,12 @@ class BadWordImpl : public BadWord
{
friend class BadWordsType;
- ChanServ::Channel *channel = nullptr;
- Anope::string word;
- BadWordType type;
+ Serialize::Storage<ChanServ::Channel *> channel;
+ Serialize::Storage<Anope::string> word;
+ Serialize::Storage<BadWordType> type;
public:
- BadWordImpl(Serialize::TypeBase *type) : BadWord(type) { }
- BadWordImpl(Serialize::TypeBase *type, Serialize::ID id) : BadWord(type, id) { }
+ using BadWord::BadWord;
ChanServ::Channel *GetChannel() override;
void SetChannel(ChanServ::Channel *c) override;
diff --git a/modules/botserv/kick.cpp b/modules/botserv/kick.cpp
index 4411ee4ed..20af77d1c 100644
--- a/modules/botserv/kick.cpp
+++ b/modules/botserv/kick.cpp
@@ -43,42 +43,41 @@ class KickerDataImpl : public KickerData
{
friend class KickerDataType;
- ChanServ::Channel *channel = nullptr;
-
- bool amsgs = false,
- badwords = false,
- bolds = false,
- caps = false,
- colors = false,
- flood = false,
- italics = false,
- repeat = false,
- reverses = false,
- underlines = false;
-
- int16_t ttb_bolds = 0,
- ttb_colors = 0,
- ttb_reverses = 0,
- ttb_underlines = 0,
- ttb_badwords = 0,
- ttb_caps = 0,
- ttb_flood = 0,
- ttb_repeat = 0,
- ttb_italics = 0,
- ttb_amsgs = 0;
-
- int16_t capsmin = 0,
- capspercent = 0,
- floodlines = 0,
- floodsecs = 0,
- repeattimes = 0;
-
- bool dontkickops = false,
- dontkickvoices = false;
+ Serialize::Storage<ChanServ::Channel *> channel;
+
+ Serialize::Storage<bool> amsgs,
+ badwords,
+ bolds,
+ caps,
+ colors,
+ flood,
+ italics,
+ repeat,
+ reverses,
+ underlines;
+
+ Serialize::Storage<int16_t> ttb_bolds,
+ ttb_colors,
+ ttb_reverses,
+ ttb_underlines,
+ ttb_badwords,
+ ttb_caps,
+ ttb_flood,
+ ttb_repeat,
+ ttb_italics,
+ ttb_amsgs;
+
+ Serialize::Storage<int16_t> capsmin,
+ capspercent,
+ floodlines,
+ floodsecs,
+ repeattimes;
+
+ Serialize::Storage<bool> dontkickops,
+ dontkickvoices;
public:
- KickerDataImpl(Serialize::TypeBase *type) : KickerData(type) { }
- KickerDataImpl(Serialize::TypeBase *type, Serialize::ID id) : KickerData(type, id) { }
+ using KickerData::KickerData;
ChanServ::Channel *GetChannel() override;
void SetChannel(ChanServ::Channel *) override;
diff --git a/modules/chanserv/access.cpp b/modules/chanserv/access.cpp
index 82a11831f..967df9025 100644
--- a/modules/chanserv/access.cpp
+++ b/modules/chanserv/access.cpp
@@ -29,7 +29,7 @@ class AccessChanAccessImpl : public AccessChanAccess
{
friend class AccessChanAccessType;
- int level = 0;
+ Serialize::Storage<int> level;
public:
static constexpr const char *NAME = "accesschanaccess";
diff --git a/modules/chanserv/akick.cpp b/modules/chanserv/akick.cpp
index 1930cb20b..9338a4dd7 100644
--- a/modules/chanserv/akick.cpp
+++ b/modules/chanserv/akick.cpp
@@ -24,14 +24,13 @@ class AutoKickImpl : public AutoKick
{
friend class AutoKickType;
- ChanServ::Channel *channel = nullptr;
- NickServ::Account *account = nullptr;
- Anope::string mask, reason, creator;
- time_t addtime = 0, last_time = 0;
+ Serialize::Storage<ChanServ::Channel *> channel;
+ Serialize::Storage<NickServ::Account *> account;
+ Serialize::Storage<Anope::string> mask, reason, creator;
+ Serialize::Storage<time_t> addtime, last_time;
public:
- AutoKickImpl(Serialize::TypeBase *type) : AutoKick(type) { }
- AutoKickImpl(Serialize::TypeBase *type, Serialize::ID id) : AutoKick(type, id) { }
+ using AutoKick::AutoKick;
ChanServ::Channel *GetChannel() override;
void SetChannel(ChanServ::Channel *ci) override;
diff --git a/modules/chanserv/entrymsg.cpp b/modules/chanserv/entrymsg.cpp
index 4f74834bd..c739ba46a 100644
--- a/modules/chanserv/entrymsg.cpp
+++ b/modules/chanserv/entrymsg.cpp
@@ -24,13 +24,12 @@ class EntryMsgImpl : public EntryMsg
{
friend class EntryMsgType;
- ChanServ::Channel *channel = nullptr;
- Anope::string creator, message;
- time_t when = 0;
+ Serialize::Storage<ChanServ::Channel *> channel;
+ Serialize::Storage<Anope::string> creator, message;
+ Serialize::Storage<time_t> when;
public:
- EntryMsgImpl(Serialize::TypeBase *type) : EntryMsg(type) { }
- EntryMsgImpl(Serialize::TypeBase *type, Serialize::ID id) : EntryMsg(type, id) { }
+ using EntryMsg::EntryMsg;
ChanServ::Channel *GetChannel() override;
void SetChannel(ChanServ::Channel *ci) override;
diff --git a/modules/chanserv/flags.cpp b/modules/chanserv/flags.cpp
index 446eeddd0..4732aff5b 100644
--- a/modules/chanserv/flags.cpp
+++ b/modules/chanserv/flags.cpp
@@ -31,7 +31,7 @@ class FlagsChanAccessImpl : public FlagsChanAccess
{
friend class FlagsChanAccessType;
- Anope::string flags;
+ Serialize::Storage<Anope::string> flags;
public:
using FlagsChanAccess::FlagsChanAccess;
diff --git a/modules/chanserv/log.cpp b/modules/chanserv/log.cpp
index b62e03d0e..f2d782c1c 100644
--- a/modules/chanserv/log.cpp
+++ b/modules/chanserv/log.cpp
@@ -25,13 +25,12 @@ class LogSettingImpl : public LogSetting
{
friend class LogSettingType;
- ChanServ::Channel *channel = nullptr;
- Anope::string service_name, command_service, command_name, method, extra, creator;
- time_t created = 0;
+ Serialize::Storage<ChanServ::Channel *> channel;
+ Serialize::Storage<Anope::string> service_name, command_service, command_name, method, extra, creator;
+ Serialize::Storage<time_t> created;
public:
- LogSettingImpl(Serialize::TypeBase *type) : LogSetting(type) { }
- LogSettingImpl(Serialize::TypeBase *type, Serialize::ID id) : LogSetting(type, id) { }
+ using LogSetting::LogSetting;
ChanServ::Channel *GetChannel() override;
void SetChannel(ChanServ::Channel *) override;
diff --git a/modules/chanserv/main/channel.h b/modules/chanserv/main/channel.h
index fd9a357eb..bb79df3c5 100644
--- a/modules/chanserv/main/channel.h
+++ b/modules/chanserv/main/channel.h
@@ -21,34 +21,33 @@ class ChannelImpl : public ChanServ::Channel
{
friend class ChannelType;
- NickServ::Account *founder = nullptr, *successor = nullptr;
- Anope::string name, desc;
- time_t time_registered = 0, last_used = 0;
- Anope::string last_topic, last_topic_setter;
- time_t last_topic_time = 0;
- int16_t bantype = 0;
- time_t banexpire = 0;
- BotInfo *bi = nullptr;
- bool greet = false;
- bool fantasy = false;
- bool noautoop = false;
- bool peace = false;
- bool securefounder = false;
- bool restricted = false;
- bool secure = false;
- bool secureops = false;
- bool signkick = false;
- bool signkicklevel = false;
- bool noexpire = false;
- bool keepmodes = false;
- bool persist = false;
- bool topiclock = false;
- bool keeptopic = false;
- bool _private = false;
+ Serialize::Storage<NickServ::Account *> founder, successor;
+ Serialize::Storage<Anope::string> name, desc;
+ Serialize::Storage<time_t> time_registered, last_used;
+ Serialize::Storage<Anope::string> last_topic, last_topic_setter;
+ Serialize::Storage<time_t> last_topic_time;
+ Serialize::Storage<int16_t> bantype;
+ Serialize::Storage<time_t> banexpire;
+ Serialize::Storage<BotInfo *> bi;
+ Serialize::Storage<bool> greet;
+ Serialize::Storage<bool> fantasy;
+ Serialize::Storage<bool> noautoop;
+ Serialize::Storage<bool> peace;
+ Serialize::Storage<bool> securefounder;
+ Serialize::Storage<bool> restricted;
+ Serialize::Storage<bool> secure;
+ Serialize::Storage<bool> secureops;
+ Serialize::Storage<bool> signkick;
+ Serialize::Storage<bool> signkicklevel;
+ Serialize::Storage<bool> noexpire;
+ Serialize::Storage<bool> keepmodes;
+ Serialize::Storage<bool> persist;
+ Serialize::Storage<bool> topiclock;
+ Serialize::Storage<bool> keeptopic;
+ Serialize::Storage<bool> _private;
public:
- ChannelImpl(Serialize::TypeBase *type) : ChanServ::Channel(type) { }
- ChannelImpl(Serialize::TypeBase *type, Serialize::ID id) : ChanServ::Channel(type, id) { }
+ using ChanServ::Channel::Channel;
~ChannelImpl();
void Delete() override;
diff --git a/modules/chanserv/main/level.h b/modules/chanserv/main/level.h
index d22dc2831..1da1b26b5 100644
--- a/modules/chanserv/main/level.h
+++ b/modules/chanserv/main/level.h
@@ -21,13 +21,12 @@ class LevelImpl : public ChanServ::Level
{
friend class LevelType;
- ChanServ::Channel *channel = nullptr;
- Anope::string name;
- int level = 0;
+ Serialize::Storage<ChanServ::Channel *> channel;
+ Serialize::Storage<Anope::string> name;
+ Serialize::Storage<int> level;
public:
- LevelImpl(Serialize::TypeBase *type) : ChanServ::Level(type) { }
- LevelImpl(Serialize::TypeBase *type, Serialize::ID id) : ChanServ::Level(type, id) { }
+ using ChanServ::Level::Level;
ChanServ::Channel *GetChannel() override;
void SetChannel(ChanServ::Channel *) override;
diff --git a/modules/chanserv/main/mode.h b/modules/chanserv/main/mode.h
index b56360a22..de3a0315d 100644
--- a/modules/chanserv/main/mode.h
+++ b/modules/chanserv/main/mode.h
@@ -21,12 +21,11 @@ class ModeImpl : public ChanServ::Mode
{
friend class CSModeType;
- ChanServ::Channel *channel = nullptr;
- Anope::string mode, param;
+ Serialize::Storage<ChanServ::Channel *> channel;
+ Serialize::Storage<Anope::string> mode, param;
public:
- ModeImpl(Serialize::TypeBase *type) : ChanServ::Mode(type) { }
- ModeImpl(Serialize::TypeBase *type, Serialize::ID id) : ChanServ::Mode(type, id) { }
+ using ChanServ::Mode::Mode;
ChanServ::Channel *GetChannel() override;
void SetChannel(ChanServ::Channel *) override;
diff --git a/modules/chanserv/mode.cpp b/modules/chanserv/mode.cpp
index b20558bc0..5a22b4be8 100644
--- a/modules/chanserv/mode.cpp
+++ b/modules/chanserv/mode.cpp
@@ -25,14 +25,13 @@ class ModeLockImpl : public ModeLock
{
friend class ModeLockType;
- ChanServ::Channel *channel = nullptr;
- bool set = false;
- Anope::string name, param, setter;
- time_t created = 0;
+ Serialize::Storage<ChanServ::Channel *> channel;
+ Serialize::Storage<bool> set;
+ Serialize::Storage<Anope::string> name, param, setter;
+ Serialize::Storage<time_t> created;
public:
- ModeLockImpl(Serialize::TypeBase *type) : ModeLock(type) { }
- ModeLockImpl(Serialize::TypeBase *type, Serialize::ID id) : ModeLock(type, id) { }
+ using ModeLock::ModeLock;
ChanServ::Channel *GetChannel() override;
void SetChannel(ChanServ::Channel *ci) override;
diff --git a/modules/chanserv/set_misc.cpp b/modules/chanserv/set_misc.cpp
index ade42675d..7bf55dfc6 100644
--- a/modules/chanserv/set_misc.cpp
+++ b/modules/chanserv/set_misc.cpp
@@ -29,12 +29,11 @@ class CSMiscDataImpl : public CSMiscData
{
friend class CSMiscDataType;
- ChanServ::Channel *channel = nullptr;
- Anope::string name, data;
+ Serialize::Storage<ChanServ::Channel *> channel;
+ Serialize::Storage<Anope::string> name, data;
public:
- CSMiscDataImpl(Serialize::TypeBase *type) : CSMiscData(type) { }
- CSMiscDataImpl(Serialize::TypeBase *type, Serialize::ID id) : CSMiscData(type, id) { }
+ using CSMiscData::CSMiscData;
ChanServ::Channel *GetChannel() override;
void SetChannel(ChanServ::Channel *s) override;
diff --git a/modules/chanserv/suspend.cpp b/modules/chanserv/suspend.cpp
index c825c35f7..c8c451548 100644
--- a/modules/chanserv/suspend.cpp
+++ b/modules/chanserv/suspend.cpp
@@ -27,13 +27,12 @@ class CSSuspendInfoImpl : public CSSuspendInfo
{
friend class CSSuspendType;
- ChanServ::Channel *channel = nullptr;
- Anope::string by, reason;
- time_t when = 0, expires = 0;
+ Serialize::Storage<ChanServ::Channel *> channel;
+ Serialize::Storage<Anope::string> by, reason;
+ Serialize::Storage<time_t> when, expires;
public:
- CSSuspendInfoImpl(Serialize::TypeBase *type) : CSSuspendInfo(type) { }
- CSSuspendInfoImpl(Serialize::TypeBase *type, Serialize::ID id) : CSSuspendInfo(type, id) { }
+ using CSSuspendInfo::CSSuspendInfo;
ChanServ::Channel *GetChannel() override;
void SetChannel(ChanServ::Channel *s) override;
diff --git a/modules/chanserv/xop.cpp b/modules/chanserv/xop.cpp
index 4e113f25e..de5ca0c0b 100644
--- a/modules/chanserv/xop.cpp
+++ b/modules/chanserv/xop.cpp
@@ -35,7 +35,7 @@ class XOPChanAccessImpl : public XOPChanAccess
{
friend class XOPChanAccessType;
- Anope::string type;
+ Serialize::Storage<Anope::string> type;
public:
using XOPChanAccess::XOPChanAccess;
diff --git a/modules/database/sql.cpp b/modules/database/sql.cpp
index 7ca4eb6d7..1739f168d 100644
--- a/modules/database/sql.cpp
+++ b/modules/database/sql.cpp
@@ -30,21 +30,6 @@ class DBSQL : public Module, public Pipe
bool inited = false;
Anope::string prefix;
ServiceReference<Provider> SQL;
- std::unordered_multimap<Serialize::Object *, Serialize::FieldBase *> cache;
-
- void CacheMiss(Serialize::Object *object, Serialize::FieldBase *field)
- {
- cache.insert(std::make_pair(object, field));
- }
-
- bool IsCacheMiss(Serialize::Object *object, Serialize::FieldBase *field)
- {
- auto range = cache.equal_range(object);
- for (auto it = range.first; it != range.second; ++it)
- if (it->second == field)
- return true;
- return false;
- }
Result Run(const Query &query)
{
@@ -91,8 +76,7 @@ class DBSQL : public Module, public Pipe
void OnNotify() override
{
Commit();
- Serialize::Clear();
- cache.clear();
+ Serialize::GC();
}
void OnReload(Configuration::Conf *conf) override
@@ -208,14 +192,8 @@ class DBSQL : public Module, public Pipe
{
SQL::Result::Value v;
- if (IsCacheMiss(object, field))
- return EVENT_CONTINUE;
-
if (!GetValue(object, field, v))
- {
- CacheMiss(object, field);
return EVENT_CONTINUE;
- }
value = v.value;
return EVENT_ALLOW;
diff --git a/modules/hostserv/main/vhost.h b/modules/hostserv/main/vhost.h
index 90ac9140f..bdc6509d7 100644
--- a/modules/hostserv/main/vhost.h
+++ b/modules/hostserv/main/vhost.h
@@ -25,12 +25,12 @@ class VHostImpl : public HostServ::VHost
{
friend class VHostType;
- Serialize::Object *owner = nullptr;
- Anope::string vident;
- Anope::string vhost;
- Anope::string creator;
- time_t created = 0;
- bool default_ = false;
+ Serialize::Storage<Serialize::Object *> owner;
+ Serialize::Storage<Anope::string> vident;
+ Serialize::Storage<Anope::string> vhost;
+ Serialize::Storage<Anope::string> creator;
+ Serialize::Storage<time_t> created;
+ Serialize::Storage<bool> default_;
public:
using HostServ::VHost::VHost;
diff --git a/modules/hostserv/request.cpp b/modules/hostserv/request.cpp
index 7b66eb59c..9508a9abc 100644
--- a/modules/hostserv/request.cpp
+++ b/modules/hostserv/request.cpp
@@ -24,15 +24,14 @@ class HostRequest : public Serialize::Object
{
friend class HostRequestType;
- NickServ::Account *acc = nullptr;
- Anope::string ident, host;
- time_t time = 0;
+ Serialize::Storage<NickServ::Account *> acc;
+ Serialize::Storage<Anope::string> ident, host;
+ Serialize::Storage<time_t> time;
public:
static constexpr const char *const NAME = "hostrequest";
- HostRequest(Serialize::TypeBase *type) : Serialize::Object(type) { }
- HostRequest(Serialize::TypeBase *type, Serialize::ID id) : Serialize::Object(type, id) { }
+ using Serialize::Object::Object;
NickServ::Account *GetAccount();
void SetAccount(NickServ::Account *);
diff --git a/modules/memoserv/main/ignore.h b/modules/memoserv/main/ignore.h
index 3c632a74e..9edca514b 100644
--- a/modules/memoserv/main/ignore.h
+++ b/modules/memoserv/main/ignore.h
@@ -23,12 +23,11 @@ class IgnoreImpl : public MemoServ::Ignore
{
friend class IgnoreType;
- MemoServ::MemoInfo *memoinfo = nullptr;
- Anope::string mask;
+ Serialize::Storage<MemoServ::MemoInfo *> memoinfo;
+ Serialize::Storage<Anope::string> mask;
public:
- IgnoreImpl(Serialize::TypeBase *type) : MemoServ::Ignore(type) { }
- IgnoreImpl(Serialize::TypeBase *type, Serialize::ID id) : MemoServ::Ignore(type, id) { }
+ using MemoServ::Ignore::Ignore;
~IgnoreImpl();
MemoServ::MemoInfo *GetMemoInfo() override;
diff --git a/modules/memoserv/main/memo.h b/modules/memoserv/main/memo.h
index 7f34f90dd..e4f91a1ad 100644
--- a/modules/memoserv/main/memo.h
+++ b/modules/memoserv/main/memo.h
@@ -23,14 +23,13 @@ class MemoImpl : public MemoServ::Memo
{
friend class MemoType;
- MemoServ::MemoInfo *memoinfo = nullptr;
- Anope::string text, sender;
- time_t time = 0;
- bool unread = false, receipt = false;
+ Serialize::Storage<MemoServ::MemoInfo *> memoinfo;
+ Serialize::Storage<Anope::string> text, sender;
+ Serialize::Storage<time_t> time;
+ Serialize::Storage<bool> unread, receipt;
public:
- MemoImpl(Serialize::TypeBase *type) : MemoServ::Memo(type) { }
- MemoImpl(Serialize::TypeBase *type, Serialize::ID id) : MemoServ::Memo(type, id) { }
+ using MemoServ::Memo::Memo;
MemoServ::MemoInfo *GetMemoInfo() override;
void SetMemoInfo(MemoServ::MemoInfo *) override;
diff --git a/modules/memoserv/main/memoinfo.h b/modules/memoserv/main/memoinfo.h
index 3232262a3..cbe37e456 100644
--- a/modules/memoserv/main/memoinfo.h
+++ b/modules/memoserv/main/memoinfo.h
@@ -23,13 +23,12 @@ class MemoInfoImpl : public MemoServ::MemoInfo
{
friend class MemoInfoType;
- Serialize::Object *owner = nullptr;
- int16_t memomax = 0;
- bool hardmax = false;
+ Serialize::Storage<Serialize::Object *> owner;
+ Serialize::Storage<int16_t> memomax;
+ Serialize::Storage<bool> hardmax;
public:
- MemoInfoImpl(Serialize::TypeBase *type) : MemoServ::MemoInfo(type) { }
- MemoInfoImpl(Serialize::TypeBase *type, Serialize::ID id) : MemoServ::MemoInfo(type, id) { }
+ using MemoServ::MemoInfo::MemoInfo;
MemoServ::Memo *GetMemo(unsigned index) override;
unsigned GetIndex(MemoServ::Memo *m) override;
diff --git a/modules/nickserv/access.cpp b/modules/nickserv/access.cpp
index 1f3622afa..e20d81037 100644
--- a/modules/nickserv/access.cpp
+++ b/modules/nickserv/access.cpp
@@ -25,12 +25,11 @@ class NickAccessImpl : public NickAccess
{
friend class NickAccessType;
- NickServ::Account *account = nullptr;
- Anope::string mask;
+ Serialize::Storage<NickServ::Account *> account;
+ Serialize::Storage<Anope::string> mask;
public:
- NickAccessImpl(Serialize::TypeBase *type) : NickAccess(type) { }
- NickAccessImpl(Serialize::TypeBase *type, Serialize::ID id) : NickAccess(type, id) { }
+ using NickAccess::NickAccess;
NickServ::Account *GetAccount() override;
void SetAccount(NickServ::Account *) override;
diff --git a/modules/nickserv/ajoin.cpp b/modules/nickserv/ajoin.cpp
index 91039a019..5973c95ac 100644
--- a/modules/nickserv/ajoin.cpp
+++ b/modules/nickserv/ajoin.cpp
@@ -25,12 +25,11 @@ class AutoJoinImpl : public AutoJoin
{
friend class AutoJoinType;
- NickServ::Account *account = nullptr;
- Anope::string channel, key;
+ Serialize::Storage<NickServ::Account *> account;
+ Serialize::Storage<Anope::string> channel, key;
public:
- AutoJoinImpl(Serialize::TypeBase *type) : AutoJoin(type) { }
- AutoJoinImpl(Serialize::TypeBase *type, Serialize::ID id) : AutoJoin(type, id) { }
+ using AutoJoin::AutoJoin;
NickServ::Account *GetAccount() override;
void SetAccount(NickServ::Account *acc) override;
diff --git a/modules/nickserv/cert.cpp b/modules/nickserv/cert.cpp
index f58515d70..51eae0fb0 100644
--- a/modules/nickserv/cert.cpp
+++ b/modules/nickserv/cert.cpp
@@ -57,12 +57,11 @@ class NSCertEntryImpl : public NSCertEntry
{
friend class NSCertEntryType;
- NickServ::Account *account = nullptr;
- Anope::string cert;
+ Serialize::Storage<NickServ::Account *> account;
+ Serialize::Storage<Anope::string> cert;
public:
- NSCertEntryImpl(Serialize::TypeBase *type) : NSCertEntry(type) { }
- NSCertEntryImpl(Serialize::TypeBase *type, Serialize::ID id) : NSCertEntry(type, id) { }
+ using NSCertEntry::NSCertEntry;
~NSCertEntryImpl();
NickServ::Account *GetAccount() override;
diff --git a/modules/nickserv/main/account.cpp b/modules/nickserv/main/account.cpp
index fa6de8455..a6fa19adf 100644
--- a/modules/nickserv/main/account.cpp
+++ b/modules/nickserv/main/account.cpp
@@ -37,6 +37,11 @@ void AccountImpl::Delete()
return Serialize::Object::Delete();
}
+bool AccountImpl::CanGC()
+{
+ return users.empty();
+}
+
Anope::string AccountImpl::GetDisplay()
{
return Get<Anope::string>(&AccountType::display);
diff --git a/modules/nickserv/main/account.h b/modules/nickserv/main/account.h
index 928213666..ba07a2a13 100644
--- a/modules/nickserv/main/account.h
+++ b/modules/nickserv/main/account.h
@@ -23,26 +23,28 @@ class AccountImpl : public NickServ::Account
{
friend class AccountType;
- Anope::string display, password, email, language;
- Oper *oper = nullptr;
- Anope::string greet;
- bool unconfirmed = false;
- bool _private = false;
- bool autoop = false;
- bool keepmodes = false;
- bool killprotect = false;
- bool killquick = false;
- bool killimmed = false;
- bool msg = false;
- bool secure = false;
- bool memosignon = false, memoreceive = false, memomail = false;
- bool hideemail = false, hidemask = false, hidestatus = false, hidequit = false;
+ Serialize::Storage<Anope::string> display, password, email, language;
+ Serialize::Storage<Oper *> oper;
+ Serialize::Storage<Anope::string> greet;
+ Serialize::Storage<bool> unconfirmed;
+ Serialize::Storage<bool> _private;
+ Serialize::Storage<bool> autoop;
+ Serialize::Storage<bool> keepmodes;
+ Serialize::Storage<bool> killprotect;
+ Serialize::Storage<bool> killquick;
+ Serialize::Storage<bool> killimmed;
+ Serialize::Storage<bool> msg;
+ Serialize::Storage<bool> secure;
+ Serialize::Storage<bool> memosignon, memoreceive, memomail;
+ Serialize::Storage<bool> hideemail, hidemask, hidestatus, hidequit;
public:
using NickServ::Account::Account;
~AccountImpl();
void Delete() override;
+ bool CanGC() override;
+
Anope::string GetDisplay() override;
void SetDisplay(const Anope::string &) override;
diff --git a/modules/nickserv/main/mode.h b/modules/nickserv/main/mode.h
index a8db73b7e..d4246809c 100644
--- a/modules/nickserv/main/mode.h
+++ b/modules/nickserv/main/mode.h
@@ -21,12 +21,11 @@ class ModeImpl : public NickServ::Mode
{
friend class NSModeType;
- NickServ::Account *account = nullptr;
- Anope::string mode;
+ Serialize::Storage<NickServ::Account *> account;
+ Serialize::Storage<Anope::string> mode;
public:
- ModeImpl(Serialize::TypeBase *type) : NickServ::Mode(type) { }
- ModeImpl(Serialize::TypeBase *type, Serialize::ID id) : NickServ::Mode(type, id) { }
+ using NickServ::Mode::Mode;
NickServ::Account *GetAccount() override;
void SetAccount(NickServ::Account *) override;
diff --git a/modules/nickserv/main/nick.h b/modules/nickserv/main/nick.h
index 9df205fb9..df0577d94 100644
--- a/modules/nickserv/main/nick.h
+++ b/modules/nickserv/main/nick.h
@@ -21,14 +21,13 @@ class NickImpl : public NickServ::Nick
{
friend class NickType;
- NickServ::Account *account = nullptr;
- Anope::string nick, last_quit, last_realname, last_usermask, last_realhost;
- time_t time_registered = 0, last_seen = 0;
- bool noexpire = false;
+ Serialize::Storage<NickServ::Account *> account;
+ Serialize::Storage<Anope::string> nick, last_quit, last_realname, last_usermask, last_realhost;
+ Serialize::Storage<time_t> time_registered, last_seen;
+ Serialize::Storage<bool> noexpire;
public:
- NickImpl(Serialize::TypeBase *type) : NickServ::Nick(type) { }
- NickImpl(Serialize::TypeBase *type, Serialize::ID id) : NickServ::Nick(type, id) { }
+ using NickServ::Nick::Nick;
~NickImpl();
void Delete() override;
diff --git a/modules/nickserv/set_misc.cpp b/modules/nickserv/set_misc.cpp
index af0859c6b..fe1859cc7 100644
--- a/modules/nickserv/set_misc.cpp
+++ b/modules/nickserv/set_misc.cpp
@@ -28,12 +28,11 @@ class NSMiscDataImpl : public NSMiscData
{
friend class NSMiscDataType;
- NickServ::Account *account = nullptr;
- Anope::string name, data;
+ Serialize::Storage<NickServ::Account *> account;
+ Serialize::Storage<Anope::string> name, data;
public:
- NSMiscDataImpl(Serialize::TypeBase *type) : NSMiscData(type) { }
- NSMiscDataImpl(Serialize::TypeBase *type, Serialize::ID id) : NSMiscData(type, id) { }
+ using NSMiscData::NSMiscData;
NickServ::Account *GetAccount() override;
void SetAccount(NickServ::Account *s) override;
diff --git a/modules/nickserv/suspend.cpp b/modules/nickserv/suspend.cpp
index 4ac1d7456..90362bcf2 100644
--- a/modules/nickserv/suspend.cpp
+++ b/modules/nickserv/suspend.cpp
@@ -26,13 +26,12 @@ class NSSuspendInfoImpl : public NSSuspendInfo
{
friend class NSSuspendType;
- NickServ::Account *account = nullptr;
- Anope::string by, reason;
- time_t when = 0, expires = 0;
+ Serialize::Storage<NickServ::Account *> account;
+ Serialize::Storage<Anope::string> by, reason;
+ Serialize::Storage<time_t> when, expires;
public:
- NSSuspendInfoImpl(Serialize::TypeBase *type) : NSSuspendInfo(type) { }
- NSSuspendInfoImpl(Serialize::TypeBase *type, Serialize::ID id) : NSSuspendInfo(type, id) { }
+ using NSSuspendInfo::NSSuspendInfo;
NickServ::Account *GetAccount() override;
void SetAccount(NickServ::Account *) override;
diff --git a/modules/operserv/dns.cpp b/modules/operserv/dns.cpp
index e607b1712..1ccb54530 100644
--- a/modules/operserv/dns.cpp
+++ b/modules/operserv/dns.cpp
@@ -27,11 +27,10 @@ class DNSZoneImpl : public DNSZone
{
friend class DNSZoneType;
- Anope::string name;
+ Serialize::Storage<Anope::string> name;
public:
- DNSZoneImpl(Serialize::TypeBase *type) : DNSZone(type) { }
- DNSZoneImpl(Serialize::TypeBase *type, Serialize::ID id) : DNSZone(type, id) { }
+ using DNSZone::DNSZone;
Anope::string GetName() override;
void SetName(const Anope::string &) override;
@@ -72,10 +71,10 @@ class DNSServerImpl : public DNSServer
ServiceReference<DNS::Manager> manager;
- DNSZone *zone = nullptr;
- Anope::string name;
- unsigned int limit = 0;
- bool pooled = false;
+ Serialize::Storage<DNSZone *> zone;
+ Serialize::Storage<Anope::string> name;
+ Serialize::Storage<unsigned int> limit;
+ Serialize::Storage<bool> pooled;
/* is actually in the pool */
bool active = false;
@@ -84,8 +83,7 @@ class DNSServerImpl : public DNSServer
std::set<Anope::string, ci::less> zones;
time_t repool = 0;
- DNSServerImpl(Serialize::TypeBase *type) : DNSServer(type) { }
- DNSServerImpl(Serialize::TypeBase *type, Serialize::ID id) : DNSServer(type, id) { }
+ using DNSServer::DNSServer;
DNSZone *GetZone() override;
void SetZone(DNSZone *) override;
@@ -188,12 +186,11 @@ class DNSZoneMembershipImpl : public DNSZoneMembership
{
friend class DNSZoneMembershipType;
- DNSServer *server = nullptr;
- DNSZone *zone = nullptr;
+ Serialize::Storage<DNSServer *> server;
+ Serialize::Storage<DNSZone *> zone;
public:
- DNSZoneMembershipImpl(Serialize::TypeBase *type) : DNSZoneMembership(type) { }
- DNSZoneMembershipImpl(Serialize::TypeBase *type, Serialize::ID id) : DNSZoneMembership(type, id) { }
+ using DNSZoneMembership::DNSZoneMembership;
DNSServer *GetServer() override;
void SetServer(DNSServer *) override;
@@ -247,8 +244,8 @@ class DNSIPImpl : public DNSIP
{
friend class DNSIPType;
- DNSServer *server = nullptr;
- Anope::string ip;
+ Serialize::Storage<DNSServer *> server;
+ Serialize::Storage<Anope::string> ip;
public:
DNSIPImpl(Serialize::TypeBase *type) : DNSIP(type) { }
diff --git a/modules/operserv/forbid.cpp b/modules/operserv/forbid.cpp
index 1a013ed0d..22d927381 100644
--- a/modules/operserv/forbid.cpp
+++ b/modules/operserv/forbid.cpp
@@ -26,13 +26,12 @@ class ForbidDataImpl : public ForbidData
{
friend class ForbidDataType;
- Anope::string mask, creator, reason;
- time_t created = 0, expires = 0;
- ForbidType type = static_cast<ForbidType>(0);
+ Serialize::Storage<Anope::string> mask, creator, reason;
+ Serialize::Storage<time_t> created, expires;
+ Serialize::Storage<ForbidType> type;
public:
- ForbidDataImpl(Serialize::TypeBase *type) : ForbidData(type) { }
- ForbidDataImpl(Serialize::TypeBase *type, Serialize::ID id) : ForbidData(type, id) { }
+ using ForbidData::ForbidData;
Anope::string GetMask() override;
void SetMask(const Anope::string &) override;
diff --git a/modules/operserv/ignore.cpp b/modules/operserv/ignore.cpp
index a25b0ef8c..397916ca4 100644
--- a/modules/operserv/ignore.cpp
+++ b/modules/operserv/ignore.cpp
@@ -25,12 +25,11 @@ class IgnoreImpl : public Ignore
{
friend class IgnoreType;
- Anope::string mask, creator, reason;
- time_t time = 0;
+ Serialize::Storage<Anope::string> mask, creator, reason;
+ Serialize::Storage<time_t> time;
public:
- IgnoreImpl(Serialize::TypeBase *type) : Ignore(type) { }
- IgnoreImpl(Serialize::TypeBase *type, Serialize::ID id) : Ignore(type, id) { }
+ using Ignore::Ignore;
Anope::string GetMask() override;
void SetMask(const Anope::string &) override;
diff --git a/modules/operserv/info.cpp b/modules/operserv/info.cpp
index 30c0b06ad..c6038af5a 100644
--- a/modules/operserv/info.cpp
+++ b/modules/operserv/info.cpp
@@ -27,13 +27,12 @@ class OperInfoImpl : public OperInfo
{
friend class OperInfoType;
- Serialize::Object *target = nullptr;
- Anope::string info, creator;
- time_t created = 0;
+ Serialize::Storage<Serialize::Object *> target;
+ Serialize::Storage<Anope::string> info, creator;
+ Serialize::Storage<time_t> created;
public:
- OperInfoImpl(Serialize::TypeBase *type) : OperInfo(type) { }
- OperInfoImpl(Serialize::TypeBase *type, Serialize::ID id) : OperInfo(type, id) { }
+ using OperInfo::OperInfo;
Serialize::Object *GetTarget() override;
void SetTarget(Serialize::Object *) override;
diff --git a/modules/operserv/news.cpp b/modules/operserv/news.cpp
index a99063c19..e2119a2de 100644
--- a/modules/operserv/news.cpp
+++ b/modules/operserv/news.cpp
@@ -77,13 +77,12 @@ class NewsItemImpl : public NewsItem
{
friend class NewsItemType;
- NewsType type;
- Anope::string text, who;
- time_t time = 0;
+ Serialize::Storage<NewsType> type;
+ Serialize::Storage<Anope::string> text, who;
+ Serialize::Storage<time_t> time;
public:
- NewsItemImpl(Serialize::TypeBase *type) : NewsItem(type) { }
- NewsItemImpl(Serialize::TypeBase *type, Serialize::ID id) : NewsItem(type, id) { }
+ using NewsItem::NewsItem;
NewsType GetNewsType() override;
void SetNewsType(NewsType) override;
diff --git a/modules/operserv/session.cpp b/modules/operserv/session.cpp
index 0390d9205..cdd230473 100644
--- a/modules/operserv/session.cpp
+++ b/modules/operserv/session.cpp
@@ -47,13 +47,12 @@ class ExceptionImpl : public Exception
{
friend class ExceptionType;
- Anope::string mask, who, reason;
- unsigned int limit = 0;
- time_t time = 0, expires = 0;
+ Serialize::Storage<Anope::string> mask, who, reason;
+ Serialize::Storage<unsigned int> limit;
+ Serialize::Storage<time_t> time, expires;
public:
- ExceptionImpl(Serialize::TypeBase *type) : Exception(type) { }
- ExceptionImpl(Serialize::TypeBase *type, Serialize::ID id) : Exception(type, id) { }
+ using Exception::Exception;
Anope::string GetMask() override;
void SetMask(const Anope::string &) override;
diff --git a/modules/operserv/stats.cpp b/modules/operserv/stats.cpp
index 04b1af6c8..abee79cf6 100644
--- a/modules/operserv/stats.cpp
+++ b/modules/operserv/stats.cpp
@@ -25,11 +25,10 @@ class StatsImpl : public Stats
{
friend class StatsType;
- unsigned int maxusercnt = 0;
- time_t maxusertime = 0;
+ Serialize::Storage<unsigned int> maxusercnt;
+ Serialize::Storage<time_t> maxusertime;
public:
-
using Stats::Stats;
unsigned int GetMaxUserCount() override;
diff --git a/src/serialize.cpp b/src/serialize.cpp
index 8f9b91d75..4717c5948 100644
--- a/src/serialize.cpp
+++ b/src/serialize.cpp
@@ -42,13 +42,25 @@ Object *Serialize::GetID(ID id)
return nullptr;
}
-void Serialize::Clear()
+void Serialize::GC()
{
- std::unordered_map<ID, Object *> o;
- objects.swap(o);
+ for (auto it = objects.begin(); it != objects.end();)
+ {
+ Object *o = it->second;
- for (const std::pair<ID, Object *> &p : o)
- delete p.second;
+ if (!o->CanGC())
+ {
+ // Wipe internal storage to force refetch
+ o->Wipe();
+ ++it;
+ continue;
+ }
+
+ Log(LOG_DEBUG_2) << "garbage collected object " << o->id;
+
+ it = objects.erase(it);
+ delete o;
+ }
}
void Serialize::Unregister(Module *m)
@@ -62,6 +74,14 @@ void Serialize::Unregister(Module *m)
field->Unregister();
}
+void Serialize::Object::Wipe()
+{
+ for (Serialize::FieldBase *base : s_type->GetFields())
+ {
+ base->Uncache(this);
+ }
+}
+
std::vector<Edge> Object::GetEdges(TypeBase *type)
{
std::vector<Edge> refs;
@@ -125,8 +145,8 @@ Object::~Object()
Log(LOG_DEBUG_2) << "Destructing object id #" << id << " address " << static_cast<void *>(this) << " type " << s_type->GetName();
/* Remove in memory edges */
- cont:
- for (const std::pair<TypeBase *, std::vector<Edge>> &p : edges)
+ std::map<TypeBase *, std::vector<Edge>> copy = edges;
+ for (const std::pair<TypeBase *, std::vector<Edge>> &p : copy)
for (const Edge &edge : p.second)
{
if (!edge.direction)
@@ -139,7 +159,6 @@ Object::~Object()
Log(LOG_DEBUG_2) << "Removing edge to object id #" << edge.other->id << " type " << edge.other->GetSerializableType()->GetName() << " on field " << edge.field->serialize_name;
this->RemoveEdge(edge.other, edge.field);
}
- goto cont;
}
objects.erase(id);
@@ -193,12 +212,18 @@ void Object::RemoveEdge(Object *other, FieldBase *field)
else
Log(LOG_DEBUG_2) << "Unable to locate edge for removal on #" << this->id << " type " << s_type->GetName() << " -> #" << other->id << " type " << other->GetSerializableType()->GetName();
+ if (myedges.empty())
+ this->edges.erase(other->GetSerializableType());
+
std::vector<Edge> &theiredges = other->edges[this->GetSerializableType()];
it = std::find(theiredges.begin(), theiredges.end(), Edge(this, field, false));
if (it != theiredges.end())
theiredges.erase(it);
else
Log(LOG_DEBUG_2) << "Unable to locate edge for removal on #" << this->id << " type " << s_type->GetName() << " <- #" << other->id << " type " << other->GetSerializableType()->GetName();
+
+ if (theiredges.empty())
+ other->edges.erase(this->GetSerializableType());
}
TypeBase::TypeBase(Module *o, const Anope::string &n) : Service(o, TypeBase::NAME, n), name(n), owner(o)