actions.hpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. #ifndef ACTIONS_H
  5. #define ACTIONS_H
  6. #include <boost/spirit/include/phoenix1.hpp>
  7. #include <boost/variant.hpp>
  8. #include "tag.hpp"
  9. struct push_child_impl
  10. {
  11. template <class T,class A>
  12. struct result {typedef void type;};
  13. template <class T,class A>
  14. void operator () (T &list, const A &value) const
  15. {
  16. typename tag::variant_type p(value);
  17. list.push_back(p);
  18. }
  19. };
  20. struct store_in_map_impl
  21. {
  22. template <class T,class A>
  23. struct result{typedef void type;};
  24. template <class T,class A>
  25. void operator () (T &map,const A &value)const
  26. {
  27. typedef typename T::value_type value_type;
  28. map.insert(value_type(value));
  29. }
  30. };
  31. struct push_back_impl
  32. {
  33. template <class T,class A>
  34. struct result {typedef void type;};
  35. template <class T,class A>
  36. void operator () (T &list,const A &value)const
  37. {
  38. list.push_back(value);
  39. }
  40. };
  41. struct store_tag_impl
  42. {
  43. template <class T,class A,class B,class C>
  44. struct result {typedef void type;};
  45. template <class T,class A,class B,class C>
  46. void operator ()(T &t,const A &a,const B &b,const C &c)const
  47. {
  48. t.id = a;
  49. t.attributes = b;
  50. t.children = c;
  51. }
  52. };
  53. typedef phoenix::function<push_back_impl> push_back_f;
  54. typedef phoenix::function<store_in_map_impl>store_in_map_f;
  55. typedef phoenix::function<push_child_impl> push_child_f;
  56. typedef phoenix::function<store_tag_impl> store_tag_f;
  57. #endif