diff options
Diffstat (limited to 'src/serialize.cpp')
-rw-r--r-- | src/serialize.cpp | 96 |
1 files changed, 19 insertions, 77 deletions
diff --git a/src/serialize.cpp b/src/serialize.cpp index 0f3e6c7a6..ee300a441 100644 --- a/src/serialize.cpp +++ b/src/serialize.cpp @@ -1,6 +1,6 @@ /* * - * (C) 2003-2012 Anope Team + * (C) 2003-2013 Anope Team * Contact us at team@anope.org * * Please read COPYING and README for further details. @@ -35,63 +35,7 @@ void Serialize::RegisterTypes() memo("Memo", Memo::Unserialize), xline("XLine", XLine::Unserialize); } -/*stringstream::stringstream() : std::stringstream(), type(Serialize::DT_TEXT), _max(0) -{ -} - -stringstream::stringstream(const stringstream &ss) : std::stringstream(ss.str()), type(Serialize::DT_TEXT), _max(0) -{ -} - -Anope::string stringstream::astr() const -{ - return this->str(); -} - -std::istream &stringstream::operator>>(Anope::string &val) -{ - val = this->str(); - return *this; -} - -bool stringstream::operator==(const stringstream &other) const -{ - return this->astr() == other.astr(); -} - -bool stringstream::operator!=(const stringstream &other) const -{ - return !(*this == other); -} - -stringstream &stringstream::SetType(Serialize::DataType t) -{ - this->type = t; - return *this; -} - -DataType Serialize::stringstream::GetType() const -{ - return this->type; -} - -stringstream &stringstream::SetMax(unsigned m) -{ - this->_max = m; - return *this; -} - -unsigned stringstream::GetMax() const -{ - return this->_max; -}*/ - -Serializable::Serializable() : last_commit(NULL), last_commit_time(0), id(0) -{ - throw CoreException("Default Serializable constructor?"); -} - -Serializable::Serializable(const Anope::string &serialize_type) : last_commit(NULL), last_commit_time(0), id(0) +Serializable::Serializable(const Anope::string &serialize_type) : last_commit(0), last_commit_time(0), id(0) { if (SerializableItems == NULL) SerializableItems = new std::list<Serializable *>(); @@ -105,7 +49,7 @@ Serializable::Serializable(const Anope::string &serialize_type) : last_commit(NU FOREACH_MOD(I_OnSerializableConstruct, OnSerializableConstruct(this)); } -Serializable::Serializable(const Serializable &other) : last_commit(NULL), last_commit_time(0), id(0) +Serializable::Serializable(const Serializable &other) : last_commit(0), last_commit_time(0), id(0) { SerializableItems->push_back(this); this->s_iter = SerializableItems->end(); @@ -118,8 +62,9 @@ Serializable::Serializable(const Serializable &other) : last_commit(NULL), last_ Serializable::~Serializable() { + FOREACH_MOD(I_OnSerializableDestruct, OnSerializableDestruct(this)); + SerializableItems->erase(this->s_iter); - delete last_commit; } Serializable &Serializable::operator=(const Serializable &) @@ -127,33 +72,23 @@ Serializable &Serializable::operator=(const Serializable &) return *this; } -void Serializable::Destroy() -{ - if (!this) - return; - - FOREACH_MOD(I_OnSerializableDestruct, OnSerializableDestruct(this)); - - delete this; -} - void Serializable::QueueUpdate() { - /* Check for modifications now */ - FOREACH_MOD(I_OnSerializeCheck, OnSerializeCheck(this->GetSerializableType())); /* Schedule updater */ FOREACH_MOD(I_OnSerializableUpdate, OnSerializableUpdate(this)); + + /* Check for modifications now - this can delete this object! */ + FOREACH_MOD(I_OnSerializeCheck, OnSerializeCheck(this->GetSerializableType())); } -bool Serializable::IsCached(Serialize::Data *data) +bool Serializable::IsCached(Serialize::Data &data) { - return this->last_commit && this->last_commit->IsEqual(data); + return this->last_commit == data.Hash(); } -void Serializable::UpdateCache(Serialize::Data *data) +void Serializable::UpdateCache(Serialize::Data &data) { - delete this->last_commit; - this->last_commit = data; + this->last_commit = data.Hash(); } bool Serializable::IsTSCached() @@ -175,6 +110,8 @@ Type::Type(const Anope::string &n, unserialize_func f, Module *o) : name(n), un { TypeOrder.push_back(this->name); Types[this->name] = this; + + FOREACH_MOD(I_OnSerializeTypeCreate, OnSerializeTypeCreate(this)); } Type::~Type() @@ -218,3 +155,8 @@ const std::vector<Anope::string> &Type::GetTypeOrder() return TypeOrder; } +const std::map<Anope::string, Serialize::Type *>& Type::GetTypes() +{ + return Types; +} + |