Reflection in C++ – Load In Place

December 6, 2009 – 10:13 pm

I 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.

  1. 5 Responses to “Reflection in C++ – Load In Place”

  2. Does it support circular pointers?

    By ok on Aug 31, 2010

  3. 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

  1. 3 Trackback(s)

  2. Mar 6, 2010: ifstream
  3. Aug 29, 2010: Clash of the Thread Pools | .mischief.mayhem.soap.
  4. Jan 23, 2011: Reflection in C++ – metadata | .mischief.mayhem.soap.

Post a Comment