A while ago, I was looking for a C/C++ XMLRPC client implementation. However, for some reason or another, I was unsatisfied with the recent implementations, which mostly seem utterly complex for my purposes. That’s why I decided to roll out my own. While the XML building and parsing is more or less straight forward (although there’s too much redundancy and unneccessary tags in the spec for my taste), implementing the possible value types made me scratch my head. The XMLRPC protocol supports a set of data types: integer, string, double etc., but also an array or a struct. Integer and double are native types, string is either a char pointer or a class. How this should be put within one class? My first sketch introduced a quite complex model with an impressing inheritence chain, but then boost::variant came to the rescue:
This defines a type called XmlRpcValue. This type can contain either a string, an int, a bool, a double, or a vector of XmlRpcValues or a string-based map of XmlRpcValues. Isn’t that cool?
We can easily utilize this type like this:
ParserValue in this case is a simple structure containing information about parsed data: