Reflection in C++ - Load In Place

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 tVec;
	tVec			v;
	rde::vector<Color*> someColors;
	rde::vector<SuperBar*> superBars;
	rde::vector containers;
	IntContainer	ic;
};
[...]
// (fill sb)
// Code to save this.
SaveObject(sb, ofstream, typeRegistry);
// Code to load:
SuperBar* psb = LoadObject(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.

Old comments

ifstream 2010-03-06 04:01:30

[…] Mail (will not be published) (required) Website © 2009 by Programmingsite tutorials …Reflection in C++ Load In Place | .mischief.mayhem.soap.I played a little bit with my Load-In-Place system. It used to only support vectors of PODs (stored […]

ok 2010-08-31 15:02:47

Does it support circular pointers?

admin 2010-09-12 18:04:12

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.

comments powered by Disqus