permute_function.hpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*=============================================================================
  2. Copyright (c) 2001-2011 Joel de Guzman
  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. #ifndef BOOST_SPIRIT_QI_DETAIL_PERMUTE_FUNCTION_HPP
  7. #define BOOST_SPIRIT_QI_DETAIL_PERMUTE_FUNCTION_HPP
  8. #if defined(_MSC_VER)
  9. #pragma once
  10. #endif
  11. #include <boost/spirit/home/support/unused.hpp>
  12. #include <boost/optional.hpp>
  13. namespace boost { namespace spirit { namespace qi { namespace detail
  14. {
  15. #ifdef _MSC_VER
  16. # pragma warning(push)
  17. # pragma warning(disable: 4512) // assignment operator could not be generated.
  18. #endif
  19. template <typename Iterator, typename Context, typename Skipper>
  20. struct permute_function
  21. {
  22. permute_function(
  23. Iterator& first_, Iterator const& last_
  24. , Context& context_, Skipper const& skipper_)
  25. : first(first_)
  26. , last(last_)
  27. , context(context_)
  28. , skipper(skipper_)
  29. {
  30. }
  31. template <typename Component, typename Attribute>
  32. bool operator()(Component const& component, Attribute& attr)
  33. {
  34. // return true if the parser succeeds and the slot is not yet taken
  35. if (!*taken && component.parse(first, last, context, skipper, attr))
  36. {
  37. *taken = true;
  38. ++taken;
  39. return true;
  40. }
  41. ++taken;
  42. return false;
  43. }
  44. template <typename Component>
  45. bool operator()(Component const& component)
  46. {
  47. // return true if the parser succeeds and the slot is not yet taken
  48. if (!*taken && component.parse(first, last, context, skipper, unused))
  49. {
  50. *taken = true;
  51. ++taken;
  52. return true;
  53. }
  54. ++taken;
  55. return false;
  56. }
  57. Iterator& first;
  58. Iterator const& last;
  59. Context& context;
  60. Skipper const& skipper;
  61. bool* taken;
  62. };
  63. #ifdef _MSC_VER
  64. # pragma warning(pop)
  65. #endif
  66. }}}}
  67. #endif