/src/contrib/boost/spirit/home/qi/detail/permute_function.hpp

http://pythonocc.googlecode.com/ · C++ Header · 88 lines · 69 code · 9 blank · 10 comment · 6 complexity · 9b2fbb8d9b342c5857057a08055ccc1f MD5 · raw file

  1. /*=============================================================================
  2. Copyright (c) 2001-2010 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. #if !defined(SPIRIT_PERMUTE_FUNCTION_MARCH_13_2007_1129AM)
  7. #define SPIRIT_PERMUTE_FUNCTION_MARCH_13_2007_1129AM
  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. template <typename Iterator, typename Context, typename Skipper>
  16. struct permute_function
  17. {
  18. permute_function(
  19. Iterator& first, Iterator const& last
  20. , Context& context, Skipper const& skipper)
  21. : first(first)
  22. , last(last)
  23. , context(context)
  24. , skipper(skipper)
  25. {
  26. }
  27. template <typename Component, typename Attribute>
  28. bool operator()(Component const& component, Attribute& attr)
  29. {
  30. // return true if the parser succeeds and the slot is not yet taken
  31. if (!*taken && component.parse(first, last, context, skipper, attr))
  32. {
  33. *taken = true;
  34. ++taken;
  35. return true;
  36. }
  37. ++taken;
  38. return false;
  39. }
  40. template <typename Component, typename Attribute>
  41. bool operator()(Component const& component, boost::optional<Attribute>& attr)
  42. {
  43. // return true if the parser succeeds and the slot is not yet taken
  44. Attribute val;
  45. if (!*taken && component.parse(first, last, context, skipper, val))
  46. {
  47. attr = val;
  48. *taken = true;
  49. ++taken;
  50. return true;
  51. }
  52. ++taken;
  53. return false;
  54. }
  55. template <typename Component>
  56. bool operator()(Component const& component)
  57. {
  58. // return true if the parser succeeds and the slot is not yet taken
  59. if (!*taken && component.parse(first, last, context, skipper, unused))
  60. {
  61. *taken = true;
  62. ++taken;
  63. return true;
  64. }
  65. ++taken;
  66. return false;
  67. }
  68. Iterator& first;
  69. Iterator const& last;
  70. Context& context;
  71. Skipper const& skipper;
  72. bool* taken;
  73. private:
  74. // silence MSVC warning C4512: assignment operator could not be generated
  75. permute_function& operator= (permute_function const&);
  76. };
  77. }}}}
  78. #endif