• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //  Copyright (c) 2001-2010 Hartmut Kaiser
2 //
3 //  Distributed under the Boost Software License, Version 1.0. (See accompanying
4 //  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5 
6 //  The purpose of this example is to show how a simple custom generator
7 //  directive can be written. We develop a custom generator allowing to wrap
8 //  the generated output after each 5th column.
9 //
10 //  For more information see: http://boost-spirit.com/home/?page_id=659
11 
12 #include <boost/spirit/include/karma_generate_attr.hpp>
13 #include <boost/spirit/include/karma_char.hpp>
14 #include <boost/spirit/include/karma_operator.hpp>
15 #include <boost/spirit/include/karma_numeric.hpp>
16 
17 #include <string>
18 #include "simple_columns_directive.hpp"
19 
20 namespace karma = boost::spirit::karma;
21 
main()22 int main()
23 {
24     using custom_generator::columns;
25 
26     std::vector<int> v;
27     for (int i = 0; i < 17; ++i)
28         v.push_back(i);
29 
30     std::string generated;
31     std::back_insert_iterator<std::string> sink(generated);
32 
33     bool result = karma::generate_delimited(
34         sink, columns[*karma::int_], karma::space, v);
35     if (result)
36     {
37         std::cout << "-------------------------------- \n";
38         std::cout << "Generation succeeded\n";
39         std::cout << "generated output: " << "\n" << generated << "\n";
40         std::cout << "-------------------------------- \n";
41     }
42     else
43     {
44         std::cout << "-------------------------------- \n";
45         std::cout << "Generation failed\n";
46         std::cout << "-------------------------------- \n";
47     }
48     return 0;
49 }
50