Re: Meta Description for class members
On Oct 8, 2:37 pm, t.lehm...@rtsgroup.net wrote:
Hi,
I've written a binding mechanism (basically intended for XML) for
class members to be able to serialize members of a class by a generic
mechanism of its base class. The binding initializing part looks like
this:
Person::Person()
{
// instance, member, default value, isAttribute
xml::bind(this, _firstName, std::string(""), true);
xml::bind(this, _age, int(0), true);
}
The issue I'm not happy with is the fact that on each creation of such
an instance the base of the person class is storing the binding
infomations. I would like to be able to define a central binding for
the class person (btw: actually a derived class simply adds bindings).
Is this possible and could someone please give a simple example?
How about a virtual function GetBindingCollection something like:
const xml::BindingCollection& Person::GetBindingCollection
{
// This initialization does a deep copy
static xml::BindCollection
collection(Base::GetBindingCollection());
static isInitialize = false;
if (! isInitialized)
{
// instance, member, default value, isAttribute
xml::bind(this, _firstName, std::string(""), true);
xml::bind(this, _age, int(0), true);
isInitialized = true;
}
return collection;
}
There are issues with thread safety here (and making sure people
remember to update GetBindingCollection when they add a new member/
change the base class).
I think there is a boost library that would allow you to initialize
the complete collection with a single statement (so you could get rid
of the isInitialized variable).
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]