source: trunk/src/core2/RpSerializable.h @ 4503

Last change on this file since 4503 was 3177, checked in by mmc, 12 years ago

Updated all of the copyright notices to reference the transfer to
the new HUBzero Foundation, LLC.

File size: 2.4 KB
Line 
1/*
2 * ======================================================================
3 *  Rappture::Serializable
4 *
5 *  AUTHOR:  Michael McLennan, Purdue University
6 *           Carol X Song, Purdue University
7 *
8 *  Copyright (c) 2004-2012  HUBzero Foundation, LLC
9 * ----------------------------------------------------------------------
10 *  See the file "license.terms" for information on usage and
11 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
12 * ======================================================================
13 */
14#ifndef RPSERIALIZABLE_H
15#define RPSERIALIZABLE_H
16
17#include <string>
18#include <map>
19#include <RpOutcome.h>
20#include <RpPtr.h>
21#include <RpSerialBuffer.h>
22
23namespace Rappture {
24
25class SerialConversion;  // see below
26
27/**
28 * Base class for any object that can be serialized into a stream,
29 * then saved to a file or written to a socket, and reconstituted
30 * into its original form.  Serializable objects can be added to
31 * a serializer, which handles the overall conversion.
32 */
33class Serializable {
34public:
35    Serializable();
36    virtual ~Serializable();
37
38    virtual const char* serializerType() const = 0;
39    virtual char serializerVersion() const = 0;
40
41    virtual void serialize(SerialBuffer& bufferPtr) const;
42    static Outcome deserialize(SerialBuffer& buffer, Ptr<Serializable>* objPtrPtr);
43
44    typedef void (Serializable::*serializeObjectMethod)(SerialBuffer& buffer) const;
45    typedef Ptr<Serializable> (*createObjectFunc)();
46    typedef Outcome (Serializable::*deserializeObjectMethod)(SerialBuffer& buffer);
47
48private:
49    friend class SerialConversion;
50
51    class ConversionFuncs {
52    public:
53        char version;
54        serializeObjectMethod serialMethod;
55        createObjectFunc createFunc;
56        deserializeObjectMethod deserialMethod;
57    };
58
59    typedef std::map<std::string, ConversionFuncs> Name2ConvFuncsMap;
60    static Name2ConvFuncsMap *_name2convFuncs;
61};
62
63/**
64 * Each class derived from Serializable should have a SerialConversion
65 * stored as a static data member.  This declares information needed
66 * to serialize/deserialize the class, making objects in that class
67 * serializable.
68 */
69class SerialConversion {
70public:
71    SerialConversion(const char *className, char version,
72        Serializable::serializeObjectMethod,
73        Serializable::createObjectFunc,
74        Serializable::deserializeObjectMethod);
75};
76
77} // namespace Rappture
78
79#endif /*RPSERIALIZABLE_H*/
Note: See TracBrowser for help on using the repository browser.