// // $Id$ #pragma once #include #include "Streamable.h" static inline utf8 JAVA_LIST_NAME () { return "java.util.ArrayList"; } class ObjectOutputStream; class ObjectInputStream; struct Streamer { virtual Shared createObject (ObjectInputStream& in) = 0; virtual void writeObject (const Shared& object, ObjectOutputStream& out) = 0; }; Streamer* getStreamer (const utf8& javaName); void registerStreamer (const utf8& javaName, Streamer* streamer); inline const utf8 getJavaName (const utf8*) { return "java.lang.String"; } inline const utf8 getJavaName (const int8*) { return "B"; } inline const utf8 getJavaName (const int16*) { return "S"; } inline const utf8 getJavaName (const int32*) { return "I"; } inline const utf8 getJavaName (const int64*) { return "J"; } inline const utf8 getJavaName (const bool*) { return "Z"; } inline const utf8 getJavaName (const float*) { return "F"; } inline const utf8 getJavaName (const double*) { return "D"; } template inline const utf8 getJavaName (const Shared*) { return getJavaName((const T*)NULL); } template inline const utf8 getJavaName (const std::vector*) { return "[" + getJavaName((const T*)NULL); } template inline const utf8 getJavaName (const std::vector< Shared >*) { return "[L" + getJavaName((const T*)NULL) + ";"; } template inline const utf8 getJavaName (const T*) { return T::javaName(); } template <> inline const utf8 getJavaName (const Streamable*) { return "java.lang.Object"; } template inline const utf8 getObjectName (T* object) { if (boost::is_base_of::value) { // Look up the object's class virtually return ((Streamable*)object)->getJavaClassName(); } else { // Everything else is assumed to be a final class return getJavaName(object); } }