This archive contains answers to questions sent to Unidata support through mid-2025. Note that the archive is no longer being updated. We provide the archive for reference; many of the answers presented here remain technically correct, even if somewhat outdated. For the most up-to-date information on the use of NSF Unidata software and data services, please consult the Software Documentation first.
Lynton, > I am currently looking at NcCompoundType related functions > addCompoundType and addMember (see ncfile.cpp and ncvar.cpp). > It seems to me that the that addCompoundType should be a template > function with one of its arguments being the user-defined structure > (currently onky the size of the structure is required). The > addCompoundType function should identify and store the (a) the size of > the structure (b) the members of the struture, recording them as > strings, and (c) the offset of each member. > That way it will enable addMember to make all the required calls to > nc_insert_compound for a single structure in one call, without the user > having to supply more information about the structure members. Also it > will make putting data into the structures easier. > > However, is it possible to extract the information about the structure > automatically? I have been looking hard on the web for some help on this > and have so far failed. > > Any ideas? I'm no C++ expert, but I think what you want is a "reflection" capability for C++. The language lacks general reflection functionality, but RTTI is a start. Here is what looks like a good summary of possible approaches along with their advantages and disadvantages and an implementation: http://www.garret.ru/cppreflection/docs/reflect.html Another implementation of a C++ reflection library and a later improvement are available here, but I don't know anything about the quality or usefulness of these techniques for the specific problem you are trying to solve: http://www.codeproject.com/KB/library/libreflection.aspx http://www.codeproject.com/KB/library/libreflection2.aspx --Russ Russ Rew UCAR Unidata Program address@hidden http://www.unidata.ucar.edu Ticket Details =================== Ticket ID: MSV-188900 Department: Support netCDF Priority: Normal Status: Closed