As most people have already said it can be done, with a custom built reflection type mechanism in C++ and some template metaprogramming techniques. That's what we've done for our Hdf wrapper library inside our larger application of Opticks (http://opticks.org/). The Hdf wrapper library is tied pretty close to the rest of the application, so you won't be able to just grab the code.
But you can browse it here:
https://opticks.ballforge.net/source/browse/opticks/trunk/4.3.X/Code/application/HdfPlugInLib/
and it's licensed under the LGPL v2.1
Specifically, look at the Hdf5Dataset::readData() and the Hdf5CustomReader and the Hdf5ReadersWriters.cpp
Hope this helps,
Kip
···
________________________________________
From: hdf-forum-bounces@hdfgroup.org [mailto:hdf-forum-bounces@hdfgroup.org] On Behalf Of Dimitris Servis
Sent: Thursday, October 22, 2009 2:15 AM
To: hdf-forum@hdfgroup.org
Subject: Re: [Hdf-forum] Help requested: how to read a compound datatype
Werner
you are correct in your conclusion, just wanted to note that in the particular case he wouldn't have to use inheritance put plain PODs. The problem with the VFD is not only that it's there, but also that you never know where it is. What you're describing is a serialization framework of classes, which considering the hints you give is quite generic, you could also do it with inheritance if you know a priori the classes you want to serialize. But stil you have to know the classes, I think in Richard's case he needs reflection to create objects at run-time and query their contents. This is somehow easier with Java but more complex with C++ especially in the handling of integral types.
regards
-- dimitris
2009/10/21 Werner Benger <werner@cct.lsu.edu>
Richard,
I'm afraid moving to C++ would make the situation worse in your case, since in C++ a class consists of more than just its data members, in particular it also comes with virtual function table (if the class has virtual functions), and there is no way such could be stored in an HDF5 file.
There may be alternatives such as a registry of objects that are mapped to HDF5 id's and allows dynamic creation of objects based on HDF5 id's (type id's) in return, and there are means to create such registries automatically in C++ involving some template metaprogramming techniques, but that's going to be somewhat complex...
Maybe you can describe your problem in more detail about what you would like to achieve? There might be simpler methods...
cheers,
Werner
On Wed, 21 Oct 2009 15:23:48 -0500, Richard van Hees <R.M.van.Hees@sron.nl> wrote:
Dear Elena and Werner,
Thanks for your help and suggestions. I somehow hoped that I lacked some knowledge as a C programmer, but I am afraid that I can not acchieve in C what I would like to do. An alternative for my project could be to move to c++. Would that help me?
Best regards, Richard
--
___________________________________________________________________________
Dr. Werner Benger Visualization Research
Laboratory for Creative Arts and Technology (LCAT)
Center for Computation & Technology at Louisiana State University (CCT/LSU)
211 Johnston Hall, Baton Rouge, Louisiana 70803
Tel.: +1 225 578 4809 Fax.: +1 225 578-5362
_______________________________________________
Hdf-forum is for HDF software users discussion.
Hdf-forum@hdfgroup.org
http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org
This message and any enclosures are intended only for the addressee. Please
notify the sender by email if you are not the intended recipient. If you are
not the intended recipient, you may not use, copy, disclose, or distribute this
message or its contents or enclosures to any other person and any such actions
may be unlawful. Ball reserves the right to monitor and review all messages
and enclosures sent to or from this email address.