generate C/C++ command line argument parsing code from XML (or similar)

dark73

New Member
Is there a tool that generates C/C++ source code from XML (or something similar) to create command line argument parsing functionality?Now a longer explanation of the question:I have up til now used gengetopt for command line argument parsing. It is a nice tool that generates C source code from its own configuration format (a text file). For instance the gengetopt configuration line\[code\]option "max-threads" m "max number of threads" int default="1" optional\[/code\]among other things generates a variable\[code\]int max_threads_arg; \[/code\]that I later can use.But gengetopt doesn't provide me with this functionality:
  • A way to generate Unix man pages from the gengetopt configuration format
  • A way to generate DocBook or HTML documentation from the gengetopt configuration format
  • A way to reuse C/C++ source code and to reuse gengetopt configuration lines when I have multiple programs that share some common command line options
Of course gengetopt can provide me with a documentation text by running \[code\]command --help\[/code\] but I am searching for marked up documentation (e.g. HTML, DocBook, Unix man pages).Do you know if there is any C/C++ command line argument tool/library with a liberal open source license that would suite my needs?I guess that such a tool would use XML to specify the command line arguments. That would make it easy to generate documentation in different formats (e.g. man pages). The XML file should only be needed at build time to generate the C/C++ source code.I know it is possible to use some other command line argument parsing library to read a configuration file in XML at runtime but I am looking for a tool that generate C/C++ source code from XML (or something similar) at build time.Update 1 I would like to do as much as possible of the computations at compile time and as less as possible at run time. So I would like to avoid libraries that give you a map of the command line options, like for instance boost::program_options::variables_map ( tutorial ). I other words, I prefer \[code\]args_info.iterations_arg\[/code\] to \[code\]vm["iterations"].as<int>()\[/code\]User tsug303 suggested the library TCLAP. It looks quite nice. It would fit my needs to divide the options into groups so that I could reuse code when multiple programs share some common options. Although it doesn't generate out the source code from a configuration file format in XML, I almost marked that answer as the accepted answer.But none of the suggested libraries fullfilled all of my requirements so I started thinking about writing my own library. A sketch: A new tool that would take as input a custom XML format and that would generate both C++ code and an XML schema. Some other C++ code is generated from the XML schema with the tool CodeSynthesis XSD. The two chunks of C++ code are combined into a library. One extra benefit is that we get an XML Schema for the command line options and that we get a way to serialize all of them into a binary format (in CDR format generated from CodeSynthesis XSD). I will see if I get the time to write such a library. Better of course is to find a libraray that has already been implemented.Today I read about user Nore's suggested alternative. It looks promising and I will be eager to try it out when the planned C++ code generation has been implemented. The suggestion from Nore looks to be the closest thing to what I have been looking for.
 
Back
Top