changes.xml 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?xml version="1.0" standalone="yes"?>
  2. <!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
  3. "http://www.boost.org/tools/boostbook/dtd/boostbook.dtd"
  4. [
  5. <!ENTITY % entities SYSTEM "program_options.ent" >
  6. %entities;
  7. ]>
  8. <section id="program_options.changes">
  9. <title>Changes since formal review</title>
  10. <para>During formal review, a large number of changes was suggested. To make
  11. using the new version easier, the implemented changes are described
  12. below.</para>
  13. <para>Let's start with an example. The following is a typical code for the
  14. reviewed version:<programlisting>
  15. options_description desc;
  16. desc.add_options()
  17. ("magic", parameter&lt;int&gt;("value"), "magic value for the program")
  18. .default_value("43")
  19. variables_map vm;
  20. options_and_arguments oa1 = parse_command_line(ac, av, desc);
  21. store(oa1, vm, desc)
  22. variables_map vm2;
  23. ifstream ifs("main.cfg");
  24. options_and_arguments oa2 = parse_config_file(ifs, desc);
  25. store(oa1, vm2, desc);
  26. vm.next(&amp;vm2);
  27. </programlisting>The code for the current version would look like:
  28. <programlisting>
  29. options_description desc;
  30. desc.add_options()
  31. ("magic", value&lt;int&gt;()->default_value(43),
  32. "magic value for the program")
  33. variables_map vm;
  34. store(parse_command_line(ac, av, desc), vm);
  35. ifstream ifs("main.cfg");
  36. store(parse_command_line(ifs, desc), vm);
  37. notify(vm);
  38. </programlisting>
  39. </para>
  40. <para>Let's examine all the changes in detail</para>
  41. <section>
  42. <title>Option description</title>
  43. <itemizedlist>
  44. <listitem>
  45. <para>The <code>parameter</code> function was renamed to
  46. <code>value</code>. Rationale: "paramater" is yet another term with no
  47. clear definition, while "value" is already used everywhere in
  48. docs.</para>
  49. </listitem>
  50. <listitem>
  51. <para>The default value is specified in different place, and should
  52. use the value of desired type, not string. Previous code was:
  53. <programlisting>
  54. ("magic", parameter&lt;int&gt;("value")).default_value("43")
  55. </programlisting>
  56. and the new code is
  57. <programlisting>
  58. ("magic", parameter&lt;int&gt;("value")->default_value(43));
  59. </programlisting>
  60. Rationale: the new way is less restrictive. At the same time, the
  61. new design allows to implement other behaviour, like validation of
  62. the value, which require knowledge of the value type.
  63. </para>
  64. </listitem>
  65. <listitem>
  66. <para>The number of token value can take on command line, which was
  67. specified using character suffix appended to value name, is now
  68. specified using more explicit member calls. Moreover, it's not longer
  69. possible to specify the "value name".
  70. For example:
  71. <programlisting>("numbers", parameter&lt;int&gt;("n+"))</programlisting>
  72. has became
  73. <programlisting>("numbers", value&lt;int&gt;()->multitoken())</programlisting>
  74. Rationale: such modifiers tend to make command line usage less
  75. clear. There's no need to make evil things too easy to do.
  76. The "value name" had only two roles: specifying modifiers, and
  77. telling what to output in automated help. The first role has became
  78. obsolete, and the second was questionable too. It was very unclear how
  79. to decide on the best "value name", and eventually the selection was randon.
  80. </para>
  81. </listitem>
  82. </itemizedlist>
  83. </section>
  84. <section>
  85. <title>Parsers</title>
  86. <itemizedlist>
  87. <listitem>
  88. <para>The <code>options_and_argument</code> class was removed.</para>
  89. </listitem>
  90. <listitem>
  91. <para>The <code>cmdline</code> and <code>config_file</code> classes
  92. were removed from the public interface. Various command line styles
  93. are now declared in the <code>command_line_style</code> subnamespace.
  94. </para>
  95. </listitem>
  96. <listitem>
  97. <para>New function <code>parse_environment</code> was added.</para>
  98. </listitem>
  99. <listitem>
  100. <para>Support for positional options was added</para>
  101. </listitem>
  102. </itemizedlist>
  103. </section>
  104. <section>
  105. <title>Storage</title>
  106. <itemizedlist>
  107. <listitem>
  108. <para>The <code>notify</code> function should be called after all
  109. sources are stored in a <code>variales_map</code> instance. This is
  110. done to property support priority of configuration sources.
  111. </para>
  112. </listitem>
  113. </itemizedlist>
  114. </section>
  115. </section>
  116. <!--
  117. Local Variables:
  118. mode: xml
  119. sgml-indent-data: t
  120. sgml-parent-document: ("program_options.xml" "section")
  121. sgml-set-face: t
  122. End:
  123. -->