|
Boost : |
From: Marcin Kalicinski (kalita_at_[hidden])
Date: 2006-04-20 16:37:39
Hi Everybody,
I see there is some confusion about possible overlap of program_options and
property_tree libraries.
First of all, my opinion is there is very little overlap. The biggest
difference between the libraries is that property_tree is hierarchical and
program_options is linear - i.e. options are accessible through a map-like
interface.
Structure of file formats, like XML, JSON etc. is inherently hierarchical.
The presence of hierarchy is their greatest strength, and most important
feature. Large amount of information is conveyed by structure of the tree
alone, not only by values it contains. The same value in two
different branches of the tree can have completely different meaning.
Contrary to that, in program_options library there is only at best a notion
of "positional options", which is completely different from hierarchy.
Briefly, PO library operates on a flat strings of options, property_tree is
a DOM. Think of property_tree like a replacement for Microsoft XML parser,
or JSON API, or Windows INI API, or registry API. Do you imagine using
program_options to manipulate XML trees, like the ones you get from XML
parser? It is not suited for that, its problem domain lies in completely
different place, namely parsing a linear string of (command-line) options,
possibly supplied as a config file or files.
In addition to that, PO library does not support writing the structures back
to config files. It is not a flaw with the library, it just does not need to
do it, because options for programs are meant to be "one shot", or "read and
forget", like command line arguments. There's not need to store them back
where they came from.
On the other hand, PO library supports many things that do not belong to
property_tree. These include, for example, options descriptions and notify
mechanisms.
Taking all that into account I do not see why anybody insists there might
exist 1:1 correspondence between the libraries. I agree both can parse
command lines, but that's about it. Other functionality is very different.
One has to distinguish between reading command-line options (or other simple
configuration) and reading structured DOM data. For example, take a program
like visual XML editor. It could use both PO and property_tree to read its
startup config (keyboard shortcuts, font etc.). But only property_tree would
be suitable to handle XML files to be parsed, displayed, edited and saved by
the editor. It would be rather ridiculous to use program_options to do that,
although not impossible, if one tried really hard.
Best regards,
Marcin
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk