1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-25 04:02:41 +01:00

Added some sectioning comments to Serialize.h.

Added additional serialization functors for use with std::foreach.

llvm-svn: 45162
This commit is contained in:
Ted Kremenek 2007-12-18 18:25:55 +00:00
parent 93d750bbe3
commit 200bc2d387

View File

@ -33,39 +33,41 @@ class Serializer {
public:
explicit Serializer(BitstreamWriter& stream);
~Serializer();
//==------------------------------------------------==//
// Template-based dispatch to emit arbitrary types.
//==------------------------------------------------==//
template <typename T>
template <typename T>
inline void Emit(const T& X) { SerializeTrait<T>::Emit(*this,X); }
template <typename T>
struct Emitter {
Serializer &S;
Emitter(Serializer& s) : S(s) {}
void operator()(const T& x) const { S.Emit(x); }
};
template <typename T>
Emitter<T> MakeEmitter() { return Emitter<T>(*this); }
//==------------------------------------------------==//
// Methods to emit primitive types.
//==------------------------------------------------==//
void EmitInt(uint64_t X);
void EmitSInt(int64_t X);
void EmitBool(bool X) { EmitInt(X); }
inline void EmitBool(bool X) { EmitInt(X); }
void EmitCStr(const char* beg, const char* end);
void EmitCStr(const char* cstr);
void EmitPtr(const void* ptr) { EmitInt(getPtrId(ptr)); }
template <typename T>
void EmitRef(const T& ref) { EmitPtr(&ref); }
inline void EmitRef(const T& ref) { EmitPtr(&ref); }
template <typename T>
void EmitOwnedPtr(T* ptr) {
inline void EmitOwnedPtr(T* ptr) {
EmitPtr(ptr);
if (ptr) SerializeTrait<T>::Emit(*this,*ptr);
}
//==------------------------------------------------==//
// Batch emission of pointers.
//==------------------------------------------------==//
template <typename T1, typename T2>
void BatchEmitOwnedPtrs(T1* p1, T2* p2) {
EmitPtr(p1);
@ -135,6 +137,61 @@ public:
if (p2) SerializeTrait<T2>::Emit(*this,*p2);
if (p3) SerializeTrait<T3>::Emit(*this,*p3);
}
//==------------------------------------------------==//
// Emitter Functors
//==------------------------------------------------==//
template <typename T>
struct Emitter0 {
Serializer& S;
Emitter0(Serializer& s) : S(s) {}
void operator()(const T& x) const {
SerializeTrait<T>::Emit(S,x);
}
};
template <typename T, typename Arg1>
struct Emitter1 {
Serializer& S;
Arg1 A1;
Emitter1(Serializer& s, Arg1 a1) : S(s), A1(a1) {}
void operator()(const T& x) const {
SerializeTrait<T>::Emit(S,x,A1);
}
};
template <typename T, typename Arg1, typename Arg2>
struct Emitter2 {
Serializer& S;
Arg1 A1;
Arg2 A2;
Emitter2(Serializer& s, Arg1 a1, Arg2 a2) : S(s), A1(a1), A2(a2) {}
void operator()(const T& x) const {
SerializeTrait<T>::Emit(S,x,A1,A2);
}
};
template <typename T>
Emitter0<T> MakeEmitter() {
return Emitter0<T>(*this);
}
template <typename T, typename Arg1>
Emitter1<T,Arg1> MakeEmitter(Arg1 a1) {
return Emitter1<T,Arg1>(*this,a1);
}
template <typename T, typename Arg1, typename Arg2>
Emitter2<T,Arg1,Arg2> MakeEmitter(Arg1 a1, Arg2 a2) {
return Emitter2<T,Arg1,Arg2>(*this,a1,a2);
}
//==------------------------------------------------==//
// Misc. query and block/record manipulation methods.
//==------------------------------------------------==//
bool isRegistered(const void* p) const;