summaryrefslogtreecommitdiff
path: root/include/serialize.h
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2012-12-13 06:12:56 -0500
committerAdam <Adam@anope.org>2012-12-13 06:12:56 -0500
commitc1077faa281c5635f85b892e605e23bd6c8fcc3b (patch)
tree213b5f87a19f182e1efd6110f03ff10d5b10ebf6 /include/serialize.h
parent76ba147c22944b67e8522cd2bb7b6e1bae498ced (diff)
Optimize much of the database code and serialize code.
Diffstat (limited to 'include/serialize.h')
-rw-r--r--include/serialize.h57
1 files changed, 20 insertions, 37 deletions
diff --git a/include/serialize.h b/include/serialize.h
index 8b8497c40..1a16e5b35 100644
--- a/include/serialize.h
+++ b/include/serialize.h
@@ -20,41 +20,24 @@
namespace Serialize
{
- enum DataType
+ class Data
{
- DT_TEXT,
- DT_INT
- };
-
- class CoreExport stringstream : public std::stringstream
- {
- private:
- Serialize::DataType type;
- unsigned _max;
-
public:
- stringstream();
- stringstream(const stringstream &ss);
- Anope::string astr() const;
-
- template<typename T> std::istream &operator>>(T &val)
+ enum Type
{
- std::istringstream is(this->str());
- is >> val;
- return *this;
- }
- std::istream &operator>>(Anope::string &val);
+ DT_TEXT,
+ DT_INT
+ };
- bool operator==(const stringstream &other) const;
- bool operator!=(const stringstream &other) const;
+ virtual ~Data() { }
- stringstream &SetType(Serialize::DataType t);
- Serialize::DataType GetType() const;
- stringstream &SetMax(unsigned m);
- unsigned GetMax() const;
- };
+ virtual std::iostream& operator[](const Anope::string &key) = 0;
- typedef std::map<Anope::string, stringstream> Data;
+ virtual bool IsEqual(Data *other) { throw CoreException("Not supported"); }
+
+ virtual void SetType(const Anope::string &key, Type t) { }
+ virtual Type GetType(const Anope::string &key) const { return DT_TEXT; }
+ };
extern void RegisterTypes();
@@ -64,7 +47,7 @@ namespace Serialize
}
/** A serialziable object. Serializable objects can be serialized into
- * a map of stringstreams (Serialize::Data), and then reconstructed or
+ * abstract data types (Serialize::Data), and then reconstructed or
* updated later at any time.
*/
class CoreExport Serializable : public virtual Base
@@ -82,7 +65,7 @@ class CoreExport Serializable : public virtual Base
/* Iterator into serializable_items */
std::list<Serializable *>::iterator s_iter;
/* The last serialized form of this object commited to the database */
- Serialize::Data last_commit;
+ Serialize::Data *last_commit;
/* The last time this object was commited to the database */
time_t last_commit_time;
@@ -108,8 +91,8 @@ class CoreExport Serializable : public virtual Base
*/
void QueueUpdate();
- bool IsCached();
- void UpdateCache();
+ bool IsCached(Serialize::Data *);
+ void UpdateCache(Serialize::Data *);
bool IsTSCached();
void UpdateTS();
@@ -117,9 +100,9 @@ class CoreExport Serializable : public virtual Base
/** Get the type of serializable object this is
* @return The serializable object type
*/
- Serialize::Type* GetSerializableType() const;
+ Serialize::Type* GetSerializableType() const { return this->s_type; }
- virtual Serialize::Data Serialize() const = 0;
+ virtual void Serialize(Serialize::Data &data) const = 0;
static const std::list<Serializable *> &GetItems();
};
@@ -164,7 +147,7 @@ class CoreExport Serialize::Type
/** Gets the name for this type
* @return The name, eg "NickAlias"
*/
- const Anope::string &GetName();
+ const Anope::string &GetName() { return this->name; }
/** Unserialized an object.
* @param obj NULL if this object doesn't yet exist. If this isn't NULL, instead
@@ -187,7 +170,7 @@ class CoreExport Serialize::Type
*/
void UpdateTimestamp();
- Module* GetOwner() const;
+ Module* GetOwner() const { return this->owner; }
static Serialize::Type *Find(const Anope::string &name);