Re: Is there a native C++ class library that provides similar ease of use to the .Net XmlSerializer?
"David Lowndes" <DavidL@example.invalid> wrote in message
news:4eb6e31v0dojelcsu8fqksrqhjtae18h4u@4ax.com...
Perhaps some of the nice features of the .NET libraries are possible
thanks
to technologies like e.g. reflection, that are present in C# but not in
C++
Reflection is available on .Net (and Java I guess) and would be
presumably be available with any .Net language not just C#. It's
advantage is that it can make such things appear invisible to the
casual user, but as we all know, you don't get something for nothing
(it must always have an overhead - and one that's unused most of the
time).
I guess I was looking for an almost invisible mechanism that someone
cleverer than me has already done in native C++ - perhaps something
relatively elegant could be done using templates.
Given how much emphasis manipulating XML has in .Net, I think it'd be
useful to have equivalent almost as easy to use facilities in native
C++. A useful addition for Orcas +1 maybe?
I think that the order of construction of members is well enough defined
that, used in conjunction with a thread-local variable for the serialization
context or lack thereof, it should be possible to have automatic
self-serialization.
i.e.
struct MyRecord
{
serialized<int> id;
serialized<std::string> firstName;
serialized<std::string> lastName;
};
You'd need at least one function (member function?) that has explicit
specializations, and then define the constructor and copy-constructor to
invoke serialization functionality when the current thread has an active
serialization context. Then the serialization wrapper just has to setup the
context and make a copy of the object, letting the compiler descend into all
members automatically, and deserialization means returning a new instance.
Dave