binary.qbk 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  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. [section:binary Binary Generators]
  8. This module includes different generators allowing to output binary data.
  9. It includes generators for default, little, and big endian binary output and
  10. a `pad` generator allowing to control padding of the generated output
  11. stream.
  12. [heading Module Header]
  13. // forwards to <boost/spirit/home/karma/binary.hpp>
  14. #include <boost/spirit/include/karma_binary.hpp>
  15. Also, see __include_structure__.
  16. [/////////////////////////////////////////////////////////////////////////////]
  17. [section:binary_native Binary Native Endianness Generators]
  18. [heading Description]
  19. The binary native endianness generators described in this section are used to
  20. emit binary byte streams laid out conforming to the native endianness (byte
  21. order) of the target architecture.
  22. [heading Header]
  23. // forwards to <boost/spirit/home/karma/binary.hpp>
  24. #include <boost/spirit/include/karma_binary.hpp>
  25. Also, see __include_structure__.
  26. [heading Namespace]
  27. [table
  28. [[Name]]
  29. [[`boost::spirit::byte_ // alias: boost::spirit::karma::byte_` ]]
  30. [[`boost::spirit::word // alias: boost::spirit::karma::word` ]]
  31. [[`boost::spirit::dword // alias: boost::spirit::karma::dword` ]]
  32. [[`boost::spirit::qword // alias: boost::spirit::karma::qword` ]]
  33. [[`boost::spirit::bin_float // alias: boost::spirit::karma::bin_float` ]]
  34. [[`boost::spirit::bin_double // alias: boost::spirit::karma::bin_double` ]]
  35. ]
  36. [note The generators `qword` and `qword(qw)` are only available on
  37. platforms where the preprocessor constant `BOOST_HAS_LONG_LONG` is
  38. defined (i.e. on platforms having native support for `unsigned long long`
  39. (64 bit) integer types).]
  40. [heading Model of]
  41. [:__primitive_generator_concept__]
  42. [variablelist Notation
  43. [[`b`] [A single byte (8 bit binary value) or a __karma_lazy_argument__
  44. that evaluates to a single byte]]
  45. [[`w`] [A 16 bit binary value or a __karma_lazy_argument__ that
  46. evaluates to a 16 bit binary value. This value is always
  47. interpreted using native endianness.]]
  48. [[`dw`] [A 32 bit binary value or a __karma_lazy_argument__ that
  49. evaluates to a 32 bit binary value. This value is always
  50. interpreted using native endianness.]]
  51. [[`qw`] [A 64 bit binary value or a __karma_lazy_argument__ that
  52. evaluates to a 64 bit binary value. This value is always
  53. interpreted using native endianness.]]
  54. [[`f`] [A float binary value or a __karma_lazy_argument__ that
  55. evaluates to a float binary value. This value is always
  56. interpreted using native endianness.]]
  57. [[`d`] [A double binary value or a __karma_lazy_argument__ that
  58. evaluates to a double binary value. This value is always
  59. interpreted using native endianness.]]
  60. ]
  61. [heading Expression Semantics]
  62. Semantics of an expression is defined only where it differs from, or is
  63. not defined in __primitive_generator_concept__.
  64. [table
  65. [[Expression] [Description]]
  66. [[`byte_`] [Output the binary representation of the least
  67. significant byte of the mandatory attribute. This
  68. generator never fails (unless the underlying
  69. output stream reports an error).]]
  70. [[`word`] [Output the binary representation of the least
  71. significant 16 bits of the mandatory attribute
  72. in native endian representation. This generator
  73. never fails (unless the underlying output stream
  74. reports an error).]]
  75. [[`dword`] [Output the binary representation of the least
  76. significant 32 bits of the mandatory attribute
  77. in native endian representation. This generator
  78. never fails (unless the underlying output stream
  79. reports an error).]]
  80. [[`qword`] [Output the binary representation of the least
  81. significant 64 bits of the mandatory attribute
  82. in native endian representation. This generator
  83. never fails (unless the underlying output stream
  84. reports an error).]]
  85. [[`bin_float`] [Output the binary representation of the mandatory
  86. float attribute in native endian representation.
  87. This generator never fails (unless the underlying
  88. output stream reports an error).]]
  89. [[`bin_double`] [Output the binary representation of the mandatory
  90. double attribute in native endian representation.
  91. This generator never fails (unless the underlying
  92. output stream reports an error).]]
  93. [[`byte_(b)`] [Output the binary representation of the least
  94. significant byte of the immediate parameter. This
  95. generator never fails (unless the underlying
  96. output stream reports an error).]]
  97. [[`word(w)`] [Output the binary representation of the least
  98. significant 16 bits of the immediate parameter
  99. in native endian representation. This generator
  100. never fails (unless the underlying output stream
  101. reports an error).]]
  102. [[`dword(dw)`] [Output the binary representation of the least
  103. significant 32 bits of the immediate parameter
  104. in native endian representation. This generator
  105. never fails (unless the underlying output stream
  106. reports an error).]]
  107. [[`qword(qw)`] [Output the binary representation of the least
  108. significant 64 bits of the immediate parameter
  109. in native endian representation. This generator
  110. never fails (unless the underlying output stream
  111. reports an error).]]
  112. [[`bin_float(f)`] [Output the binary representation of the immediate
  113. float parameter in native endian representation.
  114. This generator never fails (unless the underlying
  115. output stream reports an error).]]
  116. [[`bin_double(d)`] [Output the binary representation of the immediate
  117. double parameter in native endian representation.
  118. This generator never fails (unless the underlying
  119. output stream reports an error).]]
  120. ]
  121. [heading Attributes]
  122. [table
  123. [[Expression] [Attribute]]
  124. [[`byte_`] [`boost::uint_least8_t`, attribute is mandatory
  125. (otherwise compilation will fail)]]
  126. [[`word`] [`boost::uint_least16_t`, attribute is mandatory
  127. (otherwise compilation will fail)]]
  128. [[`dword`] [`boost::uint_least32_t`, attribute is mandatory
  129. (otherwise compilation will fail)]]
  130. [[`qword`] [`boost::uint_least64_t`, attribute is mandatory
  131. (otherwise compilation will fail)]]
  132. [[`bin_float`] [`float`, attribute is mandatory
  133. (otherwise compilation will fail)]]
  134. [[`bin_double`] [`double`, attribute is mandatory
  135. (otherwise compilation will fail)]]
  136. [[`byte_(b)`] [__unused__]]
  137. [[`word(w)`] [__unused__]]
  138. [[`dword(dw)`] [__unused__]]
  139. [[`qword(qw)`] [__unused__]]
  140. [[`bin_float(f)`] [__unused__]]
  141. [[`bin_double(d)`] [__unused__]]
  142. ]
  143. [note In addition to their usual attribute of type `Attrib` all listed generators
  144. accept an instance of a `boost::optional<Attrib>` as well. If the
  145. `boost::optional<>` is initialized (holds a value) the generators behave
  146. as if their attribute was an instance of `Attrib` and emit the value stored
  147. in the `boost::optional<>`. Otherwise the generators will fail.]
  148. [heading Complexity]
  149. [:O(N), where N is the number of bytes emitted by the binary generator]
  150. [heading Example]
  151. [note The test harness for the example(s) below is presented in the
  152. __karma_basics_examples__ section.]
  153. Some includes:
  154. [reference_karma_includes]
  155. Some using declarations:
  156. [reference_karma_using_declarations_native_binary]
  157. Basic usage of the native binary generators with some results for little endian
  158. platforms:
  159. [reference_karma_native_binary_little]
  160. Basic usage of the native binary generators with some results for big endian
  161. platforms:
  162. [reference_karma_native_binary_big]
  163. [endsect]
  164. [/////////////////////////////////////////////////////////////////////////////]
  165. [section:binary_little Binary Little Endianness Generators]
  166. [heading Description]
  167. The little native endianness generators described in this section are used to
  168. emit binary byte streams laid out conforming to the little endianness byte
  169. order.
  170. [heading Header]
  171. // forwards to <boost/spirit/home/karma/binary.hpp>
  172. #include <boost/spirit/include/karma_binary.hpp>
  173. Also, see __include_structure__.
  174. [heading Namespace]
  175. [table
  176. [[Name]]
  177. [[`boost::spirit::little_word // alias: boost::spirit::karma::little_word` ]]
  178. [[`boost::spirit::little_dword // alias: boost::spirit::karma::little_dword` ]]
  179. [[`boost::spirit::little_qword // alias: boost::spirit::karma::little_qword` ]]
  180. [[`boost::spirit::little_bin_float // alias: boost::spirit::karma::little_bin_float` ]]
  181. [[`boost::spirit::little_bin_double // alias: boost::spirit::karma::little_bin_double` ]]
  182. ]
  183. [note The generators `little_qword` and `little_qword(qw)` are only available on
  184. platforms where the preprocessor constant `BOOST_HAS_LONG_LONG` is
  185. defined (i.e. on platforms having native support for `unsigned long long`
  186. (64 bit) integer types).]
  187. [heading Model of]
  188. [:__primitive_generator_concept__]
  189. [variablelist Notation
  190. [[`w`] [A 16 bit binary value or a __karma_lazy_argument__ that
  191. evaluates to a 16 bit binary value. This value is always
  192. interpreted using native endianness.]]
  193. [[`dw`] [A 32 bit binary value or a __karma_lazy_argument__ that
  194. evaluates to a 32 bit binary value. This value is always
  195. interpreted using native endianness.]]
  196. [[`qw`] [A 64 bit binary value or a __karma_lazy_argument__ that
  197. evaluates to a 64 bit binary value. This value is always
  198. interpreted using native endianness.]]
  199. [[`f`] [A float binary value or a __karma_lazy_argument__ that
  200. evaluates to a float binary value. This value is always
  201. interpreted using native endianness.]]
  202. [[`d`] [A double binary value or a __karma_lazy_argument__ that
  203. evaluates to a double binary value. This value is always
  204. interpreted using native endianness.]]
  205. ]
  206. [heading Expression Semantics]
  207. Semantics of an expression is defined only where it differs from, or is
  208. not defined in __primitive_generator_concept__.
  209. [table
  210. [[Expression] [Description]]
  211. [[`little_word`] [Output the binary representation of the least
  212. significant 16 bits of the mandatory attribute
  213. in little endian representation. This generator
  214. never fails (unless the underlying output stream
  215. reports an error).]]
  216. [[`little_dword`] [Output the binary representation of the least
  217. significant 32 bits of the mandatory attribute
  218. in little endian representation. This generator
  219. never fails (unless the underlying output stream
  220. reports an error).]]
  221. [[`little_qword`] [Output the binary representation of the least
  222. significant 64 bits of the mandatory attribute
  223. in little endian representation. This generator
  224. never fails (unless the underlying output stream
  225. reports an error).]]
  226. [[`little_bin_float`] [Output the binary representation of the mandatory
  227. float attribute in little endian representation.
  228. This generator never fails (unless the underlying
  229. output stream reports an error).]]
  230. [[`little_bin_double`] [Output the binary representation of the mandatory
  231. double attribute in little endian representation.
  232. This generator never fails (unless the underlying
  233. output stream reports an error).]]
  234. [[`little_word(w)`] [Output the binary representation of the least
  235. significant 16 bits of the immediate parameter
  236. in little endian representation. This generator
  237. never fails (unless the underlying output stream
  238. reports an error).]]
  239. [[`little_dword(dw)`] [Output the binary representation of the least
  240. significant 32 bits of the immediate parameter
  241. in little endian representation. This generator
  242. never fails (unless the underlying output stream
  243. reports an error).]]
  244. [[`little_qword(qw)`] [Output the binary representation of the least
  245. significant 64 bits of the immediate parameter
  246. in little endian representation. This generator
  247. never fails (unless the underlying output stream
  248. reports an error).]]
  249. [[`little_bin_float(f)`] [Output the binary representation of the immediate
  250. float parameter in little endian representation.
  251. This generator never fails (unless the underlying
  252. output stream reports an error).]]
  253. [[`little_bin_double(d)`] [Output the binary representation of the immediate
  254. double parameter in little endian representation.
  255. This generator never fails (unless the underlying
  256. output stream reports an error).]]
  257. ]
  258. [heading Attributes]
  259. [table
  260. [[Expression] [Attribute]]
  261. [[`little_word`] [`boost::uint_least16_t`, attribute is mandatory
  262. (otherwise compilation will fail)]]
  263. [[`little_dword`] [`boost::uint_least32_t`, attribute is mandatory
  264. (otherwise compilation will fail)]]
  265. [[`little_qword`] [`boost::uint_least64_t`, attribute is mandatory
  266. (otherwise compilation will fail)]]
  267. [[`little_bin_float`] [`float`, attribute is mandatory
  268. (otherwise compilation will fail)]]
  269. [[`little_bin_double`] [`double`, attribute is mandatory
  270. (otherwise compilation will fail)]]
  271. [[`little_word(w)`] [__unused__]]
  272. [[`little_dword(dw)`] [__unused__]]
  273. [[`little_qword(qw)`] [__unused__]]
  274. [[`little_bin_float(f)`] [__unused__]]
  275. [[`little_bin_double(d)`] [__unused__]]
  276. ]
  277. [heading Complexity]
  278. [:O(N), where N is the number of bytes emitted by the binary generator]
  279. [heading Example]
  280. [note The test harness for the example(s) below is presented in the
  281. __karma_basics_examples__ section.]
  282. Some includes:
  283. [reference_karma_includes]
  284. Some using declarations:
  285. [reference_karma_using_declarations_little_binary]
  286. Basic usage of the little binary generators:
  287. [reference_karma_little_binary]
  288. [endsect]
  289. [/////////////////////////////////////////////////////////////////////////////]
  290. [section:binary_big Binary Big Endianness Generators]
  291. [heading Description]
  292. The big native endianness generators described in this section are used to
  293. emit binary byte streams laid out conforming to the big endianness byte
  294. order.
  295. [heading Header]
  296. // forwards to <boost/spirit/home/karma/binary.hpp>
  297. #include <boost/spirit/include/karma_binary.hpp>
  298. Also, see __include_structure__.
  299. [heading Namespace]
  300. [table
  301. [[Name]]
  302. [[`boost::spirit::big_word // alias: boost::spirit::karma::big_word` ]]
  303. [[`boost::spirit::big_dword // alias: boost::spirit::karma::big_dword` ]]
  304. [[`boost::spirit::big_qword // alias: boost::spirit::karma::big_qword` ]]
  305. [[`boost::spirit::big_bin_float // alias: boost::spirit::karma::big_bin_float` ]]
  306. [[`boost::spirit::big_bin_double // alias: boost::spirit::karma::big_bin_double` ]]
  307. ]
  308. [note The generators `big_qword` and `big_qword(qw)` are only available on
  309. platforms where the preprocessor constant `BOOST_HAS_LONG_LONG` is
  310. defined (i.e. on platforms having native support for `unsigned long long`
  311. (64 bit) integer types).]
  312. [heading Model of]
  313. [:__primitive_generator_concept__]
  314. [variablelist Notation
  315. [[`w`] [A 16 bit binary value or a __karma_lazy_argument__ that
  316. evaluates to a 16 bit binary value. This value is always
  317. interpreted using native endianness.]]
  318. [[`dw`] [A 32 bit binary value or a __karma_lazy_argument__ that
  319. evaluates to a 32 bit binary value. This value is always
  320. interpreted using native endianness.]]
  321. [[`qw`] [A 64 bit binary value or a __karma_lazy_argument__ that
  322. evaluates to a 64 bit binary value. This value is always
  323. interpreted using native endianness.]]
  324. [[`f`] [A float binary value or a __karma_lazy_argument__ that
  325. evaluates to a float binary value. This value is always
  326. interpreted using native endianness.]]
  327. [[`d`] [A double binary value or a __karma_lazy_argument__ that
  328. evaluates to a double binary value. This value is always
  329. interpreted using native endianness.]]
  330. ]
  331. [heading Expression Semantics]
  332. Semantics of an expression is defined only where it differs from, or is
  333. not defined in __primitive_generator_concept__.
  334. [table
  335. [[Expression] [Description]]
  336. [[`big_word`] [Output the binary representation of the least
  337. significant 16 bits of the mandatory attribute
  338. in big endian representation. This generator
  339. never fails (unless the underlying output stream
  340. reports an error).]]
  341. [[`big_dword`] [Output the binary representation of the least
  342. significant 32 bits of the mandatory attribute
  343. in big endian representation. This generator
  344. never fails (unless the underlying output stream
  345. reports an error).]]
  346. [[`big_qword`] [Output the binary representation of the least
  347. significant 64 bits of the mandatory attribute
  348. in big endian representation. This generator
  349. never fails (unless the underlying output stream
  350. reports an error).]]
  351. [[`big_bin_float`] [Output the binary representation of the mandatory
  352. float attribute in big endian representation.
  353. This generator never fails (unless the underlying
  354. output stream reports an error).]]
  355. [[`big_bin_double`] [Output the binary representation of the mandatory
  356. double attribute in big endian representation.
  357. This generator never fails (unless the underlying
  358. output stream reports an error).]]
  359. [[`big_word(w)`] [Output the binary representation of the least
  360. significant 16 bits of the immediate parameter
  361. in big endian representation. This generator
  362. never fails (unless the underlying output stream
  363. reports an error).]]
  364. [[`big_dword(dw)`] [Output the binary representation of the least
  365. significant 32 bits of the immediate parameter
  366. in big endian representation. This generator
  367. never fails (unless the underlying output stream
  368. reports an error).]]
  369. [[`big_qword(qw)`] [Output the binary representation of the least
  370. significant 64 bits of the immediate parameter
  371. in big endian representation. This generator
  372. never fails (unless the underlying output stream
  373. reports an error).]]
  374. [[`big_bin_float(f)`] [Output the binary representation of the immediate
  375. float parameter in big endian representation.
  376. This generator never fails (unless the underlying
  377. output stream reports an error).]]
  378. [[`big_bin_double(d)`] [Output the binary representation of the immediate
  379. double parameter in big endian representation.
  380. This generator never fails (unless the underlying
  381. output stream reports an error).]]
  382. ]
  383. [heading Attributes]
  384. [table
  385. [[Expression] [Attribute]]
  386. [[`big_word`] [`boost::uint_least16_t`, attribute is mandatory
  387. (otherwise compilation will fail)]]
  388. [[`big_dword`] [`boost::uint_least32_t`, attribute is mandatory
  389. (otherwise compilation will fail)]]
  390. [[`big_qword`] [`boost::uint_least64_t`, attribute is mandatory
  391. (otherwise compilation will fail)]]
  392. [[`big_bin_float`] [`float`, attribute is mandatory
  393. (otherwise compilation will fail)]]
  394. [[`big_bin_double`] [`double`, attribute is mandatory
  395. (otherwise compilation will fail)]]
  396. [[`big_word(w)`] [__unused__]]
  397. [[`big_dword(dw)`] [__unused__]]
  398. [[`big_qword(qw)`] [__unused__]]
  399. [[`big_bin_float(f)`] [__unused__]]
  400. [[`big_bin_double(d)`] [__unused__]]
  401. ]
  402. [heading Complexity]
  403. [:O(N), where N is the number of bytes emitted by the binary generator]
  404. [heading Example]
  405. [note The test harness for the example(s) below is presented in the
  406. __karma_basics_examples__ section.]
  407. Some includes:
  408. [reference_karma_includes]
  409. Some using declarations:
  410. [reference_karma_using_declarations_big_binary]
  411. Basic usage of the big binary generators:
  412. [reference_karma_big_binary]
  413. [endsect]
  414. [endsect]