Files
narya/cpplib/src/presents/streamers/StreamableStreamer.h
T
Michael Bayne 1c311431ad Finished the job of splitting Narya into submodules.
The ActionScript code is now under aslib and is built via Maven (and Ant). The
CPP code is under cpplib and is ignored by everything (other than service
generation), but now at least it's not crufting up the Java submodule with its
XCode project.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6783 542714f4-19e9-0310-aa3c-eee0fc999fb1
2012-02-14 19:11:33 +00:00

35 lines
1.1 KiB
C++

#pragma once
#include "presents/Streamer.h"
#include "presents/Streamable.h"
template <typename T>
class StreamableStreamer : public Streamer
{
public:
Shared<void> createObject (ObjectInputStream& in)
{
Shared<Streamable> streamable(new T());
streamable->readObject(in);
return streamable;
}
void writeObject (const Shared<void>& object, ObjectOutputStream& out)
{
((Shared<T>&)object)->writeObject(out);
}
};
#define DECLARE_STREAMABLE() \
static const utf8& javaName (); \
static void registerWithPresents () { javaName(); } \
virtual const utf8& getJavaClassName () const { return javaName(); }
#define DEFINE_STREAMABLE(nameString, StreamableClass) \
static const utf8& gStreamableClassRegistration = StreamableClass::javaName(); \
const utf8& StreamableClass::javaName () {\
static const utf8 JAVA_NAME = nameString; \
static bool gRegistered = false; \
if (!gRegistered) { registerStreamer(JAVA_NAME, new StreamableStreamer<StreamableClass>()); gRegistered = true; } \
return JAVA_NAME; }