• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //  Copyright (c) 2005 Carl Barron. Distributed under the Boost
2 //  Software License, Version 1.0. (See accompanying file
3 //  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
4 
5 #ifndef ACTIONS_H
6 #define ACTIONS_H
7 #include <boost/spirit/include/phoenix1.hpp>
8 #include <boost/variant.hpp>
9 #include "tag.hpp"
10 
11 struct push_child_impl
12 {
13     template <class T,class A>
14     struct result {typedef void type;};
15 
16     template <class T,class A>
operator ()push_child_impl17     void operator () (T &list, const A &value) const
18     {
19         typename tag::variant_type p(value);
20         list.push_back(p);
21     }
22 };
23 
24 struct store_in_map_impl
25 {
26     template <class T,class A>
27     struct result{typedef void type;};
28 
29     template <class T,class A>
operator ()store_in_map_impl30     void operator () (T &map,const A &value)const
31     {
32         typedef typename T::value_type value_type;
33         map.insert(value_type(value));
34     }
35 };
36 
37 struct push_back_impl
38 {
39     template <class T,class A>
40     struct result {typedef void type;};
41 
42     template <class T,class A>
operator ()push_back_impl43     void operator () (T &list,const A &value)const
44     {
45         list.push_back(value);
46     }
47 };
48 
49 struct store_tag_impl
50 {
51     template <class T,class A,class B,class C>
52     struct result {typedef void type;};
53 
54     template <class T,class A,class B,class C>
operator ()store_tag_impl55     void operator ()(T &t,const A &a,const B &b,const C &c)const
56     {
57         t.id = a;
58         t.attributes = b;
59         t.children = c;
60     }
61 };
62 
63 
64 typedef phoenix::function<push_back_impl>   push_back_f;
65 typedef phoenix::function<store_in_map_impl>store_in_map_f;
66 typedef phoenix::function<push_child_impl>  push_child_f;
67 typedef phoenix::function<store_tag_impl>   store_tag_f;
68 #endif
69