9
3

bool_utils.hpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright (c) 2001-2011 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. #if !defined(BOOST_SPIRIT_KARMA_BOOL_UTILS_SEP_28_2009_0644PM)
  6. #define BOOST_SPIRIT_KARMA_BOOL_UTILS_SEP_28_2009_0644PM
  7. #if defined(_MSC_VER)
  8. #pragma once
  9. #endif
  10. #include <boost/spirit/home/support/char_class.hpp>
  11. #include <boost/spirit/home/support/unused.hpp>
  12. #include <boost/spirit/home/karma/detail/generate_to.hpp>
  13. #include <boost/spirit/home/karma/detail/string_generate.hpp>
  14. #include <boost/spirit/home/karma/numeric/detail/numeric_utils.hpp>
  15. #include <boost/detail/workaround.hpp>
  16. namespace boost { namespace spirit { namespace karma
  17. {
  18. ///////////////////////////////////////////////////////////////////////////
  19. //
  20. // The bool_inserter template takes care of the boolean to string
  21. // conversion. The Policies template parameter is used to allow
  22. // customization of the formatting process
  23. //
  24. ///////////////////////////////////////////////////////////////////////////
  25. template <typename T>
  26. struct bool_policies;
  27. template <typename T
  28. , typename Policies = bool_policies<T>
  29. , typename CharEncoding = unused_type
  30. , typename Tag = unused_type>
  31. struct bool_inserter
  32. {
  33. template <typename OutputIterator, typename U>
  34. static bool
  35. call (OutputIterator& sink, U b, Policies const& p = Policies())
  36. {
  37. #if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1600))
  38. p; // suppresses warning: C4100: 'p' : unreferenced formal parameter
  39. #endif
  40. return p.template call<bool_inserter>(sink, T(b), p);
  41. }
  42. ///////////////////////////////////////////////////////////////////////
  43. // This is the workhorse behind the real generator
  44. ///////////////////////////////////////////////////////////////////////
  45. template <typename OutputIterator, typename U>
  46. static bool
  47. call_n (OutputIterator& sink, U b, Policies const& p)
  48. {
  49. #if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1600))
  50. p; // suppresses warning: C4100: 'p' : unreferenced formal parameter
  51. #endif
  52. if (b)
  53. return p.template generate_true<CharEncoding, Tag>(sink, b);
  54. return p.template generate_false<CharEncoding, Tag>(sink, b);
  55. }
  56. };
  57. }}}
  58. #endif