views:

125

answers:

2

I have set up a sort of introspection-enabling C++ library that allows, using minimum macros and a fair amount of template trickery, to declare structures and classes that get enriched with some meta-information.

This meta-information captures all important details about each field of the struct/class that you declare, and at the end of the story you are able, for each struct/class enriched in this way, to produce an xml file that dumps, for each field, its name,type,len,offset etc. etc.

For my problem, I don't need to support fields that are pointers, but only primitive types, arrays and STL containers (vectors, lists etc.)

The code that populates these meta-enriched structs/classes (the "producer"), at a certain point serializes them (for now it's a simple binary dump of all primitive types and of all the "buffers" used by the STL containers, if any).

Now I need to start developing a "reader" counterpart that is able at runtime, starting from the xml description that has been built by the "producer", to access the various fields of the stored data.

I think it's a problem of dynamic data-dictionary interpretation, but all that I have found up to know is related to read back xml data, while I have binary data and an xml description of it...

What is the best way to start on this? Is something out there that resembles this problem and that I could get inspiration from?

A: 

/* smarc's keeping it simple */

class xmlstream { ... };

class ibase { void read( xmlstream& rStream ) = 0; void write( xmlstream& rStream ) = 0; };

class classfactory { void produce( xmlstream& rStream ); void consume( xmlstream& rStream );
ibase* create( xmlstream& rStream ); void destroy( ibase* pBase ); };

class class1 : public ibase { static class1* create( ); static void destroy( class1* pObject ); void read( xmlstream& rStream ); void write( xmlstream& rStream ); };

class class2 : public ibase { static class1* create( ); static void destroy( class1* pObject ); void read( xmlstream& rStream ); void write( xmlstream& rStream ); };

Let me if this isn't clear.

Ehm,honestly I'm not really getting your point.. Could you please add some more context and some more details? Tnx...
abigagli
A: 

Did you have a look at Boost Serialization? It pretty much does what you ask for.

lothar