auto.qbk 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. [/==============================================================================
  2. Copyright (C) 2001-2011 Joel de Guzman
  3. Copyright (C) 2001-2011 Hartmut Kaiser
  4. Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. ===============================================================================/]
  7. [section:auto Auto Generator]
  8. [heading Description]
  9. This module includes the description of the `auto_` generator. This generator
  10. can be used to automatically create a generator based on the supplied attribute
  11. type.
  12. [heading Header]
  13. // forwards to <boost/spirit/home/karma/auto.hpp>
  14. #include <boost/spirit/include/karma_auto.hpp>
  15. Also, see __include_structure__.
  16. [heading Namespace]
  17. [table
  18. [[Name]]
  19. [[`boost::spirit::auto_ // alias: boost::spirit::karma::auto_`]]
  20. ]
  21. [heading Model of]
  22. [:__primitive_generator_concept__]
  23. [variablelist Notation
  24. [[`s`] [A variable instance of any type for which a mapping to a
  25. generator type is defined (the meta function
  26. `traits::create_generator_exists` returns `mpl::true_`) or a
  27. __karma_lazy_argument__ that evaluates to any type for which
  28. a mapping to a generator type is defined (the meta function
  29. `traits::create_generator_exists` returns `mpl::true_`).]]
  30. ]
  31. [heading Expression Semantics]
  32. Semantics of an expression is defined only where it differs from, or is
  33. not defined in __primitive_generator_concept__.
  34. [table
  35. [[Expression] [Description]]
  36. [[`auto_`] [Create a generator instance compatible with the
  37. supplied attribute type and use it for output
  38. generation. This generator never fails
  39. (unless the underlying output stream reports an
  40. error).]]
  41. [[`auto_(s)`] [Create a generator instance compatible with the
  42. supplied literal value. This generator never fails
  43. (unless the underlying output stream reports an
  44. error).]]
  45. ]
  46. [heading Additional Requirements]
  47. The `auto_` generators can be used to emit output for any data type for which
  48. a mapping to a generator type is defined (the meta function
  49. `traits::create_generator_exists` returns `mpl::true_`).
  50. The following table outlines the predefined mapping rules from the attribute type
  51. to the generator type. These rules are applied recursively to create the generator
  52. type which can be used to generate output from the given attribute type.
  53. [table
  54. [[Attribute type] [Generator type]]
  55. [[`char`, `wchar_t`] [`standard::char_`, `standard_wide::char_`]]
  56. [[`short`, `int`, `long`] [`short_`, `int_`, `long_`]]
  57. [[`unsigned short`, `unsigned int`, `unsigned long`]
  58. [`ushort_`, `uint_`, `ulong_`]]
  59. [[`float`, `double`, `long double`] [`float_`, `double_`, `long_double`]]
  60. [[`short`, `int`, `long`] [`short_`, `int_`, `long_`]]
  61. [[`long long`, `unsigned long long`]
  62. [`long_long`, `ulong_long`]]
  63. [[`bool`] [`bool_`]]
  64. [[Any string (`char const*`, `std::string`, etc.)]
  65. [`string`]]
  66. [[Any (STL) container] [Kleene Star (unary `'*'`)]]
  67. [[Any Fusion sequence] [Sequence operator (`'<<'`)]]
  68. [[`boost::optional<>`] [Optional operator (unary `'-'`)]]
  69. [[`boost::variant<>`] [Alternative operator (`'|'`)]]
  70. ]
  71. It is possible to add support for any custom data type by implementing a
  72. specialization of the customization point __customize_create_generator__. This
  73. customization can be used also to redefined any of the predefined mappings.
  74. [heading Attributes]
  75. [table
  76. [[Expression] [Attribute]]
  77. [[`auto_`] [`hold_any`, attribute is mandatory (otherwise
  78. compilation will fail)]]
  79. [[`auto_(s)`] [__unused__]]
  80. ]
  81. [important The attribute type `hold_any` exposed by some of the `auto_`
  82. generators is semantically and syntactically equivalent to
  83. the type implemented by __boost_any__. It has been added to /Spirit/
  84. as it has better a performance and a smaller footprint if compared to
  85. __boost_any__.
  86. ]
  87. [note In addition to their usual attribute of type `Attrib` all listed generators
  88. accept an instance of a `boost::optional<Attrib>` as well. If the
  89. `boost::optional<>` is initialized (holds a value) the generators behave
  90. as if their attribute was an instance of `Attrib` and emit the value stored
  91. in the `boost::optional<>`. Otherwise the generators will fail.]
  92. [heading Complexity]
  93. [:The complexity of the `auto_` generator depends on the attribute type. Each
  94. attribute type results in a different generator type to be instantiated which
  95. defines the overall complexity.]
  96. [heading Example]
  97. [note The test harness for the example(s) below is presented in the
  98. __karma_basics_examples__ section.]
  99. Some includes:
  100. [reference_karma_includes]
  101. Some using declarations:
  102. [reference_karma_using_declarations_auto]
  103. And a class definition used in the examples:
  104. [reference_karma_complex]
  105. [reference_karma_auto_complex]
  106. Some usage examples of `auto_` generators:
  107. [reference_karma_auto]
  108. [endsect]