summaryrefslogtreecommitdiff
path: root/src/serialize.cpp
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2012-10-01 18:50:29 -0400
committerAdam <Adam@anope.org>2012-10-01 18:50:29 -0400
commita434baed9154d90ad0dfd31c71a463fb8300bfd8 (patch)
tree587b81c85c8abd676bb6fe1897415017a6d3f85a /src/serialize.cpp
parentf14a3dfb8a4cc9da7b5066ac8320265d54dba177 (diff)
Allow modules to store data in their own databases.
Diffstat (limited to 'src/serialize.cpp')
-rw-r--r--src/serialize.cpp23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/serialize.cpp b/src/serialize.cpp
index 7bcf12283..39d0cdd8f 100644
--- a/src/serialize.cpp
+++ b/src/serialize.cpp
@@ -72,22 +72,31 @@ unsigned stringstream::getMax() const
Serializable::Serializable() : last_commit_time(0), id(0)
{
+ throw CoreException("Default Serializable constructor?");
+}
+
+Serializable::Serializable(const Anope::string &serialize_type) : last_commit_time(0), id(0)
+{
if (serializable_items == NULL)
serializable_items = new std::list<Serializable *>();
serializable_items->push_back(this);
+ this->s_type = SerializeType::Find(serialize_type);
+
this->s_iter = serializable_items->end();
--this->s_iter;
FOREACH_MOD(I_OnSerializableConstruct, OnSerializableConstruct(this));
}
-Serializable::Serializable(const Serializable &) : last_commit_time(0), id(0)
+Serializable::Serializable(const Serializable &other) : last_commit_time(0), id(0)
{
serializable_items->push_back(this);
this->s_iter = serializable_items->end();
--this->s_iter;
+ this->s_type = other.s_type;
+
FOREACH_MOD(I_OnSerializableConstruct, OnSerializableConstruct(this));
}
@@ -136,12 +145,17 @@ void Serializable::UpdateTS()
this->last_commit_time = Anope::CurTime;
}
+SerializeType* Serializable::GetSerializableType() const
+{
+ return this->s_type;
+}
+
const std::list<Serializable *> &Serializable::GetItems()
{
return *serializable_items;
}
-SerializeType::SerializeType(const Anope::string &n, unserialize_func f) : name(n), unserialize(f), timestamp(0)
+SerializeType::SerializeType(const Anope::string &n, unserialize_func f, Module *o) : name(n), unserialize(f), owner(o), timestamp(0)
{
type_order.push_back(this->name);
types[this->name] = this;
@@ -180,6 +194,11 @@ void SerializeType::UpdateTimestamp()
this->timestamp = Anope::CurTime;
}
+Module* SerializeType::GetOwner() const
+{
+ return this->owner;
+}
+
SerializeType *SerializeType::Find(const Anope::string &name)
{
Anope::map<SerializeType *>::iterator it = types.find(name);