diff options
author | Adam <Adam@anope.org> | 2012-02-14 15:13:27 -0500 |
---|---|---|
committer | Adam <Adam@anope.org> | 2012-02-14 15:13:27 -0500 |
commit | a9772cde21407c89abd161d51aff45267f87b1fb (patch) | |
tree | 9e57ba6c121d3843888917d968dd4f5d030b57cf /src/serialize.cpp | |
parent | 086790d6331357022f4da17c76b26b9fc6e2ad90 (diff) |
Clean up and reorganize our header files
Diffstat (limited to 'src/serialize.cpp')
-rw-r--r-- | src/serialize.cpp | 138 |
1 files changed, 138 insertions, 0 deletions
diff --git a/src/serialize.cpp b/src/serialize.cpp new file mode 100644 index 000000000..beaf5a8cc --- /dev/null +++ b/src/serialize.cpp @@ -0,0 +1,138 @@ +/* + * + * (C) 2003-2012 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + * Based on the original code of Epona by Lara. + * Based on the original code of Services by Andy Church. + */ + + +#include "services.h" +#include "anope.h" +#include "serialize.h" + +std::vector<Anope::string> SerializeType::type_order; +Anope::map<SerializeType *> SerializeType::types; +std::list<Serializable *> *Serializable::serizliable_items; + +stringstream::stringstream() : std::stringstream(), type(Serialize::DT_TEXT), key(false), _max(0) +{ +} + +stringstream::stringstream(const stringstream &ss) : std::stringstream(ss.str()), type(Serialize::DT_TEXT), key(false), _max(0) +{ +} + +Anope::string stringstream::astr() const +{ + return this->str(); +} + +std::istream &stringstream::operator>>(Anope::string &val) +{ + val = this->str(); + return *this; +} + +stringstream &stringstream::setType(Serialize::DataType t) +{ + this->type = t; + return *this; +} + +Serialize::DataType stringstream::getType() const +{ + return this->type; +} + +stringstream &stringstream::setKey() +{ + this->key = true; + return *this; +} + +bool stringstream::getKey() const +{ + return this->key; +} + +stringstream &stringstream::setMax(unsigned m) +{ + this->_max = m; + return *this; +} + +unsigned stringstream::getMax() const +{ + return this->_max; +} + +Serializable::Serializable() +{ + if (serizliable_items == NULL) + serizliable_items = new std::list<Serializable *>(); + serizliable_items->push_front(this); + this->s_iter = serizliable_items->begin(); +} + +Serializable::Serializable(const Serializable &) +{ + serizliable_items->push_front(this); + this->s_iter = serizliable_items->begin(); +} + +Serializable::~Serializable() +{ + serizliable_items->erase(this->s_iter); +} + +Serializable &Serializable::operator=(const Serializable &) +{ + return *this; +} + +const std::list<Serializable *> &Serializable::GetItems() +{ + return *serizliable_items; +} + +SerializeType::SerializeType(const Anope::string &n, unserialize_func f) : name(n), unserialize(f) +{ + type_order.push_back(this->name); + types[this->name] = this; +} + +SerializeType::~SerializeType() +{ + std::vector<Anope::string>::iterator it = std::find(type_order.begin(), type_order.end(), this->name); + if (it != type_order.end()) + type_order.erase(it); + types.erase(this->name); +} + +const Anope::string &SerializeType::GetName() +{ + return this->name; +} + +void SerializeType::Create(Serializable::serialized_data &data) +{ + this->unserialize(data); +} + +SerializeType *SerializeType::Find(const Anope::string &name) +{ + Anope::map<SerializeType *>::iterator it = types.find(name); + if (it != types.end()) + return it->second; + return NULL; +} + +const std::vector<Anope::string> &SerializeType::GetTypeOrder() +{ + return type_order; +} + |