Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-31 10:01:58

0001 /*=============================================================================
0002     Copyright (c) 2002-2003 Joel de Guzman
0003     Copyright (c) 2002-2003 Hartmut Kaiser
0004     http://spirit.sourceforge.net/
0005 
0006   Distributed under the Boost Software License, Version 1.0. (See accompanying
0007   file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0008 =============================================================================*/
0009 #if !defined(BOOST_SPIRIT_AS_PARSER_HPP)
0010 #define BOOST_SPIRIT_AS_PARSER_HPP
0011 
0012 #include <boost/spirit/home/classic/namespace.hpp>
0013 #include <boost/spirit/home/classic/core/primitives/primitives.hpp>
0014 
0015 namespace boost { namespace spirit {
0016 
0017 BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
0018 
0019     ///////////////////////////////////////////////////////////////////////////
0020     //
0021     //  Helper templates to derive the parser type from an auxiliary type
0022     //  and to generate an object of the required parser type given an
0023     //  auxiliary object. Supported types to convert are parsers,
0024     //  single characters and character strings.
0025     //
0026     ///////////////////////////////////////////////////////////////////////////
0027     namespace impl
0028     {
0029         template<typename T>
0030         struct default_as_parser
0031         {
0032             typedef T type;
0033             static type const& convert(type const& p)
0034             {
0035                 return p;
0036             }
0037         };
0038 
0039         struct char_as_parser
0040         {
0041             typedef chlit<char> type;
0042             static type convert(char ch)
0043             {
0044                 return type(ch);
0045             }
0046         };
0047 
0048         struct wchar_as_parser
0049         {
0050             typedef chlit<wchar_t> type;
0051             static type convert(wchar_t ch)
0052             {
0053                 return type(ch);
0054             }
0055         };
0056 
0057         struct string_as_parser
0058         {
0059             typedef strlit<char const*> type;
0060             static type convert(char const* str)
0061             {
0062                 return type(str);
0063             }
0064         };
0065 
0066         struct wstring_as_parser
0067         {
0068             typedef strlit<wchar_t const*> type;
0069             static type convert(wchar_t const* str)
0070             {
0071                 return type(str);
0072             }
0073         };
0074     }
0075 
0076     template<typename T>
0077     struct as_parser : impl::default_as_parser<T> {};
0078 
0079     template<>
0080     struct as_parser<char> : impl::char_as_parser {};
0081 
0082     template<>
0083     struct as_parser<wchar_t> : impl::wchar_as_parser {};
0084 
0085     template<>
0086     struct as_parser<char*> : impl::string_as_parser {};
0087 
0088     template<>
0089     struct as_parser<char const*> : impl::string_as_parser {};
0090 
0091     template<>
0092     struct as_parser<wchar_t*> : impl::wstring_as_parser {};
0093 
0094     template<>
0095     struct as_parser<wchar_t const*> : impl::wstring_as_parser {};
0096 
0097     template<int N>
0098     struct as_parser<char[N]> : impl::string_as_parser {};
0099 
0100     template<int N>
0101     struct as_parser<wchar_t[N]> : impl::wstring_as_parser {};
0102 
0103     template<int N>
0104     struct as_parser<char const[N]> : impl::string_as_parser {};
0105 
0106     template<int N>
0107     struct as_parser<wchar_t const[N]> : impl::wstring_as_parser {};
0108 
0109 BOOST_SPIRIT_CLASSIC_NAMESPACE_END
0110 
0111 }} // namespace BOOST_SPIRIT_CLASSIC_NS
0112 
0113 #endif