Chris@16: /*============================================================================= Chris@16: Copyright (c) 2002-2003 Joel de Guzman Chris@16: Copyright (c) 2002-2003 Hartmut Kaiser Chris@16: http://spirit.sourceforge.net/ Chris@16: Chris@16: Distributed under the Boost Software License, Version 1.0. (See accompanying Chris@16: file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: =============================================================================*/ Chris@16: #if !defined(BOOST_SPIRIT_AS_PARSER_HPP) Chris@16: #define BOOST_SPIRIT_AS_PARSER_HPP Chris@16: Chris@16: #include Chris@16: #include Chris@16: Chris@16: namespace boost { namespace spirit { Chris@16: Chris@16: BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////// Chris@16: // Chris@16: // Helper templates to derive the parser type from an auxilliary type Chris@16: // and to generate an object of the required parser type given an Chris@16: // auxilliary object. Supported types to convert are parsers, Chris@16: // single characters and character strings. Chris@16: // Chris@16: /////////////////////////////////////////////////////////////////////////// Chris@16: namespace impl Chris@16: { Chris@16: template Chris@16: struct default_as_parser Chris@16: { Chris@16: typedef T type; Chris@16: static type const& convert(type const& p) Chris@16: { Chris@16: return p; Chris@16: } Chris@16: }; Chris@16: Chris@16: struct char_as_parser Chris@16: { Chris@16: typedef chlit type; Chris@16: static type convert(char ch) Chris@16: { Chris@16: return type(ch); Chris@16: } Chris@16: }; Chris@16: Chris@16: struct wchar_as_parser Chris@16: { Chris@16: typedef chlit type; Chris@16: static type convert(wchar_t ch) Chris@16: { Chris@16: return type(ch); Chris@16: } Chris@16: }; Chris@16: Chris@16: struct string_as_parser Chris@16: { Chris@16: typedef strlit type; Chris@16: static type convert(char const* str) Chris@16: { Chris@16: return type(str); Chris@16: } Chris@16: }; Chris@16: Chris@16: struct wstring_as_parser Chris@16: { Chris@16: typedef strlit type; Chris@16: static type convert(wchar_t const* str) Chris@16: { Chris@16: return type(str); Chris@16: } Chris@16: }; Chris@16: } Chris@16: Chris@16: template Chris@16: struct as_parser : impl::default_as_parser {}; Chris@16: Chris@16: template<> Chris@16: struct as_parser : impl::char_as_parser {}; Chris@16: Chris@16: template<> Chris@16: struct as_parser : impl::wchar_as_parser {}; Chris@16: Chris@16: template<> Chris@16: struct as_parser : impl::string_as_parser {}; Chris@16: Chris@16: template<> Chris@16: struct as_parser : impl::string_as_parser {}; Chris@16: Chris@16: template<> Chris@16: struct as_parser : impl::wstring_as_parser {}; Chris@16: Chris@16: template<> Chris@16: struct as_parser : impl::wstring_as_parser {}; Chris@16: Chris@16: template Chris@16: struct as_parser : impl::string_as_parser {}; Chris@16: Chris@16: template Chris@16: struct as_parser : impl::wstring_as_parser {}; Chris@16: Chris@16: template Chris@16: struct as_parser : impl::string_as_parser {}; Chris@16: Chris@16: template Chris@16: struct as_parser : impl::wstring_as_parser {}; Chris@16: Chris@16: BOOST_SPIRIT_CLASSIC_NAMESPACE_END Chris@16: Chris@16: }} // namespace BOOST_SPIRIT_CLASSIC_NS Chris@16: Chris@16: #endif