diff options
Diffstat (limited to 'src/serialize.cpp')
-rw-r--r-- | src/serialize.cpp | 95 |
1 files changed, 70 insertions, 25 deletions
diff --git a/src/serialize.cpp b/src/serialize.cpp index 3f8df0434..9ff3fca1d 100644 --- a/src/serialize.cpp +++ b/src/serialize.cpp @@ -13,16 +13,17 @@ #include "services.h" #include "anope.h" #include "serialize.h" +#include "modules.h" std::vector<Anope::string> SerializeType::type_order; Anope::map<SerializeType *> SerializeType::types; -std::list<Serializable *> *Serializable::serizliable_items; +std::list<Serializable *> *Serializable::serializable_items; -stringstream::stringstream() : std::stringstream(), type(Serialize::DT_TEXT), key(false), _max(0) +stringstream::stringstream() : std::stringstream(), type(Serialize::DT_TEXT), _max(0) { } -stringstream::stringstream(const stringstream &ss) : std::stringstream(ss.str()), type(Serialize::DT_TEXT), key(false), _max(0) +stringstream::stringstream(const stringstream &ss) : std::stringstream(ss.str()), type(Serialize::DT_TEXT), _max(0) { } @@ -37,26 +38,25 @@ std::istream &stringstream::operator>>(Anope::string &val) return *this; } -stringstream &stringstream::setType(Serialize::DataType t) +bool stringstream::operator==(const stringstream &other) const { - this->type = t; - return *this; + return this->astr() == other.astr(); } -Serialize::DataType stringstream::getType() const +bool stringstream::operator!=(const stringstream &other) const { - return this->type; + return !(*this == other); } -stringstream &stringstream::setKey() +stringstream &stringstream::setType(Serialize::DataType t) { - this->key = true; + this->type = t; return *this; } -bool stringstream::getKey() const +Serialize::DataType stringstream::getType() const { - return this->key; + return this->type; } stringstream &stringstream::setMax(unsigned m) @@ -70,25 +70,30 @@ unsigned stringstream::getMax() const return this->_max; } -Serializable::Serializable() +Serializable::Serializable() : id(0) { - if (serizliable_items == NULL) - serizliable_items = new std::list<Serializable *>(); - serizliable_items->push_back(this); - this->s_iter = serizliable_items->end(); + if (serializable_items == NULL) + serializable_items = new std::list<Serializable *>(); + serializable_items->push_back(this); + + this->s_iter = serializable_items->end(); --this->s_iter; + + FOREACH_MOD(I_OnSerializableConstruct, OnSerializableConstruct(this)); } -Serializable::Serializable(const Serializable &) +Serializable::Serializable(const Serializable &) : id(0) { - serizliable_items->push_back(this); - this->s_iter = serizliable_items->end(); + serializable_items->push_back(this); + this->s_iter = serializable_items->end(); --this->s_iter; + + FOREACH_MOD(I_OnSerializableConstruct, OnSerializableConstruct(this)); } Serializable::~Serializable() { - serizliable_items->erase(this->s_iter); + serializable_items->erase(this->s_iter); } Serializable &Serializable::operator=(const Serializable &) @@ -96,12 +101,37 @@ Serializable &Serializable::operator=(const Serializable &) return *this; } +void Serializable::destroy() +{ + if (!this) + return; + + FOREACH_MOD(I_OnSerializableDestruct, OnSerializableDestruct(this)); + + delete this; +} + +void Serializable::QueueUpdate() +{ + FOREACH_MOD(I_OnSerializableUpdate, OnSerializableUpdate(this)); +} + +bool Serializable::IsCached() +{ + return this->last_commit == this->serialize(); +} + +void Serializable::UpdateCache() +{ + this->last_commit = this->serialize(); +} + const std::list<Serializable *> &Serializable::GetItems() { - return *serizliable_items; + return *serializable_items; } -SerializeType::SerializeType(const Anope::string &n, unserialize_func f) : name(n), unserialize(f) +SerializeType::SerializeType(const Anope::string &n, unserialize_func f) : name(n), unserialize(f), timestamp(0) { type_order.push_back(this->name); types[this->name] = this; @@ -120,9 +150,24 @@ const Anope::string &SerializeType::GetName() return this->name; } -void SerializeType::Create(Serializable::serialized_data &data) +Serializable *SerializeType::Unserialize(Serializable *obj, Serialize::Data &data) +{ + return this->unserialize(obj, data); +} + +void SerializeType::Check() +{ + FOREACH_MOD(I_OnSerializeCheck, OnSerializeCheck(this)); +} + +time_t SerializeType::GetTimestamp() const +{ + return this->timestamp; +} + +void SerializeType::UpdateTimestamp() { - this->unserialize(data); + this->timestamp = Anope::CurTime; } SerializeType *SerializeType::Find(const Anope::string &name) |