tutorial_intro.qbk 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. [/==============================================================================
  2. Copyright (C) 2001-2011 Joel de Guzman
  3. Copyright (C) 2001-2011 Hartmut Kaiser
  4. Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. ===============================================================================/]
  7. [section Quick Start]
  8. [heading Spirit.Karma - what's that?]
  9. Throughout the description of __karma__ we will try to align ourselves very
  10. much with the documentation for __qi__. The reasons are many fold:
  11. * __karma__ is the counterpart to __qi__. Some people say it's the Yin to
  12. __qi__'s Yang. __karma__ is generating byte sequences from internal data
  13. structures as __qi__ is parsing byte sequences into those (very same) internal
  14. data structures.
  15. * Both libraries have an almost identical structure, very similar semantics,
  16. and are both built using identical tools. Both libraries implement a language
  17. casting the specifics of their domain (parsing and generating) into a simple
  18. interface.
  19. Why should you use a generator library for such a simple thing as output
  20. generation? Programmers have been using `printf`, `std::stream` formatting, or
  21. `boost::format` for quite some time. The answer is - yes, for simple output
  22. formatting tasks those familiar tools might be a quick solution. But experience
  23. shows: as soon as the formatting requirements are becoming more complex output
  24. generation is getting more and more challenging in terms of readability,
  25. maintainability, and flexibility of the code. Last, but not least, it turns out
  26. that code using __karma__ runs much faster than equivalent code using either
  27. of the 'straight' methods mentioned above (see here for some numbers:
  28. __sec_karma_numeric_performance__)
  29. You might argue that more complex tasks require more complex tools. But this
  30. turns out not to be the case! The whole Spirit library is designed to be simple
  31. to use, while being scalable from trivial to very complicated applications.
  32. In terms of development simplicity and ease in deployment, the same is true for
  33. __karma__ as has been described elsewhere in this documentation for __qi__: the
  34. entire library consists of only header files, with no libraries to link against
  35. or build. Just put the spirit distribution in your include path, compile and
  36. run. Code size? Very tight, essentially comparable to hand written code.
  37. The __karma__ tutorials are built in a walk through style, starting with
  38. elementary things growing step by step in complexity. And again: keep in mind
  39. output generation is the exact opposite of parsing. Everything you already
  40. learnt about parsing using __qi__ is applicable to generating formatted output
  41. using __karma__. All you have to do is to look at __karma__ as being a
  42. mirror image of __qi__.
  43. [endsect] [/Quick Start]