customization_points.qbk 115 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869
  1. [/==============================================================================
  2. Copyright (C) 2001-2011 Hartmut Kaiser
  3. Copyright (C) 2001-2011 Joel de Guzman
  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. [import ../example/karma/customize_embedded_container.cpp] [/ this pulls in the embedded_container example]
  8. [import ../example/karma/customize_counter.cpp] [/ this pulls in the counter example]
  9. [import ../example/karma/customize_use_as_container.cpp] [/ this pulls in the use_as_container example]
  10. [def __customize_embedded_container_example__ [link spirit.advanced.customize.iterate.container_iterator.example embedded_container_example]]
  11. [def __customize_counter_example__ [link spirit.advanced.customize.iterate.deref_iterator.example counter_example]]
  12. [def __customize_use_as_container_example__ [link spirit.advanced.customize.iterate.next_iterator.example use_as_container]]
  13. [section:customize Customization of Spirit's Attribute Handling]
  14. [heading Why do we need Attribute Customization Points]
  15. [important Before you read on please be aware that the interfaces described in
  16. this section are not finalized and may change in the future without
  17. attempting to be backwards compatible. We document the customization
  18. point interfaces anyways as we think they are important.
  19. Understanding customization points helps understanding Spirit.
  20. Additionally they prove to be powerful tools enabling full
  21. integration of the user's data structures with /Qi's/ parsers and
  22. /Karma's/ generators.]
  23. __spirit__ has been written with extensibility in mind. It provides many
  24. different attribute customization points allowing to integrate custom data
  25. types with the process of parsing in __qi__ or output generation with
  26. __karma__. All attribute customization points are exposed using a similar
  27. technique: full or partial template specialization. __spirit__ generally
  28. implements the main template, providing a default implementation. You as the
  29. user have to provide a partial or full specialization of this template for the
  30. data types you want to integrate with the library. In fact, the library uses
  31. these customization points itself for instance to handle the magic of the
  32. __unused_type__ attribute type.
  33. Here is an example showing the __customize_container_value__ customization point
  34. used by different parsers (such as __qi_kleene__, __qi_plus__, etc.) to find
  35. the attribute type to be stored in a supplied STL container:
  36. [import ../../../../boost/spirit/home/support/container.hpp]
  37. [customization_container_value_default]
  38. This template is instantiated by the library at the appropriate places while
  39. using the supplied container type as the template argument. The embedded `type`
  40. is used as the attribute type while parsing the elements to be store in that
  41. container.
  42. The following example shows the predefined specialization for __unused_type__:
  43. [customization_container_value_unused]
  44. which defines its embedded `type` to be __unused_type__ as well, this way
  45. propagating the 'don't care' attribute status to the embedded parser.
  46. All attribute customization points follow the same scheme. The last template
  47. parameter is always `typename Enable = void` allowing to apply SFINAE for
  48. fine grained control over the template specialization process. But most of the
  49. time you can safely forget about its existence.
  50. The following sections will describe all customization points, together with a
  51. description which needs to be specialized for what purpose.
  52. [heading The Usage of Customization Points]
  53. The different customizations points are used by different parts of the library.
  54. Part of the customizations points are used by both, __qi__ and __karma__,
  55. whereas others are specialized to be applied for one of the sub-libraries only.
  56. We will explain when a specific customization point needs to be implemented and,
  57. equally important, which customization points need to be implemented at the
  58. same time. Often it is not sufficient to provide a specialization for one
  59. single customization point only, in this case you as the user have to provide
  60. all necessary customizations for your data type you want to integrate with the
  61. library.
  62. [/////////////////////////////////////////////////////////////////////////////]
  63. [section:is_container Determine if a Type Should be Treated as a Container (Qi and Karma)]
  64. [heading is_container]
  65. The template `is_container` is a template meta-function used as an attribute
  66. customization point. It is invoked by the /Qi/ __qi_sequence__ (`>>`) and
  67. /Karma/ __karma_sequence__ operators in order to determine whether a supplied
  68. attribute can potentially be treated as a container.
  69. [heading Header]
  70. #include <boost/spirit/home/support/container.hpp>
  71. Also, see __include_structure__.
  72. [note This header file does not need to be included directly by any user
  73. program as it is normally included by other Spirit header files relying
  74. on its content.]
  75. [heading Namespace]
  76. [table
  77. [[Name]]
  78. [[`boost::spirit::traits`]]
  79. ]
  80. [heading Synopsis]
  81. template <typename Container, typename Enable>
  82. struct is_container
  83. {
  84. <unspecified>;
  85. };
  86. [heading Template parameters]
  87. [table
  88. [[Parameter] [Description] [Default]]
  89. [[`Container`] [The type, `Container` which needs to
  90. be tested whether it has to be treated
  91. as a container] [none]]
  92. [[`Enable`] [Helper template parameter usable to selectively
  93. enable or disable certain specializations
  94. of `is_container` utilizing SFINAE (i.e.
  95. `boost::enable_if` or `boost::disable_if`).] [`void`]]
  96. ]
  97. [variablelist Notation
  98. [[`C`] [A type to be tested whether it needs to be treated
  99. as a container.]]
  100. [[`T1`, `T2`, ...] [Arbitrary types]]
  101. ]
  102. [heading Expression Semantics]
  103. [table
  104. [[Expression] [Semantics]]
  105. [[`is_container<C>::type`] [Result of the metafunction that evaluates to
  106. `mpl::true_` if a given type, `C`, is to be
  107. treated as a container, `mpl::false_` otherwise
  108. Generally, any implementation of `is_container`
  109. needs to behave as if if was a __mpl_boolean_constant__..]]
  110. ]
  111. [heading Predefined Specializations]
  112. __spirit__ predefines specializations of this customization point for
  113. several types. The following table lists those types together with the
  114. conditions for which the corresponding specializations will evaluate to
  115. `mpl::true_` (see __mpl_boolean_constant__):
  116. [table
  117. [[Template Parameters] [Semantics]]
  118. [[`T`] [Returns `mpl::true_` if `T` has the following
  119. embedded types defined: `value_type`,
  120. `iterator`, `size_type`, and`reference`.
  121. Otherwise it will return `mpl::false_`.]]
  122. [[`boost::optional<T>`] [Returns `is_container<T>::type`]]
  123. [[`boost::variant<T1, T2, ...>`]
  124. [Returns `mpl::true_` if at least one of the
  125. `is_container<TN>::type` returns `mpl::true_`
  126. (where `TN` is `T1`, `T2`, ...).
  127. Otherwise it will return `mpl::false_`.]]
  128. [[__unused_type__] [Returns `mpl::false_`.]]
  129. ]
  130. [heading When to implement]
  131. The customization point `is_container` needs to be implemented for a specific
  132. type whenever this type is to be used as an attribute in place of a STL
  133. container. It is applicable for parsers (__qi__) and generators (__karma__).
  134. As a rule of thumb: it has to be implemented whenever a certain type
  135. is to be passed as an attribute to a parser or a generator normally exposing a
  136. STL container, `C` and if the type does not expose the interface of a STL container
  137. (i.e. `is_container<C>::type` would normally return `mpl::false_`). These
  138. components have an attribute propagation rule in the form:
  139. a: A --> Op(a): vector<A>
  140. where `Op(a)` stands for any meaningful operation on the component `a`.
  141. [heading Related Attribute Customization Points]
  142. If this customization point is implemented, the following other customization
  143. points might need to be implemented as well.
  144. [table
  145. [[Name] [When to implement]]
  146. [[__customize_container_value__] [Needs to be implemented whenever `is_container` is implemented.]]
  147. [[__customize_push_back_container__] [Qi: __qi_list__, __qi_kleene__, __qi_plus__, [qi_repeat Repeat].]]
  148. [[__customize_container_iterator__] [Karma: __karma_list__, [karma_kleene Kleene (unary `*`)], __karma_plus__, [karma_repeat Repeat].]]
  149. [[__customize_begin_container__] [Karma: __karma_list__, [karma_kleene Kleene (unary `*`)], __karma_plus__, [karma_repeat Repeat].]]
  150. [[__customize_end_container__] [Karma: __karma_list__, [karma_kleene Kleene (unary `*`)], __karma_plus__, [karma_repeat Repeat].]]
  151. [[__customize_deref_iterator__] [Karma: __karma_list__, [karma_kleene Kleene (unary `*`)], __karma_plus__, [karma_repeat Repeat].]]
  152. [[__customize_next_iterator__] [Karma: __karma_list__, [karma_kleene Kleene (unary `*`)], __karma_plus__, [karma_repeat Repeat].]]
  153. [[__customize_compare_iterators__] [Karma: __karma_list__, [karma_kleene Kleene (unary `*`)], __karma_plus__, [karma_repeat Repeat].]]
  154. [[__customize_clear_value__] [Qi: __qi_list__, __qi_kleene__, __qi_plus__, [qi_repeat Repeat].]]
  155. ]
  156. [heading Example]
  157. For examples of how to use the customization point `is_container` please
  158. see here: __customize_embedded_container_example__,
  159. __customize_use_as_container_example__, and __customize_counter_example__.
  160. [endsect] [/ is_container]
  161. [/////////////////////////////////////////////////////////////////////////////]
  162. [section:is_string Determine if a Type Should be Treated as a String (Qi and Karma)]
  163. [heading is_string]
  164. The `is_string` customization point is a template meta-function. It is used by
  165. /Qi/ [qi_lit_string String Literals] (`lit(str)`), /Qi/ [qi_lit_char Character Literals]
  166. (`lit(c)`), /Karma/ [karma_lit_string String Literals] (`lit(str)`), /Karma/ [karma_lit_char Character Literals]
  167. (`lit(c)`) and other Spirit components. It determines whether a supplied type
  168. can be treated as a string.
  169. [heading Module Headers]
  170. #include <boost/spirit/home/support/string_traits.hpp>
  171. Also, see __include_structure__.
  172. [note This header file does not need to be included directly by any user
  173. program as it is normally included by other Spirit header files relying
  174. on its content.]
  175. [heading Namespace]
  176. [table
  177. [[Name]]
  178. [[`boost::spirit::traits`]]
  179. ]
  180. [heading Synopsis]
  181. template <typename T>
  182. struct is_string
  183. {
  184. <unspecified>;
  185. };
  186. [heading Template parameters]
  187. [table
  188. [[Parameter] [Description] [Default]]
  189. [[`T`] [The type, `T` which needs to be tested as a string] [none]]
  190. ]
  191. [variablelist Notation
  192. [[`T`] [An arbitrary type.]]
  193. [[`N`] [An arbitrary integral constant.]]
  194. [[`Char`] [A character type.]]
  195. [[`Traits`] [A character traits type.]]
  196. [[`Allocator`] [A standard allocator type.]]
  197. ]
  198. [heading Expression Semantics]
  199. [table
  200. [[Expression] [Semantics]]
  201. [[`is_string<T>::type`] [Result of the metafunction that evalutes to mpl::true_
  202. if a given type, `T`, is to be treated as a string and
  203. mpl::false_ otherwise. Generally,
  204. any implementation of `is_string` needs to behave as
  205. if if was a __mpl_boolean_constant__.]]
  206. ]
  207. [heading Predefined Specializations]
  208. [table
  209. [[Type] [Semantics]]
  210. [[`T`] [Returns `mpl::false_`.]]
  211. [[`T const`] [Returns `is_string<T>`.]]
  212. [[`char const*`] [Returns `mpl::true_`.]]
  213. [[`wchar_t const*`] [Returns `mpl::true_`.]]
  214. [[`char*`] [Returns `mpl::true_`.]]
  215. [[`wchar_t*`] [Returns `mpl::true_`.]]
  216. [[`char[N]`] [Returns `mpl::true_`.]]
  217. [[`wchar_t[N]`] [Returns `mpl::true_`.]]
  218. [[`char const[N]`] [Returns `mpl::true_`.]]
  219. [[`wchar_t const[N]`] [Returns `mpl::true_`.]]
  220. [[`char(&)[N]`] [Returns `mpl::true_`.]]
  221. [[`wchar_t(&)[N]`] [Returns `mpl::true_`.]]
  222. [[`char const(&)[N]`] [Returns `mpl::true_`.]]
  223. [[`wchar_t const(&)[N]`] [Returns `mpl::true_`.]]
  224. [[`std::basic_string<Char, Traits, Allocator>`] [Returns `mpl::true_`.]]
  225. ]
  226. [heading When to implement]
  227. This customization point needs to be implemented to use user-defined string classes
  228. that do not correspond to std::string syntax and semantics.
  229. [heading Related Attribute Customization Points]
  230. If this customization point is implemented, the following other customization
  231. points need to be implemented as well.
  232. [table
  233. [[Name] [When to implement]]
  234. [[__customize_is_char__] [For string types whose underlying character type
  235. is not `char` or `wchar_t`, `is_char` must be
  236. implemented.]]
  237. [[__customize_char_type_of__] [Whenever `is_string` is implemented.]]
  238. [[__customize_extract_c_string__] [Whenever `is_string` is implemented.]]
  239. ]
  240. [/ TODO: examples ]
  241. [endsect] [/ is_string]
  242. [/////////////////////////////////////////////////////////////////////////////]
  243. [section:handles_container Determine Whether a Component Handles Container Attributes (Qi and Karma)]
  244. [heading handles_container]
  245. The template `handles_container` is a template meta-function used as an attribute
  246. customization point. It is invoked by the /Qi/ __qi_sequence__ (`>>`) and
  247. /Karma/ __karma_sequence__ operators in order to determine whether a sequence
  248. element (component) handles container attributes directly. This customization
  249. point is invoked for container attributes only, and only if the sequence is
  250. compatible with the supplied container attribute.
  251. If a component, which is part of a sequence is able to handle a container
  252. attribute directly, the sequence passes the attribute to the component without
  253. any additional action. In __qi__ the component uses the attribute to directly
  254. store all matched attributes. In __karma__ the generator component extracts
  255. the attributes needed for output generation directly from this attribute.
  256. If a component, which is part of a sequence is not able to handle container
  257. attributes, in __qi__ the sequence passes a new instance of the container
  258. attributes' `value_type` to the parser component, inserting the result into
  259. the attribute on behalf of the parser component. In __karma__ the sequence
  260. extracts the next container element on behalf of the generator component and
  261. passing it the extracted value.
  262. [heading Header]
  263. #include <boost/spirit/home/support/handles_container.hpp>
  264. Also, see __include_structure__.
  265. [note This header file does not need to be included directly by any user
  266. program as it is normally included by other Spirit header files relying
  267. on its content.]
  268. [heading Namespace]
  269. [table
  270. [[Name]]
  271. [[`boost::spirit::traits`]]
  272. ]
  273. [heading Synopsis]
  274. template <
  275. typename Component, typename Attribute, typename Context,
  276. typename Iterator, typename Enable>
  277. struct handles_container
  278. {
  279. <unspecified>;
  280. };
  281. [heading Template parameters]
  282. [table
  283. [[Parameter] [Description] [Default]]
  284. [[`Component`] [The component type `Component` which needs to
  285. be tested whether it handles container attributes
  286. directly.] [none]]
  287. [[`Attribute`] [The attribute type `Attribute` as passed to the
  288. sequence operator.] [none]]
  289. [[`Context`] [This is the type of the current component execution
  290. context.] [`unused_type`]]
  291. [[`Iterator`] [The type, `Iterator` is the type of the iterators
  292. used to invoke the component.] [`unused_type`]]
  293. [[`Enable`] [Helper template parameter usable to selectively
  294. enable or disable certain specializations
  295. of `is_container` utilizing SFINAE (i.e.
  296. `boost::enable_if` or `boost::disable_if`).] [`void`]]
  297. ]
  298. [variablelist Notation
  299. [[`Component`] [A component type to be tested whether it directly handles
  300. container attributes in the context of sequences.]]
  301. [[`Attribute`] [A container attribute type as passed to the sequence.]]
  302. [[`T1`, `T2`, ...] [Arbitrary types]]
  303. ]
  304. [heading Expression Semantics]
  305. [table
  306. [[Expression] [Semantics]]
  307. [[`handles_container<Component, Attribute>::type`]
  308. [Result of the metafunction that evaluates to
  309. `mpl::true_` if a given component type `Component`,
  310. handles container attributes directly,
  311. `mpl::false_` otherwise. Generally,
  312. any implementation of `handles_container` needs to
  313. behave as if if was a __mpl_boolean_constant__.]]
  314. ]
  315. [heading Predefined Specializations]
  316. __spirit__ predefines specializations of this customization point for
  317. several types. The following table lists those types together with the
  318. conditions for which the corresponding specializations will evaluate to
  319. `mpl::true_` (see __mpl_boolean_constant__):
  320. [table
  321. [[Template Parameters] [Semantics]]
  322. [[`Component`, `Attribute`] [Always returns `mpl::false_` (the default).]]
  323. [[`rule<Iterator, T1, T2, T3, T4>`, `Attribute`]
  324. [Returns `is_container<A>`, where `A` is the
  325. attribute exposed by the rule (__qi__ and
  326. __karma__).]]
  327. [[`grammar<Iterator, T1, T2, T3, T4>`, `Attribute`]
  328. [Returns `is_container<A>`, where `A` is the
  329. attribute exposed by the grammar (__qi__ and
  330. __karma__).]]
  331. ]
  332. [heading When to implement]
  333. The customization point `handles_container` needs to be implemented for a
  334. specific type whenever this type directly handles container attributes.
  335. It is applicable for parsers (__qi__) and generators (__karma__). It will have
  336. to be implemented under rare circumstances only.
  337. [/ TODO: examples ]
  338. [endsect] [/ handles_container]
  339. [/////////////////////////////////////////////////////////////////////////////]
  340. [section:transform Transform an Attribute to a Different Type (Qi and Karma)]
  341. [heading transform_attribute]
  342. The template `transform_attribute` is a type used as an attribute customization
  343. point. It is invoked by /Qi/ `rule`, semantic action and `attr_cast`, and /Karma/
  344. `rule`, semantic action and [karma_attr_cast `attr_cast`]. It is used to
  345. automatically transform the user
  346. provided attribute to the attribute type expected by the right hand side
  347. component (for `rule`), the semantic action, or the embedded component
  348. (for `attr_cast`).
  349. [note The interface of this customization point has been changed with Boost
  350. V1.44. We added the `Domain` template parameter to allow for more fine
  351. grained specializations for __qi__ and __karma__.]
  352. [heading Module Headers]
  353. #include <boost/spirit/home/support/attributes.hpp>
  354. Also, see __include_structure__.
  355. [note This header file does not need to be included directly by any user
  356. program as it is normally included by other Spirit header files relying
  357. on its content.]
  358. [heading Namespace]
  359. [table
  360. [[Name]]
  361. [[`boost::spirit::traits`]]
  362. ]
  363. [heading Synopsis]
  364. template <typename Exposed, typename Transformed, typename Domain, typename Enable>
  365. struct transform_attribute
  366. {
  367. typedef <unspecified> type;
  368. static type pre(Exposed& val);
  369. static void post(Exposed& val, type attr); // Qi only
  370. static void fail(Exposed&); // Qi only
  371. };
  372. [heading Template parameters]
  373. [table
  374. [[Parameter] [Description] [Default]]
  375. [[`Exposed`] [The attribute type supplied to the component
  376. which needs to be transformed.] [none]]
  377. [[`Transformed`] [The attribute type expected by the component
  378. to be provided as the result of the transformation.] [none]]
  379. [[`Domain`] [The domain of the sub library the template is
  380. instantiated in. Typically this is either `qi::domain`
  381. or `karma::domain`.] [none]]
  382. [[`Enable`] [Helper template parameter usable to selectively
  383. enable or disable certain specializations
  384. of `transform_attribute` utilizing SFINAE (i.e.
  385. `boost::enable_if` or `boost::disable_if`).] [`void`]]
  386. ]
  387. [variablelist Notation
  388. [[`Exposed`] [The type, `Exposed` is the type of the attribute as
  389. passed in by the user.]]
  390. [[`Transformed`] [The type, `Transformed` is the type of the attribute
  391. as passed along to the right hand side of the `rule`
  392. (embedded component of `attr_cast`).]]
  393. [[`Domain`] [The domain of the sub library the template is
  394. instantiated in. Typically this is either `qi::domain`
  395. or `karma::domain`.]]
  396. [[`exposed`] [An instance of type `Exposed`.]]
  397. [[`transformed`] [An instance of type `Transformed`.]]
  398. ]
  399. [heading Expression Semantics]
  400. [table
  401. [[Expression] [Semantics]]
  402. [[`transform_attribute<Exposed, Transformed, Domain>::type`]
  403. [Evaluates to the type to be used as the result of the
  404. transformation (to be passed to the right hand side of
  405. the `rule` or to the embedded component of the
  406. `attr_cast`. Most of the time this is equal to
  407. `Transformed`, but in other cases this might evaluate to
  408. `Transformed&` instead avoiding superfluous object
  409. creation.]]
  410. [[
  411. ``type transform_attribute<Exposed, Transformed, Domain>::pre(exposed)``]
  412. [Do `pre`-transformation before invoking the right hand
  413. side component for `rule` (or the embedded component
  414. for `attr_cast`). This takes the attribute supplied as by
  415. the user (of type `Exposed`) and returns the attribute
  416. to be passed down the component hierarchy (of the type
  417. as exposed by the metafunction `type`). This function
  418. will be called in /Qi/ and for /Karma/.]]
  419. [[
  420. ``void transform_attribute<Exposed, Transformed, Domain>::post(exposed, transformed)``]
  421. [Do `post`-transformation after the invocation of the
  422. right hand side component for `rule` (or the embedded
  423. component for `attr_cast`). This takes the original
  424. attribute as supplied by the user and the attribute
  425. as returned from the right hand side (embedded)
  426. component and is expected to propagate the result back
  427. into the supplied attribute instance. This function
  428. will be called in /Qi/ only.]]
  429. [[
  430. ``void transform_attribute<Exposed, Transformed, Domain>::fail(exposed)``]
  431. [Handling failing parse operations of the
  432. right hand side component for `rule` (or the embedded
  433. component for `attr_cast`). This function
  434. will be called in /Qi/ only.]]
  435. ]
  436. [heading Predefined Specializations]
  437. [table
  438. [[Template parameters] [Semantics]]
  439. [[`Exposed`, `Transformed`] [`type` evaluates to `Transformed`,
  440. `pre()` returns a new instance of `Transformed`
  441. constructed from the argument of type `Exposed`,
  442. `post()` assigns `transformed` to `exposed`.]]
  443. [[`optional<Exposed>`, `Transformed`,
  444. `typename disable_if<is_same<optional<Exposed>, Transformed> >::type`]
  445. [`type` evaluates to `Transformed&`,
  446. `pre()` returns a reference to the instance of `Transformed`
  447. stored in the passed optional (the argument of type `optional<Exposed>`),
  448. the optional instance is initialized, if needed.
  449. `post()` does nothing, `fail()` resets the
  450. optional (its parameter) instance to the non-initialized state.]]
  451. [[`Exposed&`, `Transformed`] [`type` evaluates to `Transformed`,
  452. `pre()` returns a new instance of `Transformed`
  453. constructed from the argument of type `Exposed`,
  454. `post()` assigns `transformed` to `exposed`.]]
  455. [[`Attrib&`, `Attrib`] [`type` evaluates to `Attrib&`,
  456. `pre()` returns it's argument, `post()` does
  457. nothing.]]
  458. [[`Exposed const`, `Transformed`] [(usind in /Karma/ only) `type` evaluates to
  459. `Transformed`, `pre()` returns it's argument,
  460. `post()` is not implemented.]]
  461. [[`Attrib const&`, `Attrib`] [(usind in /Karma/ only) `type` evaluates to `Attrib const&`,
  462. `pre()` returns it's argument, `post()` is not
  463. implemented.]]
  464. [[`Attrib const`, `Attrib`] [(usind in /Karma/ only) `type` evaluates to `Attrib const&`,
  465. `pre()` returns it's argument, `post()` is not
  466. implemented.]]
  467. [[__unused_type__, `Attrib`] [`type` evaluates to __unused_type__, `pre()`
  468. and `post()` do nothing.]]
  469. [[`Attrib`, __unused_type__] [`type` evaluates to __unused_type__, `pre()`
  470. and `post()` do nothing.]]
  471. ]
  472. [heading When to implement]
  473. The customization point `transform_attribute` needs to be implemented for a
  474. specific pair of types whenever the attribute type supplied to a `rule` or
  475. `attr_cast` cannot automatically transformed to the attribute type expected by
  476. the right hand side of the `rule` (embedded component of the `attr_cast`)
  477. because the default implementation as shown above is not applicable. Examples
  478. for this could be that the type `Transformed` is not constructible from
  479. the type `Exposed`.
  480. [/ TODO: examples ]
  481. [endsect] [/ transform]
  482. [/////////////////////////////////////////////////////////////////////////////]
  483. [/ section:optional Handling of Optional Attributes (Qi and Karma)]
  484. [/ optional_attribute]
  485. [/ endsect] [/ optional]
  486. [/////////////////////////////////////////////////////////////////////////////]
  487. [section:assign_to Store a Parsed Attribute Value (Qi)]
  488. After parsing input and generating an attribute value this value needs to
  489. assigned to the attribute instance provided by the user. The customization
  490. points `assign_to_attribute_from_iterators` and `assign_to_attribute_from_value`
  491. are utilized to adapt this assignment to the concrete type to be assigned.
  492. This section describes both.
  493. [section:assign_to_attribute_from_iterators Store an Attribute after a Parser Produced a Pair of Iterators (Qi)]
  494. [heading assign_to_attribute_from_iterators]
  495. The template `assign_to_attribute_from_iterators` is a type used as an attribute
  496. customization point. It is invoked by the those /Qi/ parsers not producing any
  497. attribute value but returning a pair of iterators pointing to the matched input
  498. sequence. It is used to either store the iterator pair into the attribute
  499. instance provided by the user or to convert the iterator pair into an attribute
  500. as provided by the user.
  501. [heading Module Headers]
  502. #include <boost/spirit/home/qi/detail/assign_to.hpp>
  503. Also, see __include_structure__.
  504. [note This header file does not need to be included directly by any user
  505. program as it is normally included by other Spirit header files relying
  506. on its content.]
  507. [heading Namespace]
  508. [table
  509. [[Name]]
  510. [[`boost::spirit::traits`]]
  511. ]
  512. [heading Synopsis]
  513. template <typename Attrib, typename Iterator, typename Enable>
  514. struct assign_to_attribute_from_iterators
  515. {
  516. static void call(Iterator const& first, Iterator const& last, Attrib& attr);
  517. };
  518. [heading Template parameters]
  519. [table
  520. [[Parameter] [Description] [Default]]
  521. [[`Attrib`] [The type, `Attrib` is the type of the attribute as
  522. passed in by the user.] [none]]
  523. [[`Iterator`] [The type, `Iterator` is the type of the iterators
  524. as produced by the parser.] [none]]
  525. [[`Enable`] [Helper template parameter usable to selectively
  526. enable or disable certain specializations
  527. of `assign_to_attribute_from_value` utilizing SFINAE (i.e.
  528. `boost::enable_if` or `boost::disable_if`).] [`void`]]
  529. ]
  530. [variablelist Notation
  531. [[`Attrib`] [A type to be used as the target to store the attribute value in.]]
  532. [[`attr`] [An attribute instance of type `Attrib`.]]
  533. [[`Iterator`] [The iterator type used by the parser. This type usually
  534. corresponds to the iterators as passed in by the user.]]
  535. [[`begin`, `end`] [Iterator instances of type `Iterator` pointing to the
  536. begin and the end of the matched input sequence.]]
  537. ]
  538. [heading Expression Semantics]
  539. [table
  540. [[Expression] [Semantics]]
  541. [[
  542. ``assign_to_attribute_from_iterators<Attrib, Iterator>::call(b, e, attr)``]
  543. [Use the iterators `begin` and `end` to initialize
  544. the attribute `attr`.]]
  545. ]
  546. [heading Predefined Specializations]
  547. [table
  548. [[Template Parameters] [Semantics]]
  549. [[`Attrib`, `Iterator`] [Execute an assignment `attr = Attrib(begin, end)`.]]
  550. [[__unused_type__, `T`] [Do nothing.]]
  551. ]
  552. [heading When to implement]
  553. The customization point `assign_to_attribute_from_iterators` needs to be
  554. implemented for a specific type whenever the default implementation as shown
  555. above is not applicable. Examples for this could be that the type `Attrib` is
  556. not constructible from the pair of iterators.
  557. [/ TODO: examples ]
  558. [endsect] [/ assign_to_attribute_from_iterators]
  559. [section:assign_to_attribute_from_value Store an Attribute Value after a Parser Produced a Value (Qi)]
  560. [heading assign_to_attribute_from_value]
  561. The template `assign_to_attribute_from_value` is a type used as an attribute
  562. customization point. It is invoked by all primitive /Qi/ parsers in order
  563. to store a parsed attribute value into the attribute instance provided by the
  564. user, if this attribute is not a container type (`is_container<T>::type`
  565. evaluates to `mpl::false_`, where `T` is the attribute type).
  566. [heading Module Headers]
  567. #include <boost/spirit/home/qi/detail/assign_to.hpp>
  568. Also, see __include_structure__.
  569. [note This header file does not need to be included directly by any user
  570. program as it is normally included by other Spirit header files relying
  571. on its content.]
  572. [heading Namespace]
  573. [table
  574. [[Name]]
  575. [[`boost::spirit::traits`]]
  576. ]
  577. [heading Synopsis]
  578. template <typename Attrib, typename T, typename Enable>
  579. struct assign_to_attribute_from_value
  580. {
  581. static void call(T const& val, Attrib& attr);
  582. };
  583. [heading Template parameters]
  584. [table
  585. [[Parameter] [Description] [Default]]
  586. [[`Attrib`] [The type, `Attrib` is the type of the attribute as
  587. passed in by the user. This type is not a container
  588. type (`is_container<Attrib>::type` evaluates to
  589. `mpl::false_`).] [none]]
  590. [[`T`] [The type, `T` is the type of the attribute instance
  591. as produced by the parser.] [none]]
  592. [[`Enable`] [Helper template parameter usable to selectively
  593. enable or disable certain specializations
  594. of `assign_to_attribute_from_value` utilizing SFINAE (i.e.
  595. `boost::enable_if` or `boost::disable_if`).] [`void`]]
  596. ]
  597. [variablelist Notation
  598. [[`Attrib`] [A type to be used as the target to store the attribute
  599. value in. This type is guaranteed not to be a container
  600. type (`is_container<Attrib>::type` evaluates to
  601. `mpl::false_`).]]
  602. [[`attr`] [An attribute instance of type `Attrib`.]]
  603. [[`T`] [A type as produced by the parser. The parser temporarily stores
  604. its parsed values using this type.]]
  605. [[`t`] [An attribute instance of type `T`.]]
  606. ]
  607. [heading Expression Semantics]
  608. [table
  609. [[Expression] [Semantics]]
  610. [[
  611. ``assign_to_attribute_from_value<Attrib, T>::call(t, attr)``]
  612. [Copy (assign) the value `t` to the attribute `attr`.]]
  613. ]
  614. [heading Predefined Specializations]
  615. [table
  616. [[Template Parameters] [Semantics]]
  617. [[`Attrib`, `T`] [Assign the argument `t` to `attr`.]]
  618. [[__unused_type__, `T`] [Do nothing.]]
  619. ]
  620. [heading When to implement]
  621. The customization point `assign_to_attribute_from_value` needs to be
  622. implemented for a specific type whenever the default implementation as shown
  623. above is not applicable. Examples for this could be that the type `Attrib` is
  624. not copy constructible.
  625. [/ TODO: examples ]
  626. [endsect] [/ assign_to_attribute_from_value]
  627. [section:assign_to_container_from_value Store an Attribute Value into a Container after a Parser Produced a Value (Qi)]
  628. [heading assign_to_container_from_value]
  629. The template `assign_to_container_from_value` is a type used as an attribute
  630. customization point. It is invoked by all primitive /Qi/ parsers in order
  631. to store a parsed attribute value into the attribute instance provided by the
  632. user, if this attribute is a container type (`is_container<T>::type` evaluates
  633. to `mpl::true_`, where `T` is the attribute type).
  634. [heading Module Headers]
  635. #include <boost/spirit/home/qi/detail/assign_to.hpp>
  636. Also, see __include_structure__.
  637. [note This header file does not need to be included directly by any user
  638. program as it is normally included by other Spirit header files relying
  639. on its content.]
  640. [heading Namespace]
  641. [table
  642. [[Name]]
  643. [[`boost::spirit::traits`]]
  644. ]
  645. [heading Synopsis]
  646. template <typename Attrib, typename T, typename Enable>
  647. struct assign_to_container_from_value
  648. {
  649. static void call(T const& val, Attrib& attr);
  650. };
  651. [heading Template parameters]
  652. [table
  653. [[Parameter] [Description] [Default]]
  654. [[`Attrib`] [The type, `Attrib` is the type of the attribute as
  655. passed in by the user. This type is a container
  656. type (`is_container<Attrib>::type` evaluates to
  657. `mpl::true_`).] [none]]
  658. [[`T`] [The type, `T` is the type of the attribute instance
  659. as produced by the parser.] [none]]
  660. [[`Enable`] [Helper template parameter usable to selectively
  661. enable or disable certain specializations
  662. of `assign_to_container_from_value` utilizing SFINAE (i.e.
  663. `boost::enable_if` or `boost::disable_if`).] [`void`]]
  664. ]
  665. [variablelist Notation
  666. [[`Attrib`] [A type to be used as the target to store the attribute
  667. value in. This type is guaranteed to be a container
  668. type (`is_container<Attrib>::type` evaluates to
  669. `mpl::true_`).]]
  670. [[`attr`] [An attribute instance of type `Attrib`.]]
  671. [[`T`] [A type as produced by the parser. The parser temporarily stores
  672. its parsed values using this type.]]
  673. [[`t`] [An attribute instance of type `T`.]]
  674. ]
  675. [heading Expression Semantics]
  676. [table
  677. [[Expression] [Semantics]]
  678. [[
  679. ``assign_to_container_from_value<Attrib, T>::call(t, attr)``]
  680. [Add the value `t` to the container attribute `attr`.]]
  681. ]
  682. [heading Predefined Specializations]
  683. [table
  684. [[Template Parameters] [Semantics]]
  685. [[`Attrib`, `T`] [Add the argument `t` to `attr`.]]
  686. [[__unused_type__, `T`] [Do nothing.]]
  687. ]
  688. [heading When to implement]
  689. The customization point `assign_to_container_from_value` needs to be
  690. implemented for a specific type whenever the default implementation as shown
  691. above is not applicable. Examples for this could be that the type `Attrib` is
  692. not copy constructible.
  693. [/ TODO: examples ]
  694. [endsect] [/ assign_to_container_from_value]
  695. [endsect] [/ assign_to]
  696. [/////////////////////////////////////////////////////////////////////////////]
  697. [section:store_value Store Parsed Attribute Values into a Container (Qi)]
  698. In order to customize Spirit to accept a given data type as a container for
  699. elements parsed by any of the repetitive parsers (__qi_kleene__, __qi_plus__,
  700. __qi_list__, and [qi_repeat Repeat]) two attribute customization points have to be
  701. specialized: __customize_container_value__ and __customize_push_back_container__.
  702. This section describes both.
  703. [section:container_value Determine the Type to be Stored in a Container (Qi)]
  704. [heading container_value]
  705. The template `container_value` is a template meta function used as an attribute
  706. customization point. It is invoked by the /Qi/ repetitive parsers
  707. (__qi_kleene__, __qi_plus__, __qi_list__, and [qi_repeat Repeat]) to determine the
  708. type to store in a container.
  709. [heading Module Headers]
  710. #include <boost/spirit/home/support/container.hpp>
  711. Also, see __include_structure__.
  712. [note This header file does not need to be included directly by any user
  713. program as it is normally included by other Spirit header files relying
  714. on its content.]
  715. [heading Namespace]
  716. [table
  717. [[Name]]
  718. [[`boost::spirit::traits`]]
  719. ]
  720. [heading Synopsis]
  721. template <typename Container, typename Enable>
  722. struct container_value
  723. {
  724. typedef <unspecified> type;
  725. };
  726. [heading Template parameters]
  727. [table
  728. [[Parameter] [Description] [Default]]
  729. [[`Container`] [The type `Container` is the type for which the
  730. type f the elements has to be deduced.] [none]]
  731. [[`Enable`] [Helper template parameter usable to selectively
  732. enable or disable certain specializations
  733. of `container_value` utilizing SFINAE (i.e.
  734. `boost::enable_if` or `boost::disable_if`).] [`void`]]
  735. ]
  736. [variablelist
  737. [[`C`] [A type to be tested whether it needs to be treated
  738. as a container.]]
  739. [[`T1`, `T2`, ...] [Arbitrary types]]
  740. ]
  741. [heading Expression Semantics]
  742. [table
  743. [[Expression] [Semantics]]
  744. [[`container_value<C>::type`] [Metafunction that evaluates to the type
  745. to be stored in a given container type,
  746. `C`.]]
  747. ]
  748. [heading Predefined Specializations]
  749. __spirit__ predefines specializations of this customization point for
  750. several types. The following table lists those types together with the types
  751. exposed and the corresponding semantics:
  752. [table
  753. [[Template Parameters] [Semantics]]
  754. [[`C`] [The non-const `value_type` of the given container
  755. type, `C`. ]]
  756. [[`boost::optional<C>`] [Returns `container_value<C>::type`]]
  757. [[`boost::variant<T1, T2, ...>`]
  758. [Returns `container_value<TN>::value` for the
  759. first `TN` (out of `T1`, `T2`, ...) for which
  760. `is_container<TN>::type` evaluates to `mpl::true_`.
  761. Otherwise it will return __unused_type__.]]
  762. [[__unused_type__] [Returns __unused_type__.]]
  763. ]
  764. [heading When to implement]
  765. The customization point `is_container` needs to be implemented for a specific
  766. type whenever this type is to be used as an attribute in place of a STL
  767. container. It is applicable for parsers (__qi__) only. As a rule of thumb: it
  768. has to be implemented whenever a certain type is to be passed as an attribute
  769. to a parser normally exposing a STL container and if the type does not expose
  770. the interface of a STL container (i.e. no embedded typedef for `value_type`).
  771. These components have an attribute propagation rule in the form:
  772. a: A --> Op(a): vector<A>
  773. where `Op(a)` stands for any meaningful operation on the component `a`.
  774. [heading Related Attribute Customization Points]
  775. If this customization point is implemented, the following other customization
  776. points might need to be implemented as well.
  777. [table
  778. [[Name] [When to implement]]
  779. [[__customize_push_back_container__] [Qi: __qi_list__, __qi_kleene__, __qi_plus__, [qi_repeat Repeat].]]
  780. [[__customize_clear_value__] [Qi: __qi_list__, __qi_kleene__, __qi_plus__, [qi_repeat Repeat].]]
  781. ]
  782. [heading Example]
  783. Here is an example showing the default implementation of the
  784. __customize_container_value__ customization point provided by the library:
  785. [customization_container_value_default]
  786. This template is instantiated by the library at the appropriate places while
  787. using the supplied container type as the template argument. The embedded `type`
  788. is used as the attribute type while parsing the elements to be store in that
  789. container.
  790. The following example shows the predefined specialization for __unused_type__:
  791. [customization_container_value_unused]
  792. which defines its embedded `type` to be __unused_type__ as well, this way
  793. propagating the 'don't care' attribute status to the embedded parser.
  794. [/ TODO: examples ]
  795. [endsect] [/ container_value]
  796. [section:push_back Store a Parsed Attribute Value into a Container (Qi)]
  797. [heading push_back_container]
  798. The template `push_back_container` is a type used as an attribute customization
  799. point. It is invoked by the /Qi/ repetitive parsers (__qi_kleene__, __qi_plus__,
  800. __qi_list__, and [qi_repeat Repeat]) to store a parsed attribute value into a
  801. container.
  802. [heading Module Headers]
  803. #include <boost/spirit/home/support/container.hpp>
  804. Also, see __include_structure__.
  805. [note This header file does not need to be included directly by any user
  806. program as it is normally included by other Spirit header files relying
  807. on its content.]
  808. [heading Namespace]
  809. [table
  810. [[Name]]
  811. [[`boost::spirit::traits`]]
  812. ]
  813. [heading Synopsis]
  814. template <typename Container, typename Attrib, typename Enable>
  815. struct push_back_container
  816. {
  817. static bool call(Container& c, Attrib const& val);
  818. };
  819. [heading Template parameters]
  820. [table
  821. [[Parameter] [Description] [Default]]
  822. [[`Container`] [The type, `Container` needs to
  823. be tested whether it has to be treated
  824. as a container] [none]]
  825. [[`Attrib`] [The type, `Attrib` is the one returned from the
  826. customization point __customize_container_value__
  827. and represents the attribute value to be stored in
  828. the container of type `Container`.] [none]]
  829. [[`Enable`] [Helper template parameter usable to selectively
  830. enable or disable certain specializations
  831. of `push_back_container` utilizing SFINAE (i.e.
  832. `boost::enable_if` or `boost::disable_if`).] [`void`]]
  833. ]
  834. [variablelist Notation
  835. [[`C`] [A type to be used as a container to store attribute values in.]]
  836. [[`c`] [A container instance of type `C`.]
  837. [[`Attrib`] [A type to be used as a container to store attribute values in.]]
  838. [[`attr`] [An attribute instance of type `Attrib`.]]
  839. [[`T1`, `T2`, ...] [Arbitrary types]]
  840. ]
  841. [heading Expression Semantics]
  842. [table
  843. [[Expression] [Semantics]]
  844. [[
  845. ``push_back_container<C, Attrib>::call(c, attr)``]
  846. [Static function that is invoked whenever an
  847. attribute value, `attr` needs to be stored
  848. into the container instance `c`. This function
  849. should return `true` on success and `false`
  850. otherwise. Returning `false` causes the
  851. corresponding parser to fail.]]
  852. ]
  853. [heading Predefined Specializations]
  854. __spirit__ predefines specializations of this customization point for
  855. several types. The following table lists those types together with the types
  856. exposed and the corresponding semantics:
  857. [table
  858. [[Template Parameters] [Semantics]]
  859. [[`C`, `Attrib`] [Store the provided attribute instance `attr` into
  860. the given container `c` using the function call
  861. `c.insert(c.end(), attr)`.]]
  862. [[`boost::optional<C>`, `Attrib`]
  863. [If the provided instance of `boost::optional<>` is not
  864. initialized, invoke the appropriate initialization
  865. and afterwards apply the customization point
  866. `push_back_container<C, Attrib>`, treating the
  867. instance held by the optional (of type `C`) as
  868. the container to store the attribute in.]]
  869. [[`boost::variant<T1, T2, ...>`, `Attrib`]
  870. [If the instance of the variant currently holds a
  871. value with a type, `TN`, for which `is_container<TN>::type`
  872. evaluates to `mpl::true_`, this customization
  873. point specialization will apply
  874. `push_back_container<TN, Attrib>`, treating the
  875. instance held by the variant (of type `TN`) as
  876. the container to store the attribute in. Otherwise
  877. it will raise an assertion.]]
  878. [[__unused_type__] [Do nothing.]]
  879. ]
  880. [heading When to Implement]
  881. The customization point `push_back_container` needs to be implemented for a
  882. specific type whenever this type is to be used as an attribute in place of a STL
  883. container. It is applicable for parsers (__qi__) only. As a rule of thumb: it
  884. has to be implemented whenever a certain type is to be passed as an attribute
  885. to a parser normally exposing a STL container and if the type does not expose
  886. the interface of a STL container (i.e. no function being equivalent to
  887. `c.insert(c.end(), attr)`. These components have an attribute propagation rule
  888. in the form:
  889. a: A --> Op(a): vector<A>
  890. where `Op(a)` stands for any meaningful operation on the component `a`.
  891. [heading Related Attribute Customization Points]
  892. If this customization point is implemented, the following other customization
  893. points might need to be implemented as well.
  894. [table
  895. [[Name] [When to implement]]
  896. [[__customize_container_value__] [Qi: __qi_list__, __qi_kleene__, __qi_plus__, [qi_repeat Repeat].]]
  897. [[__customize_clear_value__] [Qi: __qi_list__, __qi_kleene__, __qi_plus__, [qi_repeat Repeat].]]
  898. ]
  899. [heading Example]
  900. Here is an example showing the default implementation of the
  901. __customize_container_value__ customization point provided by the library:
  902. [customization_push_back_default]
  903. This template is instantiated by the library at the appropriate places while
  904. using the supplied container and element types as the template arguments. The
  905. member function `call()` will be called whenever an element has to be added to
  906. the supplied container
  907. The following example shows the predefined specialization for __unused_type__:
  908. [customization_push_back_unused]
  909. which defines an empty member function `call()`.
  910. [/ TODO: examples ]
  911. [endsect] [/ push_back]
  912. [endsect] [/ store_value]
  913. [/////////////////////////////////////////////////////////////////////////////]
  914. [section:clear_value Re-Initialize an Attribute Value before Parsing (Qi)]
  915. [heading clear_value]
  916. The template `clear_value` is a type used as an attribute customization point.
  917. It is invoked by the /Qi/ repetitive parsers (__qi_kleene__, __qi_plus__,
  918. __qi_list__, and [qi_repeat Repeat]) in order to re-initialize the attribute
  919. instance passed to the embedded parser after it has been stored in the provided
  920. container. This re-initialized attribute instance is reused during the next
  921. iteration of the repetitive parser.
  922. [heading Module Headers]
  923. #include <boost/spirit/home/support/attributes.hpp>
  924. Also, see __include_structure__.
  925. [note This header file does not need to be included directly by any user
  926. program as it is normally included by other Spirit header files relying
  927. on its content.]
  928. [heading Namespace]
  929. [table
  930. [[Name]]
  931. [[`boost::spirit::traits`]]
  932. ]
  933. [heading Synopsis]
  934. template <typename Attrib, typename Enable>
  935. struct clear_value
  936. {
  937. static void call(Attrib& val);
  938. };
  939. [heading Template parameters]
  940. [table
  941. [[Parameter] [Description] [Default]]
  942. [[`Attrib`] [The type, `Attrib` of the attribute to be
  943. re-initialized.] [none]]
  944. [[`Enable`] [Helper template parameter usable to selectively
  945. enable or disable certain specializations
  946. of `clear_value` utilizing SFINAE (i.e.
  947. `boost::enable_if` or `boost::disable_if`).] [`void`]]
  948. ]
  949. [variablelist Notation
  950. [[`Attrib`] [A type to be used as a container to store attribute values in.]]
  951. [[`attr`] [An attribute instance of type `Attrib`.]]
  952. [[`T1`, `T2`, ...] [Arbitrary types]]
  953. ]
  954. [heading Expression Semantics]
  955. [table
  956. [[Expression] [Semantics]]
  957. [[
  958. ``clear_value<Attrib>::call(Attrib& attr)``] [Re-initialize the instance referred to by
  959. `attr` in the most efficient way.]]
  960. ]
  961. [heading Predefined Specializations]
  962. __spirit__ predefines specializations of this customization point for
  963. several types. The following table lists those types together with the types
  964. exposed and the corresponding semantics:
  965. [table
  966. [[Template Parameters] [Semantics]]
  967. [[`Attrib`] [Re-initialize using assignment of default
  968. constructed value.]]
  969. [[Any type `T` for which `is_container<>::type` is `mpl::true_`]
  970. [Call the member function `attr.clear()` for the
  971. passed attribute instance.]]
  972. [[`boost::optional<Attrib>`] [Clear the `optional` instance and leave it
  973. uninitialized.]]
  974. [[`boost::variant<T1, T2, ...>`][Invoke the `clear_value` customization
  975. point for the currently held value.]]
  976. [[`fusion::tuple<T1, T2, ...>`][Invoke the `clear_value` customization
  977. point for all elements of the tuple.]]
  978. [[__unused_type__] [Do nothing.]]
  979. ]
  980. [heading When to Implement]
  981. The customization point `clear_value` needs to be implemented for a
  982. specific type whenever this type is to be used as an attribute to be stored
  983. into a STL container and if the type cannot be re-initialized using one of the
  984. specializations listed above. Examples for this might be types not being default
  985. constructible or container types not exposing a member function `clear()`.
  986. [/ TODO: examples ]
  987. [endsect] [/ clear_value]
  988. [/////////////////////////////////////////////////////////////////////////////]
  989. [section:extract_from Extract an Attribute Value to Generate Output (Karma)]
  990. [heading extract_from]
  991. Before generating output for a value this value needs to extracted from the
  992. attribute instance provided by the user. The customization point
  993. `extract_from_attribute` is utilized to adapt this extraction for any data type possibly
  994. used to store the values to output.
  995. [note The interface of this customization point has been changed with Boost
  996. V1.44. We added the `Exposed` template parameter to allow for more fine
  997. grained specializations of the required __karma__ attribute
  998. transformations.]
  999. [heading Module Headers]
  1000. #include <boost/spirit/home/karma/detail/extract_from.hpp>
  1001. Also, see __include_structure__.
  1002. [note This header file does not need to be included directly by any user
  1003. program as it is normally included by other Spirit header files relying
  1004. on its content.]
  1005. [heading Namespace]
  1006. [table
  1007. [[Name]]
  1008. [[`boost::spirit::traits`]]
  1009. ]
  1010. [heading Synopsis]
  1011. template <typename Exposed, typename Attrib, typename Enable>
  1012. struct extract_from_attribute
  1013. {
  1014. typedef <unspecified> type;
  1015. template <typename Context>
  1016. static type call(Attrib const& attr, Context& context);
  1017. };
  1018. [heading Template parameters]
  1019. [table
  1020. [[Parameter] [Description] [Default]]
  1021. [[`Exposed`] [The type, `Exposed` of the attribute natively
  1022. exposed by the component the `extract_from_attribute` is
  1023. invoked from.] [none]]
  1024. [[`Attrib`] [The type, `Attrib` of the attribute to be used to
  1025. generate output from.] [none]]
  1026. [[`Enable`] [Helper template parameter usable to selectively
  1027. enable or disable certain specializations
  1028. of `clear_value` utilizing SFINAE (i.e.
  1029. `boost::enable_if` or `boost::disable_if`).] [`void`]]
  1030. [[`Context`] [This is the type of the current generator execution
  1031. context.]]
  1032. ]
  1033. [variablelist Notation
  1034. [[`Exposed`] [A type exposed as the native attribute of a component.]]
  1035. [[`Attrib`] [A type to be used to generate output from.]]
  1036. [[`attr`] [An attribute instance of type `Attrib`.]]
  1037. [[`ctx`] [An instance of type `Context`.]]
  1038. ]
  1039. [heading Expression Semantics]
  1040. [table
  1041. [[Expression] [Semantics]]
  1042. [[
  1043. ``extract_from_attribute<Exposed, Attrib>::call(attr, ctx)``]
  1044. [Extract the value to generate
  1045. output from `attr` and return it to the caller.]]
  1046. ]
  1047. [heading Predefined Specializations]
  1048. __spirit__ predefines specializations of this customization point for
  1049. several types. The following table lists those types together with the types
  1050. exposed and the corresponding semantics:
  1051. [table
  1052. [[Template Parameters] [Semantics]]
  1053. [[`Attrib`] [The exposed typedef `type` is defined to
  1054. `Attrib const&`. The function `call()` returns
  1055. the argument by reference without change.]]
  1056. [[`boost::optional<Attrib>`] [The exposed typedef `type` is defined to
  1057. `Attrib const&`. The function `call()` returns
  1058. the value held by the `optional<>` argument
  1059. by reference without change.]]
  1060. [[`boost::reference_wrapper<Attrib>`]
  1061. [The exposed typedef `type` is defined to
  1062. `Attrib const&`. The function `call()` returns
  1063. the value held by the `reference_wrapper<>`
  1064. argument by reference without change.]]
  1065. [[__unused_type__] [The exposed typedef `type` is defined to
  1066. __unused_type__. The function `call()` returns
  1067. an instance of __unused_type__.]]
  1068. ]
  1069. [heading When to implement]
  1070. The customization point `extract_from_attribute` needs to be implemented for a
  1071. specific type whenever the default implementation as shown above is not
  1072. applicable. Examples for this could be that the type to be extracted is
  1073. different from `Attrib` and is not copy constructible.
  1074. [/ TODO: examples ]
  1075. [endsect] [/ extract_from]
  1076. [/////////////////////////////////////////////////////////////////////////////]
  1077. [section:extract_from_container Extract From a Container Attribute Value to Generate Output (Karma)]
  1078. [heading extract_from_container]
  1079. Before generating output for a value this value needs to extracted from the
  1080. attribute instance provided by the user. The customization point
  1081. `extract_from_container` is utilized to adapt this extraction for any data type possibly
  1082. used to store the values to output.
  1083. [note The interface of this customization point has been changed with Boost
  1084. V1.44. We added the `Exposed` template parameter to allow for more fine
  1085. grained specializations of the required __karma__ attribute
  1086. transformations.]
  1087. [heading Module Headers]
  1088. #include <boost/spirit/home/karma/detail/extract_from.hpp>
  1089. Also, see __include_structure__.
  1090. [note This header file does not need to be included directly by any user
  1091. program as it is normally included by other Spirit header files relying
  1092. on its content.]
  1093. [heading Namespace]
  1094. [table
  1095. [[Name]]
  1096. [[`boost::spirit::traits`]]
  1097. ]
  1098. [heading Synopsis]
  1099. template <typename Exposed, typename Attrib, typename Enable>
  1100. struct extract_from_container
  1101. {
  1102. typedef <unspecified> type;
  1103. template <typename Context>
  1104. static type call(Attrib const& attr, Context& context);
  1105. };
  1106. [heading Template parameters]
  1107. [table
  1108. [[Parameter] [Description] [Default]]
  1109. [[`Exposed`] [The type, `Exposed` of the attribute natively
  1110. exposed by the component the `extract_from_container` is
  1111. invoked from.] [none]]
  1112. [[`Attrib`] [The type, `Attrib` is the container attribute to be used to
  1113. generate output from.] [none]]
  1114. [[`Enable`] [Helper template parameter usable to selectively
  1115. enable or disable certain specializations
  1116. of `clear_value` utilizing SFINAE (i.e.
  1117. `boost::enable_if` or `boost::disable_if`).] [`void`]]
  1118. [[`Context`] [This is the type of the current generator execution
  1119. context.]]
  1120. ]
  1121. [heading Notation]
  1122. [variablelist Notation
  1123. [[`Exposed`] [A type exposed as the native attribute of a component.]]
  1124. [[`Attrib`] [A container type to be used to generate output from.]]
  1125. [[`attr`] [An attribute instance of type `Attrib`.]]
  1126. [[`ctx`] [An instance of type `Context`.]]
  1127. ]
  1128. [heading Expression Semantics]
  1129. [table
  1130. [[Expression] [Semantics]]
  1131. [[
  1132. ``extract_from_container<Exposed, Attrib>::call(attr, ctx)``]
  1133. [Extract the value to generate
  1134. output from the contaner given by `attr` and return
  1135. it to the caller.]]
  1136. ]
  1137. [heading Predefined Specializations]
  1138. __spirit__ predefines specializations of this customization point for
  1139. several types. The following table lists those types together with the types
  1140. exposed and the corresponding semantics:
  1141. [table
  1142. [[Template Parameters] [Value]]
  1143. [[`Attrib`] [The exposed typedef `type` is defined to
  1144. `Attrib const&`. The function `call()` returns
  1145. the argument by reference without change.]]
  1146. [[__unused_type__] [The exposed typedef `type` is defined to
  1147. __unused_type__. The function `call()` returns
  1148. an instance of __unused_type__.]]
  1149. ]
  1150. [heading When to implement]
  1151. The customization point `extract_from_container` needs to be implemented for a
  1152. specific container type whenever the default implementation as shown above is not
  1153. applicable. Examples for this could be that the type to be extracted is
  1154. different from `Attrib` and is not copy constructible.
  1155. [heading Example]
  1156. TBD
  1157. [endsect] [/ extract_from]
  1158. [/////////////////////////////////////////////////////////////////////////////]
  1159. [section:iterate Extract Attribute Values to Generate Output from a Container (Karma)]
  1160. [section:container_iterator Determine the Type of the Iterator of a Container]
  1161. [heading container_iterator]
  1162. The template `container_iterator` is a template meta-function used as an attribute
  1163. customization point. It is invoked by the /Karma/ repetitive generators (such
  1164. as __karma_list__, [karma_kleene Kleene (unary `*`)], __karma_plus__, and
  1165. [karma_repeat Repeat]) in order to determine the type of the iterator to use to
  1166. iterate over the items to be exposed as the elements of a container.
  1167. [heading Module Headers]
  1168. #include <boost/spirit/home/support/container.hpp>
  1169. Also, see __include_structure__.
  1170. [note This header file does not need to be included directly by any user
  1171. program as it is normally included by other Spirit header files relying
  1172. on its content.]
  1173. [heading Namespace]
  1174. [table
  1175. [[Name]]
  1176. [[`boost::spirit::traits`]]
  1177. ]
  1178. [heading Synopsis]
  1179. template <typename Container, typename Enable>
  1180. struct container_iterator
  1181. {
  1182. typedef <unspecified> type;
  1183. };
  1184. [heading Template parameters]
  1185. [table
  1186. [[Parameter] [Description] [Default]]
  1187. [[`Container`] [The type, `Container` for which the
  1188. iterator type has to be returned] [none]]
  1189. [[`Enable`] [Helper template parameter usable to selectively
  1190. enable or disable certain specializations
  1191. of `container_iterator` utilizing SFINAE (i.e.
  1192. `boost::enable_if` or `boost::disable_if`).] [`void`]]
  1193. ]
  1194. [variablelist Notation
  1195. [[`C`] [A container type the iterator type needs to be evaluated for.]]
  1196. ]
  1197. [heading Expression Semantics]
  1198. [table
  1199. [[Expression] [Semantics]]
  1200. [[`container_iterator<C>::type`] [Result of the metafunction that evaluates
  1201. the type to be used as the iterator for
  1202. accessing all elements of a container, `C`.]]
  1203. ]
  1204. The returned type conceptually needs to be equivalent to a standard forward
  1205. iterator. But it does not have to expose the standardized interface. If this
  1206. customization point is implemented for a certain container type, all related
  1207. customization points need to be implemented as well (see
  1208. [link spirit.advanced.customize.iterate.container_iterator.related_attribute_customization_points Related Attribute Customization Points]
  1209. below). This encapsulates the specific iterator interface required for a
  1210. given type. The minimal requirements for a type to be exposed as an iterator in
  1211. this context are:
  1212. * it needs to be comparable for equality (see __customize_compare_iterators__),
  1213. * it needs to be incrementable (see __customize_next_iterator__),
  1214. * it needs to be dereferencible (see __customize_deref_iterator__).
  1215. [heading Predefined Specializations]
  1216. __spirit__ predefines specializations of this customization point for
  1217. several types. The following table lists those types together with the
  1218. types returned by the embedded typedef `type`:
  1219. [table
  1220. [[Template Parameters] [Semantics]]
  1221. [[`C`] [Returns `C::iterator`.]]
  1222. [[`C const`] [Returns `C::const_iterator`.]]
  1223. [[__unused_type__] [Returns __unused_type__` const*`.]]
  1224. ]
  1225. [heading When to implement]
  1226. The customization point `container_iterator` needs to be implemented for a specific
  1227. type whenever this type is to be used as an attribute in place of a STL
  1228. container. It is applicable for generators (__karma__) only. As a rule of thumb:
  1229. it has to be implemented whenever a certain type is to be passed as an attribute
  1230. to a generator normally exposing a STL container, `C` and if the type does not expose
  1231. the interface of a STL container (i.e. `is_container<C>::type` would normally
  1232. return `mpl::false_`).
  1233. [heading Related Attribute Customization Points]
  1234. If this customization point is implemented, the following other customization
  1235. points might need to be implemented as well.
  1236. [table
  1237. [[Name] [When to implement]]
  1238. [[__customize_is_container__] [Needs to be implemented whenever a type is to be used as a container attribute in /Karma/.]]
  1239. [[__customize_container_iterator__] [Karma: __karma_list__, [karma_kleene Kleene (unary `*`)], __karma_plus__, [karma_repeat Repeat].]]
  1240. [[__customize_begin_container__] [Karma: __karma_list__, [karma_kleene Kleene (unary `*`)], __karma_plus__, [karma_repeat Repeat].]]
  1241. [[__customize_end_container__] [Karma: __karma_list__, [karma_kleene Kleene (unary `*`)], __karma_plus__, [karma_repeat Repeat].]]
  1242. [[__customize_deref_iterator__] [Karma: __karma_list__, [karma_kleene Kleene (unary `*`)], __karma_plus__, [karma_repeat Repeat].]]
  1243. [[__customize_next_iterator__] [Karma: __karma_list__, [karma_kleene Kleene (unary `*`)], __karma_plus__, [karma_repeat Repeat].]]
  1244. [[__customize_compare_iterators__] [Karma: __karma_list__, [karma_kleene Kleene (unary `*`)], __karma_plus__, [karma_repeat Repeat].]]
  1245. ]
  1246. [heading Example]
  1247. Here are the header files needed to make the example code below compile:
  1248. [customize_karma_embedded_container_includes]
  1249. The example (for the full source code please see here:
  1250. [@../../example/karma/customize_embedded_container.cpp customize_embedded_container.cpp])
  1251. uses the data structure
  1252. [customize_karma_embedded_container_data]
  1253. as a direct container attribute to the __karma_list__ generator. In order to
  1254. make this data structure compatible we need to specialize a couple of attribute
  1255. customization points: __customize_is_container__, __customize_container_iterator__,
  1256. __customize_begin_container__, and __customize_end_container__. As you can see
  1257. the specializations simply expose the embedded `std::vector<int>` as the
  1258. container to use. We don't need to specialize the customization points related
  1259. to iterators (__customize_deref_iterator__, __customize_next_iterator__,
  1260. and __customize_compare_iterators__) as we expose a standard iterator and the
  1261. default implementation of these customizations handles standard iterators out
  1262. of the box.
  1263. [customize_karma_embedded_container_traits]
  1264. The last code snippet shows an example using an instance of the data structure
  1265. `client::embedded_container` to generate output from a __karma_list__
  1266. generator:
  1267. [customize_karma_embedded_container]
  1268. As you can see, the specializations for the customization points as defined
  1269. above enable the seamless integration of the custom data structure without
  1270. having to modify the output format or the generator itself.
  1271. For other examples of how to use the customization point `container_iterator`
  1272. please see here: __customize_use_as_container_example__ and
  1273. __customize_counter_example__.
  1274. [endsect] [/ container_iterator]
  1275. [section:begin_container Get the Iterator pointing to the Begin of a Container Attribute]
  1276. [heading begin_container]
  1277. The template `begin_container` is a type used as an attribute customization point.
  1278. It is invoked by the /Karma/ repetitive generators (such as __karma_list__,
  1279. [karma_kleene Kleene (unary `*`)], __karma_plus__, and [karma_repeat Repeat])
  1280. in order to get an iterator pointing to the first element of the container
  1281. holding the attributes to generate output from.
  1282. [heading Module Headers]
  1283. #include <boost/spirit/home/support/container.hpp>
  1284. Also, see __include_structure__.
  1285. [note This header file does not need to be included directly by any user
  1286. program as it is normally included by other Spirit header files relying
  1287. on its content.]
  1288. [heading Namespace]
  1289. [table
  1290. [[Name]]
  1291. [[`boost::spirit::traits`]]
  1292. ]
  1293. [heading Synopsis]
  1294. template <typename Container, typename Enable>
  1295. struct begin_container
  1296. {
  1297. static typename container_iterator<Container>::type
  1298. call(Container& c);
  1299. };
  1300. [heading Template parameters]
  1301. [table
  1302. [[Parameter] [Description] [Default]]
  1303. [[`Container`] [The type, `Container` for which the iterator pointing
  1304. to the first element has to be returned] [none]]
  1305. [[`Enable`] [Helper template parameter usable to selectively
  1306. enable or disable certain specializations
  1307. of `begin_container` utilizing SFINAE (i.e.
  1308. `boost::enable_if` or `boost::disable_if`).] [`void`]]
  1309. ]
  1310. [variablelist Notation
  1311. [[`C`] [A container type the begin iterator needs to be returned for.]]
  1312. [[`c`] [An instance of a container, `C`.]]
  1313. ]
  1314. [heading Expression Semantics]
  1315. [table
  1316. [[Expression] [Semantics]]
  1317. [[`begin_container<C>::call(c)`] [Return the iterator usable to dereference
  1318. the first element of the given container,
  1319. `c`. The type of the returned iterator is
  1320. expected to be the same as the type returned
  1321. by the customization point
  1322. __customize_container_iterator__.]]
  1323. ]
  1324. The returned instance conceptually needs to be equivalent to a standard forward
  1325. iterator. But it does not have to expose the standardized interface. If this
  1326. customization point is implemented for a certain container type, all related
  1327. customization points need to be implemented as well (see
  1328. [link spirit.advanced.customize.iterate.begin_container.related_attribute_customization_points Related Attribute Customization Points]
  1329. below). This encapsulates the specific iterator interface required for a
  1330. given type. The minimal requirements for a type to be exposed as an iterator in
  1331. this context are:
  1332. * it needs to be comparable for equality (see __customize_compare_iterators__),
  1333. * it needs to be incrementable (see __customize_next_iterator__),
  1334. * it needs to be dereferencible (see __customize_deref_iterator__).
  1335. [heading Predefined Specializations]
  1336. __spirit__ predefines specializations of this customization point for
  1337. several types. The following table lists those types together with the
  1338. types returned by the embedded typedef `type`:
  1339. [table
  1340. [[Template Parameters] [Semantics]]
  1341. [[`C`] [Returns `c.begin()`.]]
  1342. [[`C const`] [Returns `c.begin()`.]]
  1343. [[__unused_type__] [Returns `&unused`.]]
  1344. ]
  1345. [heading When to implement]
  1346. The customization point `begin_container` needs to be implemented for a specific
  1347. type whenever this type is to be used as an attribute in place of a STL
  1348. container. It is applicable for generators (__karma__) only. As a rule of thumb:
  1349. it has to be implemented whenever a certain type is to be passed as an attribute
  1350. to a generator normally exposing a STL container, `C` and if the type does not expose
  1351. the interface of a STL container (i.e. `is_container<C>::type` would normally
  1352. return `mpl::false_`).
  1353. [heading Related Attribute Customization Points]
  1354. If this customization point is implemented, the following other customization
  1355. points might need to be implemented as well.
  1356. [table
  1357. [[Name] [When to implement]]
  1358. [[__customize_is_container__] [Needs to be implemented whenever a type is to be used as a container attribute in /Karma/.]]
  1359. [[__customize_container_iterator__] [Karma: __karma_list__, [karma_kleene Kleene (unary `*`)], __karma_plus__, [karma_repeat Repeat].]]
  1360. [[__customize_begin_container__] [Karma: __karma_list__, [karma_kleene Kleene (unary `*`)], __karma_plus__, [karma_repeat Repeat].]]
  1361. [[__customize_end_container__] [Karma: __karma_list__, [karma_kleene Kleene (unary `*`)], __karma_plus__, [karma_repeat Repeat].]]
  1362. [[__customize_deref_iterator__] [Karma: __karma_list__, [karma_kleene Kleene (unary `*`)], __karma_plus__, [karma_repeat Repeat].]]
  1363. [[__customize_next_iterator__] [Karma: __karma_list__, [karma_kleene Kleene (unary `*`)], __karma_plus__, [karma_repeat Repeat].]]
  1364. [[__customize_compare_iterators__] [Karma: __karma_list__, [karma_kleene Kleene (unary `*`)], __karma_plus__, [karma_repeat Repeat].]]
  1365. ]
  1366. [heading Example]
  1367. For examples of how to use the customization point `begin_container` please
  1368. see here: __customize_embedded_container_example__,
  1369. __customize_use_as_container_example__, and __customize_counter_example__.
  1370. [endsect] [/ begin_container]
  1371. [section:end_container Get the Iterator pointing to the End of a Container Attribute]
  1372. [heading end_container]
  1373. The template `end_container` is a type used as an attribute customization point.
  1374. It is invoked by the /Karma/ repetitive generators (such as __karma_list__,
  1375. [karma_kleene Kleene (unary `*`)], __karma_plus__, and [karma_repeat Repeat])
  1376. in order to get an iterator pointing to the end of the container
  1377. holding the attributes to generate output from.
  1378. [heading Module Headers]
  1379. #include <boost/spirit/home/support/container.hpp>
  1380. Also, see __include_structure__.
  1381. [note This header file does not need to be included directly by any user
  1382. program as it is normally included by other Spirit header files relying
  1383. on its content.]
  1384. [heading Namespace]
  1385. [table
  1386. [[Name]]
  1387. [[`boost::spirit::traits`]]
  1388. ]
  1389. [heading Synopsis]
  1390. template <typename Container, typename Enable>
  1391. struct end_container
  1392. {
  1393. static typename container_iterator<Container>::type
  1394. call(Container& c);
  1395. };
  1396. [heading Template parameters]
  1397. [table
  1398. [[Parameter] [Description] [Default]]
  1399. [[`Container`] [The type, `Container` for which the iterator pointing
  1400. to the first element has to be returned] [none]]
  1401. [[`Enable`] [Helper template parameter usable to selectively
  1402. enable or disable certain specializations
  1403. of `end_container` utilizing SFINAE (i.e.
  1404. `boost::enable_if` or `boost::disable_if`).] [`void`]]
  1405. ]
  1406. [variablelist Notation
  1407. [[`C`] [A container type the end iterator needs to be returned for.]]
  1408. [[`c`] [An instance of a container, `C`.]]
  1409. ]
  1410. [heading Expression Semantics]
  1411. [table
  1412. [[Expression] [Semantics]]
  1413. [[`end_container<C>::call(c)`] [Return the iterator usable to compare a
  1414. different iterator with in order to detect
  1415. whether the other iterator reached the end
  1416. of the given container, `c`. The type of
  1417. the returned iterator is expected to be the
  1418. same as the type returned by the
  1419. customization point __customize_container_iterator__.]]
  1420. ]
  1421. [heading Predefined Specializations]
  1422. __spirit__ predefines specializations of this customization point for
  1423. several types. The following table lists those types together with the
  1424. types returned by the embedded typedef `type`:
  1425. [table
  1426. [[Template Parameters] [Semantics]]
  1427. [[`C`] [Returns `c.end()`.]]
  1428. [[`C const`] [Returns `c.end()`.]]
  1429. [[__unused_type__] [Returns `&unused`.]]
  1430. ]
  1431. [heading When to implement]
  1432. The customization point `end_container` needs to be implemented for a specific
  1433. type whenever this type is to be used as an attribute in place of a STL
  1434. container. It is applicable for generators (__karma__) only. As a rule of thumb:
  1435. it has to be implemented whenever a certain type is to be passed as an attribute
  1436. to a generator normally exposing a STL container, `C` and if the type does not expose
  1437. the interface of a STL container (i.e. `is_container<C>::type` would normally
  1438. return `mpl::false_`).
  1439. [heading Related Attribute Customization Points]
  1440. If this customization point is implemented, the following other customization
  1441. points might need to be implemented as well.
  1442. [table
  1443. [[Name] [When to implement]]
  1444. [[__customize_is_container__] [Needs to be implemented whenever a type is to be used as a container attribute in /Karma/.]]
  1445. [[__customize_container_iterator__] [Karma: __karma_list__, [karma_kleene Kleene (unary `*`)], __karma_plus__, [karma_repeat Repeat].]]
  1446. [[__customize_begin_container__] [Karma: __karma_list__, [karma_kleene Kleene (unary `*`)], __karma_plus__, [karma_repeat Repeat].]]
  1447. [[__customize_end_container__] [Karma: __karma_list__, [karma_kleene Kleene (unary `*`)], __karma_plus__, [karma_repeat Repeat].]]
  1448. [[__customize_deref_iterator__] [Karma: __karma_list__, [karma_kleene Kleene (unary `*`)], __karma_plus__, [karma_repeat Repeat].]]
  1449. [[__customize_next_iterator__] [Karma: __karma_list__, [karma_kleene Kleene (unary `*`)], __karma_plus__, [karma_repeat Repeat].]]
  1450. [[__customize_compare_iterators__] [Karma: __karma_list__, [karma_kleene Kleene (unary `*`)], __karma_plus__, [karma_repeat Repeat].]]
  1451. ]
  1452. [heading Example]
  1453. For examples of how to use the customization point `end_container` please
  1454. see here: __customize_embedded_container_example__,
  1455. __customize_use_as_container_example__, and __customize_counter_example__.
  1456. [endsect] [/ end_container]
  1457. [section:next_iterator Increment the Iterator pointing into a Container Attribute]
  1458. [heading next_iterator]
  1459. The template `next_iterator` is a type used as an attribute customization point.
  1460. It is invoked by the /Karma/ repetitive generators (such as __karma_list__,
  1461. [karma_kleene Kleene (unary `*`)], __karma_plus__, and [karma_repeat Repeat])
  1462. in order to get an iterator pointing to the next element of a container
  1463. holding the attributes to generate output from.
  1464. [heading Module Headers]
  1465. #include <boost/spirit/home/support/container.hpp>
  1466. Also, see __include_structure__.
  1467. [note This header file does not need to be included directly by any user
  1468. program as it is normally included by other Spirit header files relying
  1469. on its content.]
  1470. [heading Namespace]
  1471. [table
  1472. [[Name]]
  1473. [[`boost::spirit::traits`]]
  1474. ]
  1475. [heading Synopsis]
  1476. template <typename Iterator, typename Enable>
  1477. struct next_iterator
  1478. {
  1479. static void call(Iterator& it);
  1480. };
  1481. [heading Template parameters]
  1482. [table
  1483. [[Parameter] [Description] [Default]]
  1484. [[`Iterator`] [The type, `Iterator` of the iterator to increment.
  1485. This is the same as the type returned by the
  1486. customization point __customize_container_iterator__.] [none]]
  1487. [[`Enable`] [Helper template parameter usable to selectively
  1488. enable or disable certain specializations
  1489. of `next_iterator` utilizing SFINAE (i.e.
  1490. `boost::enable_if` or `boost::disable_if`).] [`void`]]
  1491. ]
  1492. [variablelist Notation
  1493. [[`Iterator`] [An iterator type.]]
  1494. [[`it`] [An instance of an iterator of type `Iterator`.]]
  1495. [[`C`] [A container type whose iterator type is `Iterator`.]]
  1496. ]
  1497. [heading Expression Semantics]
  1498. [table
  1499. [[Expression] [Semantics]]
  1500. [[`next_iterator<Iterator>::call(it)`] [Increment the iterator pointing so that
  1501. it is pointing to the next element.]]
  1502. ]
  1503. [heading Predefined Specializations]
  1504. __spirit__ predefines specializations of this customization point for
  1505. several types. The following table lists those types together with the
  1506. types returned by the embedded typedef `type`:
  1507. [table
  1508. [[Template Parameters] [Semantics]]
  1509. [[`Iterator`] [Executes `++it`.]]
  1510. [[__unused_type__` const*`][Does nothing.]]
  1511. ]
  1512. [heading When to implement]
  1513. The customization point `next_iterator` needs to be implemented for a specific
  1514. iterator type whenever the container this iterator belongs to is to be used as
  1515. an attribute in place of a STL container. It is applicable for generators
  1516. (__karma__) only. As a rule of thumb: it has to be implemented whenever a certain
  1517. iterator type belongs to a container which is to be passed as an attribute
  1518. to a generator normally exposing a STL container, `C` and if the container type
  1519. does not expose the interface of a STL container (i.e. `is_container<C>::type`
  1520. would normally return `mpl::false_`).
  1521. [heading Related Attribute Customization Points]
  1522. If this customization point is implemented, the following other customization
  1523. points might need to be implemented as well.
  1524. [table
  1525. [[Name] [When to implement]]
  1526. [[__customize_is_container__] [Needs to be implemented whenever a type is to be used as a container attribute in /Karma/.]]
  1527. [[__customize_container_iterator__] [Karma: __karma_list__, [karma_kleene Kleene (unary `*`)], __karma_plus__, [karma_repeat Repeat].]]
  1528. [[__customize_begin_container__] [Karma: __karma_list__, [karma_kleene Kleene (unary `*`)], __karma_plus__, [karma_repeat Repeat].]]
  1529. [[__customize_end_container__] [Karma: __karma_list__, [karma_kleene Kleene (unary `*`)], __karma_plus__, [karma_repeat Repeat].]]
  1530. [[__customize_deref_iterator__] [Karma: __karma_list__, [karma_kleene Kleene (unary `*`)], __karma_plus__, [karma_repeat Repeat].]]
  1531. [[__customize_next_iterator__] [Karma: __karma_list__, [karma_kleene Kleene (unary `*`)], __karma_plus__, [karma_repeat Repeat].]]
  1532. [[__customize_compare_iterators__] [Karma: __karma_list__, [karma_kleene Kleene (unary `*`)], __karma_plus__, [karma_repeat Repeat].]]
  1533. ]
  1534. [heading Example]
  1535. Here are the header files needed to make the example code below compile:
  1536. [customize_karma_use_as_container_includes]
  1537. The example (for the full source code please see here:
  1538. [@../../example/karma/customize_use_as_container.cpp customize_use_as_container.cpp])
  1539. uses the data structure
  1540. [customize_karma_use_as_container_data]
  1541. as a direct attribute to the __karma_list__ generator. This type does not
  1542. expose any of the interfaces of an STL container. It does not even expose the
  1543. usual semantics of a container. The purpose of this artificial example is to
  1544. demonstrate how the customization points can be used to expose independent data
  1545. elements as a single container. The example shows how to enable its use as an
  1546. attribute to /Karma's/ repetitive generators.
  1547. In order to make this data structure compatible we need to specialize a couple
  1548. of attribute customization points: __customize_is_container__,
  1549. __customize_container_iterator__, __customize_begin_container__, and
  1550. __customize_end_container__. In addition, we specialize all of the
  1551. iterator related customization points as well: __customize_deref_iterator__,
  1552. __customize_next_iterator__, and __customize_compare_iterators__.
  1553. [customize_karma_use_as_container_traits]
  1554. [customize_karma_use_as_container_iterator_traits]
  1555. The last code snippet shows an example using an instance of the data structure
  1556. `client::use_as_container` to generate output from a __karma_list__ generator:
  1557. [customize_karma_use_as_container]
  1558. As you can see, the specializations for the customization points as defined
  1559. above enable the seamless integration of the custom data structure without
  1560. having to modify the output format or the generator itself.
  1561. [endsect] [/ next_iterator]
  1562. [section:deref_iterator Dereference the Iterator pointing into a Container Attribute]
  1563. [heading deref_iterator]
  1564. The template `deref_iterator` is a type used as an attribute customization point.
  1565. It is invoked by the /Karma/ repetitive generators (such as __karma_list__,
  1566. [karma_kleene Kleene (unary `*`)], __karma_plus__, and [karma_repeat Repeat])
  1567. in order to dereference an iterator pointing to an element of a container
  1568. holding the attributes to generate output from.
  1569. [heading Module Headers]
  1570. #include <boost/spirit/home/support/container.hpp>
  1571. Also, see __include_structure__.
  1572. [note This header file does not need to be included directly by any user
  1573. program as it is normally included by other Spirit header files relying
  1574. on its content.]
  1575. [heading Namespace]
  1576. [table
  1577. [[Name]]
  1578. [[`boost::spirit::traits`]]
  1579. ]
  1580. [heading Synopsis]
  1581. template <typename Iterator, typename Enable>
  1582. struct deref_iterator
  1583. {
  1584. typedef <unspecified> type;
  1585. static type call(Iterator& it);
  1586. };
  1587. [heading Template parameters]
  1588. [table
  1589. [[Parameter] [Description] [Default]]
  1590. [[`Iterator`] [The type, `Iterator` of the iterator to dereference.
  1591. This is the same as the type returned by the
  1592. customization point __customize_container_iterator__.] [none]]
  1593. [[`Enable`] [Helper template parameter usable to selectively
  1594. enable or disable certain specializations
  1595. of `deref_iterator` utilizing SFINAE (i.e.
  1596. `boost::enable_if` or `boost::disable_if`).] [`void`]]
  1597. ]
  1598. [variablelist Notation
  1599. [[`Iterator`] [An iterator type.]]
  1600. [[`it`] [An instance of an iterator of type `Iterator`.]]
  1601. [[`C`] [A container type whose iterator type is `Iterator`.]]
  1602. ]
  1603. [heading Expression Semantics]
  1604. [table
  1605. [[Expression] [Semantics]]
  1606. [[`deref_iterator<Iterator>::type`] [Metafunction result evaluating to the
  1607. type returned by dereferencing the iterator.]]
  1608. [[`deref_iterator<Iterator>::call(it)`] [Return the element in the container
  1609. referred to by the iterator. The type of the
  1610. returned value is the same as returned by the
  1611. metafunction result `type`.]]
  1612. ]
  1613. [heading Predefined Specializations]
  1614. __spirit__ predefines specializations of this customization point for
  1615. several types. The following table lists those types together with the
  1616. types returned by the embedded typedef `type`:
  1617. [table
  1618. [[Template Parameters] [Semantics]]
  1619. [[`Iterator`] [The metafunction result `type` evaluates to
  1620. `std::iterator_traits<Iterator>::reference` and the
  1621. function `call()` returns `*it`.]]
  1622. [[__unused_type__` const*`][The metafunction result `type` evaluates to
  1623. __unused_type__ and the function `call()` returns `unused`.]]
  1624. ]
  1625. [heading When to implement]
  1626. The customization point `deref_iterator` needs to be implemented for a specific
  1627. iterator type whenever the container this iterator belongs to is to be used as
  1628. an attribute in place of a STL container. It is applicable for generators
  1629. (__karma__) only. As a rule of thumb: it has to be implemented whenever a certain
  1630. iterator type belongs to a container which is to be passed as an attribute
  1631. to a generator normally exposing a STL container, `C` and if the container type
  1632. does not expose the interface of a STL container (i.e. `is_container<C>::type`
  1633. would normally return `mpl::false_`).
  1634. [heading Related Attribute Customization Points]
  1635. If this customization point is implemented, the following other customization
  1636. points might need to be implemented as well.
  1637. [table
  1638. [[Name] [When to implement]]
  1639. [[__customize_is_container__] [Needs to be implemented whenever a type is to be used as a container attribute in /Karma/.]]
  1640. [[__customize_container_iterator__] [Karma: __karma_list__, [karma_kleene Kleene (unary `*`)], __karma_plus__, [karma_repeat Repeat].]]
  1641. [[__customize_begin_container__] [Karma: __karma_list__, [karma_kleene Kleene (unary `*`)], __karma_plus__, [karma_repeat Repeat].]]
  1642. [[__customize_end_container__] [Karma: __karma_list__, [karma_kleene Kleene (unary `*`)], __karma_plus__, [karma_repeat Repeat].]]
  1643. [[__customize_deref_iterator__] [Karma: __karma_list__, [karma_kleene Kleene (unary `*`)], __karma_plus__, [karma_repeat Repeat].]]
  1644. [[__customize_next_iterator__] [Karma: __karma_list__, [karma_kleene Kleene (unary `*`)], __karma_plus__, [karma_repeat Repeat].]]
  1645. [[__customize_compare_iterators__] [Karma: __karma_list__, [karma_kleene Kleene (unary `*`)], __karma_plus__, [karma_repeat Repeat].]]
  1646. ]
  1647. [heading Example]
  1648. Here are the header files needed to make the example code below compile:
  1649. [customize_karma_counter_includes]
  1650. The example (for the full source code please see here:
  1651. [@../../example/karma/customize_counter.cpp customize_counter.cpp])
  1652. uses the data structure
  1653. [customize_karma_counter_data]
  1654. as a direct attribute to the __karma_list__ generator. This type does not
  1655. expose any of the interfaces of an STL container. It does not even expose the
  1656. usual semantics of a container. The presented customization points build a
  1657. counter instance which is incremented each time it is accessed. The examples
  1658. shows how to enable its use as an attribute to /Karma's/ repetitive generators.
  1659. In order to make this data structure compatible we need to specialize a couple
  1660. of attribute customization points: __customize_is_container__,
  1661. __customize_container_iterator__, __customize_begin_container__, and
  1662. __customize_end_container__. In addition, we specialize one of the
  1663. iterator related customization points as well: __customize_deref_iterator__.
  1664. [customize_karma_counter_traits]
  1665. [customize_karma_counter_iterator_traits]
  1666. The last code snippet shows an example using an instance of the data structure
  1667. `client::counter` to generate output from a __karma_list__ generator:
  1668. [customize_karma_counter]
  1669. As you can see, the specializations for the customization points as defined
  1670. above enable the seamless integration of the custom data structure without
  1671. having to modify the output format or the generator itself.
  1672. For other examples of how to use the customization point `deref_iterator`
  1673. please see here: __customize_use_as_container_example__.
  1674. [endsect] [/ deref_iterator]
  1675. [section:compare_iterators Compare two Iterator pointing into a Container Attribute for Equality]
  1676. [heading compare_iterators]
  1677. The template `compare_iterators` is a type used as an attribute customization
  1678. point. It is invoked by the /Karma/ repetitive generators (such as __karma_list__,
  1679. [karma_kleene Kleene (unary `*`)], __karma_plus__, and [karma_repeat Repeat])
  1680. in order to compare the current iterator (returned either from
  1681. __customize_begin_container__ or from __customize_next_iterator__) with the end
  1682. iterator (returned from __customize_end_container__) in order to find the end
  1683. of the element sequence to generate output for.
  1684. [heading Module Headers]
  1685. #include <boost/spirit/home/support/container.hpp>
  1686. Also, see __include_structure__.
  1687. [note This header file does not need to be included directly by any user
  1688. program as it is normally included by other Spirit header files relying
  1689. on its content.]
  1690. [heading Namespace]
  1691. [table
  1692. [[Name]]
  1693. [[`boost::spirit::traits`]]
  1694. ]
  1695. [heading Synopsis]
  1696. template <typename Iterator, typename Enable>
  1697. struct compare_iterators
  1698. {
  1699. static bool call(Iterator const& it1, Iterator const& it2);
  1700. };
  1701. [heading Template parameters]
  1702. [table
  1703. [[Parameter] [Description] [Default]]
  1704. [[`Iterator`] [The type, `Iterator` of the iterator to dereference.
  1705. This is the same as the type returned by the
  1706. customization point __customize_container_iterator__.] [none]]
  1707. [[`Enable`] [Helper template parameter usable to selectively
  1708. enable or disable certain specializations
  1709. of `compare_iterators` utilizing SFINAE (i.e.
  1710. `boost::enable_if` or `boost::disable_if`).] [`void`]]
  1711. ]
  1712. [variablelist Notation
  1713. [[`Iterator`] [An iterator type.]]
  1714. [[`it1`, `it2`] [Instances of an iterator of type `Iterator`.]]
  1715. [[`C`] [A container type whose iterator type is `Iterator`.]]
  1716. ]
  1717. [heading Expression Semantics]
  1718. [table
  1719. [[Expression] [Semantics]]
  1720. [[`compare_iterators<Iterator>::call(it1, it2)`]
  1721. [Returns whether the iterators `it1`
  1722. `it2` are to be treated as being
  1723. equal.]]
  1724. ]
  1725. [heading Predefined Specializations]
  1726. __spirit__ predefines specializations of this customization point for
  1727. several types. The following table lists those types together with the
  1728. types returned by the embedded typedef `type`:
  1729. [table
  1730. [[Template Parameters] [Semantics]]
  1731. [[`Iterator`] [The function `call()` returns it1 == it2.]]
  1732. [[__unused_type__` const*`][The function `call()` always returns false.]]
  1733. ]
  1734. [heading When to implement]
  1735. The customization point `compare_iterators` needs to be implemented for a specific
  1736. iterator type whenever the container this iterator belongs to is to be used as
  1737. an attribute in place of a STL container. It is applicable for generators
  1738. (__karma__) only. As a rule of thumb: it has to be implemented whenever a certain
  1739. iterator type belongs to a container which is to be passed as an attribute
  1740. to a generator normally exposing a STL container, `C` and if the container type
  1741. does not expose the interface of a STL container (i.e. `is_container<C>::type`
  1742. would normally return `mpl::false_`).
  1743. [heading Related Attribute Customization Points]
  1744. If this customization point is implemented, the following other customization
  1745. points might need to be implemented as well.
  1746. [table
  1747. [[Name] [When to implement]]
  1748. [[__customize_is_container__] [Needs to be implemented whenever a type is to be used as a container attribute in /Karma/.]]
  1749. [[__customize_container_iterator__] [Karma: __karma_list__, [karma_kleene Kleene (unary `*`)], __karma_plus__, [karma_repeat Repeat].]]
  1750. [[__customize_begin_container__] [Karma: __karma_list__, [karma_kleene Kleene (unary `*`)], __karma_plus__, [karma_repeat Repeat].]]
  1751. [[__customize_end_container__] [Karma: __karma_list__, [karma_kleene Kleene (unary `*`)], __karma_plus__, [karma_repeat Repeat].]]
  1752. [[__customize_deref_iterator__] [Karma: __karma_list__, [karma_kleene Kleene (unary `*`)], __karma_plus__, [karma_repeat Repeat].]]
  1753. [[__customize_next_iterator__] [Karma: __karma_list__, [karma_kleene Kleene (unary `*`)], __karma_plus__, [karma_repeat Repeat].]]
  1754. [[__customize_compare_iterators__] [Karma: __karma_list__, [karma_kleene Kleene (unary `*`)], __karma_plus__, [karma_repeat Repeat].]]
  1755. ]
  1756. [heading Example]
  1757. For an example of how to use the customization point `compare_iterators`
  1758. please see here: __customize_use_as_container_example__.
  1759. [endsect] [/ compare_iterators]
  1760. [endsect] [/ iterate]
  1761. [/////////////////////////////////////////////////////////////////////////////]
  1762. [section:string_traits Extract a C-Style String to Generate Output from a String Type (Karma)]
  1763. [section:is_char Determine if a Type is a Character]
  1764. [heading is_char]
  1765. `is_char` is a metafunction that detects if a given type is a character.
  1766. [heading Module Headers]
  1767. #include <boost/spirit/home/support/string_traits.hpp>
  1768. Also, see __include_structure__.
  1769. [note This header file does not need to be included directly by any user
  1770. program as it is normally included by other Spirit header files relying
  1771. on its content.]
  1772. [heading Namespace]
  1773. [table
  1774. [[Name]]
  1775. [[`boost::spirit::traits`]]
  1776. ]
  1777. [heading Synopsis]
  1778. template <typename T>
  1779. struct is_char
  1780. {
  1781. <unspecified>;
  1782. };
  1783. [heading Template parameters]
  1784. [table
  1785. [[Parameter] [Description] [Default]]
  1786. [[`T`] [The type to detect.] [none]]
  1787. ]
  1788. [variablelist Notation
  1789. [[`T`] [An arbitrary type]]
  1790. ]
  1791. [heading Expression Semantics]
  1792. [table
  1793. [[Expression] [Semantics]]
  1794. [[`is_char<T>::type`] [`mpl::true_` if T should be treated as a character
  1795. type, and `mpl::false_` otherwise. Generally,
  1796. any implementation of `is_char` needs to behave as
  1797. if if was a __mpl_boolean_constant__.]]
  1798. ]
  1799. [heading Predefined Specializations]
  1800. [table
  1801. [[Type] [Semantics]]
  1802. [[`T`] [`mpl::false_`]]
  1803. [[`T const`] [`is_char<T>`]]
  1804. [[`char`] [`mpl::true_`]]
  1805. [[`wchar_t`] [`mpl::true_`]]
  1806. ]
  1807. [heading When to implement]
  1808. This customization point needs to be implemented for any strings that use a
  1809. type other than `char` or `wchar_t to store character data.
  1810. [heading Related Attribute Customization Points]
  1811. If this customization point is implemented, the following other customization
  1812. points need to be implemented as well.
  1813. [table
  1814. [[Name] [When to implement]]
  1815. [[__customize_is_string__] [Whenever `is_char` is implemented.]]
  1816. [[__customize_char_type_of__] [Whenever `is_char` is implemented.]]
  1817. ]
  1818. [/ TODO: examples ]
  1819. [endsect] [/ is_char]
  1820. [section:char_type_of Determine the Character Type of a String]
  1821. [heading char_type_of]
  1822. This customization point is an MPL metafunction which returns the character
  1823. type of a given string type. `char_type_of` handles user-defined types such as
  1824. std::string, as well as C-style strings.
  1825. [heading Module Headers]
  1826. #include <boost/spirit/home/support/string_traits.hpp>
  1827. Also, see __include_structure__.
  1828. [note This header file does not need to be included directly by any user
  1829. program as it is normally included by other Spirit header files relying
  1830. on its content.]
  1831. [heading Namespace]
  1832. [table
  1833. [[Name]]
  1834. [[`boost::spirit::traits`]]
  1835. ]
  1836. [heading Synopsis]
  1837. template <typename T>
  1838. struct char_type_of
  1839. {
  1840. typedef <unspecified> type;
  1841. };
  1842. [heading Template parameters]
  1843. [table
  1844. [[Parameter] [Description] [Default]]
  1845. [[`T`] [A string type.] [none]]
  1846. ]
  1847. [variablelist Notation
  1848. [[`T`] [An arbitrary type.]]
  1849. [[`N`] [An arbitrary integral constant.]]
  1850. [[`Char`] [A character type.]]
  1851. [[`Traits`] [A character traits type.]]
  1852. [[`Allocator`] [A standard allocator type.]]
  1853. ]
  1854. [heading Expression Semantics]
  1855. [table
  1856. [[Expression] [Semantics]]
  1857. [[`char_type_of<T>::type`] [The character type of the string type `T`.]]
  1858. ]
  1859. [heading Predefined Specializations]
  1860. [table
  1861. [[Type] [Semantics]]
  1862. [[`T const`] [Returns `char_type_of<T>`.]]
  1863. [[`char`] [Returns `char`.]]
  1864. [[`wchar_t`] [Returns `wchar_t`.]]
  1865. [[`char const*`] [Returns `char const`.]]
  1866. [[`wchar_t const*`] [Returns `wchar_t const`.]]
  1867. [[`char*`] [Returns `char`.]]
  1868. [[`wchar_t*`] [Returns `wchar_t`.]]
  1869. [[`char[N]`] [Returns `char`.]]
  1870. [[`wchar_t[N]`] [Returns `wchar_t`.]]
  1871. [[`char const[N]`] [Returns `char const`.]]
  1872. [[`wchar_t const[N]`] [Returns `wchar_t const`.]]
  1873. [[`char(&)[N]`] [Returns `char`.]]
  1874. [[`wchar_t(&)[N]`] [Returns `wchar_t`.]]
  1875. [[`char const(&)[N]`] [Returns `char const`.]]
  1876. [[`wchar_t const(&)[N]`] [Returns `wchar_t const`.]]
  1877. [[`std::basic_string<Char, Traits, Allocator>`] [Returns `Char`.]]
  1878. ]
  1879. [heading When to implement]
  1880. This customization point needs to be implemented whenever __customize_is_string__
  1881. is implemented.
  1882. [heading Related Attribute Customization Points]
  1883. If this customization point is implemented, the following other customization
  1884. points need to be implemented as well.
  1885. [table
  1886. [[Name] [When to implement]]
  1887. [[__customize_is_char__] [For string types whose underlying character type
  1888. is not `char` or `wchar_t`, `is_char` must be
  1889. implemented.]]
  1890. [[__customize_is_string__] [Whenever `char_type_of` is implemented.]]
  1891. [[__customize_extract_c_string__] [Whenever `char_type_of` is implemented.]]
  1892. ]
  1893. [/ TODO: examples ]
  1894. [endsect] [/ char_type_of]
  1895. [section:extract_c_string Get a C-style String from a String Type]
  1896. [heading extract_c_string]
  1897. `extract_c_string` returns a pointer to an array of elements of a const character
  1898. type. It is invoked through a static method `call`. This customization point is
  1899. responsible for handling it's own garbage collecting; the lifetime of the returned
  1900. C-string must be no shorter than the lifetime of the string instance passed to
  1901. the `call` method.
  1902. [heading Module Headers]
  1903. #include <boost/spirit/home/support/string_traits.hpp>
  1904. Also, see __include_structure__.
  1905. [note This header file does not need to be included directly by any user
  1906. program as it is normally included by other Spirit header files relying
  1907. on its content.]
  1908. [heading Namespace]
  1909. [table
  1910. [[Name]]
  1911. [[`boost::spirit::traits`]]
  1912. ]
  1913. [heading Synopsis]
  1914. template <typename String>
  1915. struct extract_c_string
  1916. {
  1917. typedef <unspecified> char_type;
  1918. static char_type const* call (String const&);
  1919. };
  1920. [heading Template parameters]
  1921. [table
  1922. [[Parameter] [Description] [Default]]
  1923. [[`String`] [A string type.] [none]]
  1924. ]
  1925. [variablelist Notation
  1926. [[`T`] [An arbitrary type.]]
  1927. [[`Char`] [A character type.]]
  1928. [[`Traits`] [A character traits type.]]
  1929. [[`Allocator`] [A standard allocator type.]]
  1930. [[`str`] [A string instance.]]
  1931. ]
  1932. [heading Expression Semantics]
  1933. [table
  1934. [[Expression] [Semantics]]
  1935. [[`extract_c_string<T>::char_type`] [The return type of `call`.]]
  1936. [[`extract_c_string<T>::call(str)`] [Extract a c-string of type `char_type`
  1937. from `str`.]]
  1938. ]
  1939. [heading Predefined Specializations]
  1940. [table
  1941. [[Type] [Semantics]]
  1942. [[`T`] [`call` takes a parameter of type `T const*`, and returns it without
  1943. modification. An overload of `call` takes a parameter of type `T*`
  1944. and casts it to `T const*`, returning the result. `char_type` is
  1945. `char_type_of<T>::type`.]]
  1946. [[`T const`] [`call` takes a parameter `str` of type `T const` and returns
  1947. `extract_c_string<T>::call(str)`. `char_type` is
  1948. `char_type_of<T>::type`.]]
  1949. [[`T&`] [`call` takes a parameter `str` of type `T&` and returns
  1950. `extract_c_string<T>::call(str)`. `char_type` is
  1951. `char_type_of<T>::type`.]]
  1952. [[`T const&`] [`call` takes a parameter `str` of type `T const&` and returns
  1953. `extract_c_string<T>::call(str)`. `char_type` is
  1954. `char_type_of<T>::type`.]]
  1955. [[`std::basic_string<Char, Traits, Allocator>`]
  1956. [`call` takes a parameter `str` and returns `str.c_str()`. `char_type` is
  1957. `Char`.]]
  1958. ]
  1959. [heading When to implement]
  1960. This customization point needs to be implemented whenever __customize_is_string__
  1961. is implemented.
  1962. [heading Related Attribute Customization Points]
  1963. If this customization point is implemented, the following other customization
  1964. points need to be implemented as well.
  1965. [table
  1966. [[Name] [When to implement]]
  1967. [[__customize_is_char__] [For string types whose underlying character type
  1968. is not `char` or `wchar_t`, `is_char` must be
  1969. implemented.]]
  1970. [[__customize_is_string__] [Whenever `extract_c_string` is implemented.]]
  1971. [[__customize_char_type_of__] [Whenever `extract_c_string` is implemented.]]
  1972. ]
  1973. [/ TODO: examples ]
  1974. [endsect] [/ string]
  1975. [endsect] [/ string_traits]
  1976. [/////////////////////////////////////////////////////////////////////////////]
  1977. [section:attribute_as Atomically Extract an Attribute Value from a Container (Karma)]
  1978. [heading attribute_as]
  1979. `attribute_as` atomically extracts an instance of a type from another type.
  1980. This customization point is used by the __karma_as__ directive.
  1981. [heading Module Headers]
  1982. #include <boost/spirit/home/support/attributes_fwd.hpp>
  1983. Also, see __include_structure__.
  1984. [note This header file does not need to be included directly by any user
  1985. program as it is normally included by other Spirit header files relying
  1986. on its content.]
  1987. [heading Namespace]
  1988. [table
  1989. [[Name]]
  1990. [[`boost::spirit::traits`]]
  1991. ]
  1992. [heading Synopsis]
  1993. template <typename T, typename Attribute, typename Enable = void>
  1994. struct attribute_as;
  1995. [heading Template parameters]
  1996. [table
  1997. [[Parameter] [Description] [Default]]
  1998. [[`T`] [The type of the attribute natively
  1999. exposed by the component the `attribute_as` is
  2000. invoked from.] [none]]
  2001. [[`Attribute`] [The type of the attribute to be used to
  2002. generate output from.] [none]]
  2003. [[`Enable`] [Helper template parameter usable to selectively
  2004. enable or disable certain specializations
  2005. of `attribute_as` utilizing SFINAE (i.e.
  2006. `boost::enable_if` or `boost::disable_if`).] [`void`]]
  2007. ]
  2008. [variablelist Notation
  2009. [[`attr`] [An instance of type `Attrib`.]]
  2010. ]
  2011. [heading Expression Semantics]
  2012. [table
  2013. [[Expression] [Semantics]]
  2014. [[`attribute_as<T, Attribute>::type`] [The result type of the extraction.]]
  2015. [[`attribute_as<T, Attribute>::call(attr)`] [Extract and return an instance
  2016. of `type`.]]
  2017. [[`attribute_as<T, Attribute>::valid_as(attr)`] [Determine, at runtime, if the extraction of
  2018. an instance of `type` from `attr`
  2019. would cause an error.]]
  2020. ]
  2021. [heading Predefined Specializations]
  2022. __spirit__ predefines specializations of this customization point for
  2023. several types. The following table lists those types together with the types
  2024. exposed and the corresponding semantics:
  2025. [table
  2026. [[Template Parameters] [Semantics]]
  2027. [[__unused_type__] [The exposed typedef `type` is defined to
  2028. __unused_type__. The function `call()` returns
  2029. an instance of __unused_type__.]]
  2030. ]
  2031. [heading When to implement]
  2032. This customization point may need to be implemented when using the __karma_as__
  2033. directive.
  2034. [/ TODO: examples ]
  2035. [endsect] [/ attribute_as]
  2036. [/////////////////////////////////////////////////////////////////////////////]
  2037. [section:auto Create Components from Attributes (Qi and Karma)]
  2038. [def __auto_parser_requirements__ [link spirit.qi.reference.auto.additional_requirements Additional Attribute Requirements for Parsers]]
  2039. [def __auto_generator_requirements__ [link spirit.karma.reference.auto.additional_requirements Additional Attribute Requirements for Generators]]
  2040. [def __auto_parser_example__ [link spirit.qi.reference.auto.example Example for Using the `qi::auto_` Parser]]
  2041. [def __auto_generator_example__ [link spirit.karma.reference.auto.example Example for Using the `karma::auto_` Generator]]
  2042. __spirit__ supports the creation of a default parser or a default generator from
  2043. a given attribute type. It implements a minimal set of predefined mappings from
  2044. different attribute types to parsers and generators (for a description of the
  2045. predefined mappings see __auto_parser_requirements__ and
  2046. __auto_generator_requirements__).
  2047. The customization points described in this section (__customize_create_parser__
  2048. and __customize_create_generator__) can be specialized to define additional
  2049. mappings for custom data types.
  2050. [section:create_parser Define a Custom Attribute Mapping for a Parser]
  2051. [heading create_parser]
  2052. The template `create_parser` is a type used as an customization point. It is
  2053. invoked by the /Qi/ __create_parser__ API function in order to create
  2054. a custom mapping of the given data type to a parser expression. This
  2055. parser expression will be returned from __create_parser__ whenever the
  2056. given data type is encountered.
  2057. [heading Module Headers]
  2058. // forwards to <boost/spirit/home/qi/auto.hpp>
  2059. #include <boost/spirit/include/qi_auto.hpp>
  2060. Also, see __include_structure__.
  2061. [heading Namespace]
  2062. [table
  2063. [[Name]]
  2064. [[`boost::spirit::traits`]]
  2065. ]
  2066. [heading Synopsis]
  2067. template <typename T, typename Enable>
  2068. struct create_parser
  2069. {
  2070. typedef <unspecified> type;
  2071. static type const& call();
  2072. };
  2073. [heading Template parameters]
  2074. [table
  2075. [[Parameter] [Description] [Default]]
  2076. [[`T`] [The type, `T` for which a custom mapping to a
  2077. parser should be established.] [none]]
  2078. [[`Enable`] [Helper template parameter usable to selectively
  2079. enable or disable certain specializations
  2080. of `create_generator` utilizing SFINAE (i.e.
  2081. `boost::enable_if` or `boost::disable_if`).] [`void`]]
  2082. ]
  2083. [variablelist Notation
  2084. [[`T`] [An arbitrary type.]]
  2085. ]
  2086. [heading Expression Semantics]
  2087. [table
  2088. [[Expression] [Semantics]]
  2089. [[`create_parser<T>::type`] [Defines the type of the parser
  2090. expression returned from `call`.]]
  2091. [[`create_parser<T>::call()`] [Returns a parser expression (usually
  2092. this is a proto::expression) to be used
  2093. as the default parser for the given
  2094. type, `T`.]]
  2095. ]
  2096. [heading Predefined Specializations]
  2097. __spirit__ predefines specializations of this customization point for
  2098. several types. All predefined mappings are listed here: __auto_parser_requirements__.
  2099. [note It is possible to overload the predefined mappings for the listed types
  2100. by providing your own specialization of the `create_parser` customization
  2101. point for the type to modify.]
  2102. [heading When to implement]
  2103. The customization point `create_parser` needs to be implemented for a specific
  2104. type whenever this type should be usable with the API function __create_parser__
  2105. (which includes using the `qi::auto_` parser and the special API functions
  2106. based on the automatic creation of the matching parser type).
  2107. [heading Example]
  2108. For an example of how to use the customization point `create_parser`
  2109. please see here: __auto_parser_example__.
  2110. [endsect]
  2111. [section:create_generator Define a Custom Attribute Mapping for a Generator]
  2112. [heading create_generator]
  2113. The template `create_generator` is a type used as an customization point. It is
  2114. invoked by the /Karma/ __create_generator__ API function in order to create
  2115. a custom mapping of the given data type to a generator expression. This
  2116. generator expression will be returned from __create_generator__ whenever the
  2117. given data type is encountered.
  2118. [heading Module Headers]
  2119. // forwards to <boost/spirit/home/karma/auto.hpp>
  2120. #include <boost/spirit/include/karma_auto.hpp>
  2121. Also, see __include_structure__.
  2122. [heading Namespace]
  2123. [table
  2124. [[Name]]
  2125. [[`boost::spirit::traits`]]
  2126. ]
  2127. [heading Synopsis]
  2128. template <typename T, typename Enable>
  2129. struct create_generator
  2130. {
  2131. typedef <unspecified> type;
  2132. static type const& call();
  2133. };
  2134. [heading Template parameters]
  2135. [table
  2136. [[Parameter] [Description] [Default]]
  2137. [[`T`] [The type, `T` for which a custom mapping to a
  2138. generator should be established.] [none]]
  2139. [[`Enable`] [Helper template parameter usable to selectively
  2140. enable or disable certain specializations
  2141. of `create_generator` utilizing SFINAE (i.e.
  2142. `boost::enable_if` or `boost::disable_if`).] [`void`]]
  2143. ]
  2144. [variablelist Notation
  2145. [[`T`] [An arbitrary type.]]
  2146. ]
  2147. [heading Expression Semantics]
  2148. [table
  2149. [[Expression] [Semantics]]
  2150. [[`create_generator<T>::type`] [Defines the type of the generator
  2151. expression returned from `call`.]]
  2152. [[`create_generator<T>::call()`] [Returns a generator expression (usually
  2153. this is a proto::expression) to be used
  2154. as the default generator for the given
  2155. type, `T`.]]
  2156. ]
  2157. [heading Predefined Specializations]
  2158. __spirit__ predefines specializations of this customization point for
  2159. several types. All predefined mappings are listed here: __auto_generator_requirements__.
  2160. [note It is possible to overload the predefined mappings for the listed types
  2161. by providing your own specialization of the `create_generator` customization
  2162. point for the type to modify.]
  2163. [heading When to implement]
  2164. The customization point `create_generator` needs to be implemented for a specific
  2165. type whenever this type should be usable with the API function __create_generator__
  2166. (which includes using the `karma::auto_` generator and the special API functions
  2167. based on the automatic creation of the matching generator type).
  2168. [heading Example]
  2169. For an example of how to use the customization point `create_generator`
  2170. please see here: __auto_generator_example__.
  2171. [endsect]
  2172. [endsect]
  2173. [endsect] [/ customize]