[gmx-developers] XML and std::map?

Vedran Miletić rivanvx at gmail.com
Tue Sep 29 14:21:45 CEST 2015


sorry for the delay, I started replying and then got carried away by
something else that was more urgent.

Anyway, if you are still considering std::map, my thoughts are below.

2015-09-23 10:23 GMT+02:00 David van der Spoel <spoel at xray.bmc.uu.se>:
> I guess the routine parsing the std::map has to interpret what is there,
> right? And as such this routine has to have the information that is needed.
> The idea would be just to have a generic tree structure to parse, and to
> have just one routine deal with libxml2 rather than directly interfacing to
> libxml2 from every file that has to be read.

In dynamic typing languages, yes. In C++, you can not do that; you
have to predict the number of levels of nesting in advance. E.g. for
XML with two levels of nesting you have:

std::map<std::string, std::map<std::string, std::string> >

With three levels of nesting you would have:

std::map<std::string, std::map<std::string, std::map<std::string,
std::string> > >

I don't see how can you overload the function and return the right
type. The best you can do is make parsers for specific XML files which
always have the same number of nesting levels.

> The question is therefore mainly whether std::map is the right structure?

Would be interesting to try, nevertheless.


Vedran Miletić

More information about the gromacs.org_gmx-developers mailing list