00001 #ifndef COMMON_SERIALIZABLE_H
00002 #define COMMON_SERIALIZABLE_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 class Repository;
00045 class MarkState;
00046
00047
00048
00049 #define OBTYPE(code,ver,schema,nm) TY_##nm = code,
00050 enum SerTypeConst {
00051 #include "OBTYPES.def"
00052
00053 TY_ntypes,
00054 TY_Serializable
00055 };
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066 #define SERIALIZABLE_FIRST_METAVERSION 4
00067 #define SERIALIZABLE_CURRENT_METAVERSION 4
00068
00069 #define SERIALIZABLE_CURRENT_SCHEMA_METAVERSION 4
00070
00071 struct SerialType;
00072 struct Buffer;
00073
00074
00075 namespace sdr {
00076 class OStream;
00077 class IStream;
00078 };
00079
00082 struct Serializable : public Countable {
00083 friend class SerMeta;
00084
00085 public:
00086 const SerialType *serType;
00087 uint32_t metaVer;
00088 uint32_t obVer;
00089
00090
00091 uint32_t affinity;
00092
00093
00094 bool canFreeze;
00095 private:
00096 TrueName trueName;
00097
00098 public:
00099
00100
00101 inline Serializable(const SerialType* st, uint32_t mv, uint32_t ov)
00102 : serType(st)
00103 {
00104 metaVer = mv;
00105 obVer = ov;
00106 affinity = 0;
00107
00108 canFreeze = false;
00109 trueName = TrueName::Null;
00110 }
00111
00112 Serializable(const Serializable& other)
00113 {
00114 serType = other.serType;
00115 metaVer = other.metaVer;
00116 obVer = other.obVer;
00117 affinity = other.affinity;
00118 canFreeze = false;
00119 trueName = TrueName::Null;
00120 }
00121
00122 virtual ~Serializable()
00123 {
00124 }
00125
00126 inline SerTypeConst getType() const;
00127
00128 TrueName getTrueName() const;
00129 TrueName getTrueName();
00130
00131 GCPtr<Serializable> deepCopy() const;
00132
00133 inline void SetAffinity(uint32_t aff)
00134 {
00135 affinity = aff;
00136 }
00137
00138 inline uint32_t GetAffinity()
00139 {
00140 return affinity;
00141 }
00142
00143 void toBuffer(Buffer& buf, bool forSignature = false);
00144
00145 public:
00146
00147
00148 void serialize_meta(sdr::OStream& strm) const;
00149 void deserialize_meta(sdr::IStream &strm);
00150 };
00151
00159 struct SerialType {
00160 const SerTypeConst tyConst;
00161
00162
00163
00164
00165
00166 const Serializable& ser;
00167
00168 const char * tyName;
00169
00170 static const SerialType* find(SerTypeConst tyConst);
00171
00172 void (*serialize)(sdr::OStream& os, GCPtr<const Serializable> s);
00173 GCPtr<Serializable> (*deserialize)(sdr::IStream&, const Serializable &meta);
00174 void (*mark) (GCPtr<Repository>,
00175 GCPtr<const Serializable> container,
00176 GCPtr<const Serializable> ob,
00177 MarkState& memObs);
00178 bool (*check) (GCPtr<const Serializable> ob);
00179 };
00180
00181 inline SerTypeConst Serializable::getType() const
00182 {
00183 return serType->tyConst;
00184 }
00185
00186
00187
00188
00189
00190
00191 #define SERIALIZABLE_DECLS(typename) \
00192 public: \
00193 static void serialize(sdr::OStream& os, GCPtr<const Serializable> s); \
00194 static GCPtr<Serializable> deserialize(sdr::IStream&, const Serializable &meta); \
00195 static void mark(GCPtr<Repository> r, \
00196 GCPtr<const Serializable> container, \
00197 GCPtr<const Serializable> ob, \
00198 MarkState& memObs); \
00199 static bool check(GCPtr<const Serializable> ob); \
00200 \
00201 static const SerialType SerType; \
00202 static const Serializable CurMeta; \
00203 \
00204 typename(const Serializable& s = CurMeta); \
00205 virtual ~typename()
00206
00207
00208
00209
00210 typedef struct SerMeta SerMeta;
00211 struct SerMeta : public Serializable {
00212 SERIALIZABLE_DECLS(SerMeta);
00213
00214 Serializable meta;
00215
00216 static GCPtr<SerMeta> fromSerializable(GCPtr<const Serializable>);
00217 };
00218
00219 #define ser_mark(r, pv, v, ms) v->serType->mark(r, pv, v, ms)
00220
00221 void mark_truename(GCPtr<const Serializable> ob, MarkState& ms, TrueName tn);
00222 void mark_mutname(GCPtr<const Serializable> ob, MarkState& ms, MutName mutName);
00223
00224 #if 0
00225 void ser_init(void *s, const Serializable *);
00226
00227
00228
00229 #define CMVAR(x) cm_##x
00230 #define CMCHANGED(s1) ( ((Serializable *)s1)->trueName.tnval = 0 )
00231 #define CMSET(s1,x,v) ( CMCHANGED(s1), s1->CMVAR(x) = (v) )
00232 #define CMGET(s,x) s->CMVAR(x)
00233 #define CMCLOBBER(s,x) (CMCHANGED(s), s->CMVAR(x))
00234 #define CM_CANFREEZE(s) ((Serializable *)s)->canFreeze = FALSE
00235
00236
00237 #define AFFGET(s) (((Serializable *)s)->affinity)
00238 #define AFFSET(s,a) (AFFGET(s) = a)
00239 #endif
00240
00241
00242
00243
00244
00245 #endif