Serialization
I'm doing a very complicated structure for serialize/deserialize
objects, in short I have this abstract class
--8<---------------cut here---------------start------------->8---
#ifndef STREAMABLE_H
#define STREAMABLE_H
#include "Stream.hpp"
template <typename T>
class Serializable
{
public:
Serializable() {}
virtual Stream toStream() = 0;
// used to parse the given stream and create the object
virtual T parseStream(const Stream&) = 0;
};
#endif /* STREAMABLE_H */
--8<---------------cut here---------------end--------------->8---
and all the objects that want to bea able to create a stream and parse
it have to overload it.
Now 2 problems:
- the definition of the classes is something like
class PadNodeID : public Serializable<PadNodeID>
so the template parameter is always the class itself, maybe is it
possible to avoid it?
- the "parseStream" function doesn't really make sense to be called from
one object, since it's supposed to create one.
But making it static and virtual doens't work, so how should I declare
it in such a way that I can do.
--8<---------------cut here---------------start------------->8---
Type t = Type::parseStream(st);
--8<---------------cut here---------------end--------------->8---
Thanks again,
Andrea