Reflection in C++ – Load In Place
December 6, 2009 – 10:13 pmI played a little bit with my Load-In-Place system. It used to only support vectors of PODs (stored by value). Now it handles also vectors of pointers & vectors of classes. Sample structure that’ll be saved/loaded automatically:
struct IntContainer
{
int* pInt;
};
struct SuperBar
{
unsigned long i;
// [Hidden]
float* p;
bool b;
signed char s;
Color color;
SuperBar* psb;
typedef rde::vector<int> tVec;
tVec v;
rde::vector<Color*> someColors;
rde::vector<SuperBar*> superBars;
rde::vector<IntContainer> containers;
IntContainer ic;
};
[...]
// (fill sb)
// Code to save this.
SaveObject(sb, ofstream, typeRegistry);
// Code to load:
SuperBar* psb = LoadObject<SuperBar>(ifstream, typeRegistry);
Cool thing is, fixup cost for loading is roughly linear (it’s constant per-pointer, no recursion), only saving gets more complicated as structure complexity increases (so it’s still good to be careful, of course). I’ve updated download package.










5 Responses to “Reflection in C++ – Load In Place”
Does it support circular pointers?
By ok on Aug 31, 2010
That’s a good question, I just tested it out of curiosity and it turns out it does, out of the box :). Tested most straightforward case with a pointing to b, b pointing to a. After loading, relationship is preserved.
By admin on Sep 12, 2010