1 | /* |
---|
2 | * ---------------------------------------------------------------------- |
---|
3 | * Rappture::Serializer |
---|
4 | * The object collects a series of other objects together and |
---|
5 | * serializes them into a single byte stream. That stream can |
---|
6 | * be written to a file, send over a socket, and so forth. The |
---|
7 | * resulting stream can be loaded by a Serializer and the objects |
---|
8 | * can be reconstituted to their original form. |
---|
9 | * |
---|
10 | * ====================================================================== |
---|
11 | * AUTHOR: Michael McLennan, Purdue University |
---|
12 | * Copyright (c) 2004-2006 Purdue Research Foundation |
---|
13 | * |
---|
14 | * See the file "license.terms" for information on usage and |
---|
15 | * redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
16 | * ====================================================================== |
---|
17 | */ |
---|
18 | #ifndef RPSERIALIZER_H |
---|
19 | #define RPSERIALIZER_H |
---|
20 | |
---|
21 | #include <map> |
---|
22 | #include <RpPtr.h> |
---|
23 | #include <RpOutcome.h> |
---|
24 | #include "RpSerialBuffer.h" |
---|
25 | #include "RpSerializable.h" |
---|
26 | |
---|
27 | namespace Rappture { |
---|
28 | |
---|
29 | class Serializer { |
---|
30 | public: |
---|
31 | Serializer(); |
---|
32 | virtual ~Serializer(); |
---|
33 | |
---|
34 | virtual Ptr<SerialBuffer> serialize(); |
---|
35 | virtual Outcome deserialize(const char* bytes, int nbytes); |
---|
36 | |
---|
37 | virtual int size() const; |
---|
38 | virtual Ptr<Serializable> get(int pos) const; |
---|
39 | |
---|
40 | virtual Serializer& clear(); |
---|
41 | virtual const char* add(Serializable* objPtr); |
---|
42 | |
---|
43 | private: |
---|
44 | // disallow these operations |
---|
45 | Serializer(const Serializer& status) { assert(0); } |
---|
46 | Serializer& operator=(const Serializer& status) { assert(0); } |
---|
47 | |
---|
48 | // list of objects being serialized or deserialized |
---|
49 | std::vector<const char*> _idlist; |
---|
50 | |
---|
51 | // map each id in _idlist to the corresponding object |
---|
52 | typedef std::map<std::string, Ptr<Serializable> > SerializerId2Obj; |
---|
53 | SerializerId2Obj _id2obj; |
---|
54 | }; |
---|
55 | |
---|
56 | } // namespace Rappture |
---|
57 | |
---|
58 | #endif |
---|