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

Last change on this file since 3589 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
RevLine 
[364]1/*
[413]2 * ======================================================================
[364]3 *  Rappture::Serializable
4 *
[413]5 *  AUTHOR:  Michael McLennan, Purdue University
6 *           Carol X Song, Purdue University
7 *
[3177]8 *  Copyright (c) 2004-2012  HUBzero Foundation, LLC
[413]9 * ----------------------------------------------------------------------
[364]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 */
[1031]14#ifndef RPSERIALIZABLE_H
15#define RPSERIALIZABLE_H
[364]16
17#include <string>
18#include <map>
[1031]19#include <RpOutcome.h>
[1032]20#include <RpPtr.h>
21#include <RpSerialBuffer.h>
[364]22
23namespace Rappture {
24
25class SerialConversion;  // see below
26
[413]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 */
[364]33class Serializable {
34public:
35    Serializable();
36    virtual ~Serializable();
37
[370]38    virtual const char* serializerType() const = 0;
39    virtual char serializerVersion() const = 0;
[364]40
41    virtual void serialize(SerialBuffer& bufferPtr) const;
[370]42    static Outcome deserialize(SerialBuffer& buffer, Ptr<Serializable>* objPtrPtr);
[364]43
[370]44    typedef void (Serializable::*serializeObjectMethod)(SerialBuffer& buffer) const;
45    typedef Ptr<Serializable> (*createObjectFunc)();
46    typedef Outcome (Serializable::*deserializeObjectMethod)(SerialBuffer& buffer);
47
[364]48private:
49    friend class SerialConversion;
50
[370]51    class ConversionFuncs {
52    public:
[364]53        char version;
54        serializeObjectMethod serialMethod;
55        createObjectFunc createFunc;
56        deserializeObjectMethod deserialMethod;
57    };
58
[370]59    typedef std::map<std::string, ConversionFuncs> Name2ConvFuncsMap;
[364]60    static Name2ConvFuncsMap *_name2convFuncs;
61};
62
[413]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 */
[364]69class SerialConversion {
70public:
[370]71    SerialConversion(const char *className, char version,
[364]72        Serializable::serializeObjectMethod,
73        Serializable::createObjectFunc,
74        Serializable::deserializeObjectMethod);
75};
76
77} // namespace Rappture
78
[1031]79#endif /*RPSERIALIZABLE_H*/
Note: See TracBrowser for help on using the repository browser.