spirit_qi.hpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Copyright Andrey Semashev 2007 - 2013.
  3. * Distributed under the Boost Software License, Version 1.0.
  4. * (See accompanying file LICENSE_1_0.txt or copy at
  5. * http://www.boost.org/LICENSE_1_0.txt)
  6. */
  7. /*!
  8. * \file support/spirit_qi.hpp
  9. * \author Andrey Semashev
  10. * \date 19.07.2009
  11. *
  12. * This header enables Boost.Spirit.Qi support for Boost.Log.
  13. */
  14. #ifndef BOOST_LOG_SUPPORT_SPIRIT_QI_HPP_INCLUDED_
  15. #define BOOST_LOG_SUPPORT_SPIRIT_QI_HPP_INCLUDED_
  16. #include <boost/log/detail/config.hpp>
  17. #include <boost/log/utility/functional/matches.hpp>
  18. #include <boost/spirit/include/qi_parse.hpp>
  19. #include <boost/spirit/include/qi_domain.hpp>
  20. #include <boost/spirit/include/support_component.hpp>
  21. #include <boost/log/detail/header.hpp>
  22. #ifdef BOOST_HAS_PRAGMA_ONCE
  23. #pragma once
  24. #endif
  25. namespace boost {
  26. BOOST_LOG_OPEN_NAMESPACE
  27. namespace aux {
  28. //! The trait verifies if the type can be converted to a Boost.Spirit.Qi parser
  29. template< typename T >
  30. struct is_spirit_qi_parser< T, true > :
  31. public spirit::traits::is_component< spirit::qi::domain, T >
  32. {
  33. };
  34. //! The matching functor implementation
  35. template< >
  36. struct matches_fun_impl< boost_spirit_qi_expression_tag >
  37. {
  38. template< typename StringT, typename ParserT >
  39. static bool matches(
  40. StringT const& str,
  41. ParserT const& expr)
  42. {
  43. typedef typename StringT::const_iterator const_iterator;
  44. const_iterator it = str.begin(), end = str.end();
  45. return (spirit::qi::parse(it, end, expr) && it == end);
  46. }
  47. };
  48. } // namespace aux
  49. BOOST_LOG_CLOSE_NAMESPACE // namespace log
  50. } // namespace boost
  51. #include <boost/log/detail/footer.hpp>
  52. #endif // BOOST_LOG_SUPPORT_SPIRIT_QI_HPP_INCLUDED_