// Copyright (c) 2001-2010 Hartmut Kaiser // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #if !defined(BOOST_SPIRIT_KARMA_META_CREATE_NOV_21_2009_0425PM) #define BOOST_SPIRIT_KARMA_META_CREATE_NOV_21_2009_0425PM #if defined(_MSC_VER) #pragma once #endif #include #include #include #include #include #include #include #include #include #include #include #include #include /////////////////////////////////////////////////////////////////////////////// namespace boost { namespace spirit { namespace karma { /////////////////////////////////////////////////////////////////////////// // compatible STL containers template struct meta_create_container { typedef make_unary_proto_expr< typename Container::value_type , proto::tag::dereference, karma::domain > make_proto_expr; typedef typename make_proto_expr::type type; static type call() { return make_proto_expr::call(); } }; /////////////////////////////////////////////////////////////////////////// // String types template struct meta_create_string { typedef spirit::standard::string_type type; static type const& call() { return spirit::standard::string; } }; template <> struct meta_create_string { typedef spirit::standard_wide::string_type type; static type const& call() { return spirit::standard_wide::string; } }; template <> struct meta_create_string { typedef spirit::standard_wide::string_type type; static type const& call() { return spirit::standard_wide::string; } }; template struct meta_create_string { typedef spirit::standard_wide::string_type type; static type const& call() { return spirit::standard_wide::string; } }; template struct meta_create_string { typedef spirit::standard_wide::string_type type; static type const& call() { return spirit::standard_wide::string; } }; template struct meta_create_string { typedef spirit::standard_wide::string_type type; static type const& call() { return spirit::standard_wide::string; } }; template struct meta_create_string { typedef spirit::standard_wide::string_type type; static type const& call() { return spirit::standard_wide::string; } }; template struct meta_create_string > { typedef spirit::standard_wide::string_type type; static type const& call() { return spirit::standard_wide::string; } }; /////////////////////////////////////////////////////////////////////////// // Fusion sequences template struct meta_create_sequence { // create a mpl sequence from the given fusion sequence typedef typename mpl::fold< typename fusion::result_of::as_vector::type , mpl::vector<>, mpl::push_back >::type sequence_type; typedef make_nary_proto_expr< sequence_type, proto::tag::shift_left, karma::domain > make_proto_expr; typedef typename make_proto_expr::type type; static type call() { return make_proto_expr::call(); } }; /////////////////////////////////////////////////////////////////////////// // the default is to use the standard streaming operator unless it's a // STL container or a fusion sequence // The default implementation will be chosen if no predefined mapping of // the data type T to a Karma component is defined. struct no_auto_mapping_exists {}; template struct meta_create_impl : mpl::identity {}; template struct meta_create_impl , mpl::not_ > , mpl::not_ > > >::type> : meta_create_container {}; template struct meta_create_impl >::type> : meta_create_string {}; template struct meta_create_impl >::type> : meta_create_sequence {}; template struct meta_create : meta_create_impl {}; /////////////////////////////////////////////////////////////////////////// // optional template struct meta_create > { typedef make_unary_proto_expr< T, proto::tag::negate, karma::domain > make_proto_expr; typedef typename make_proto_expr::type type; static type call() { return make_proto_expr::call(); } }; /////////////////////////////////////////////////////////////////////////// // alternatives template struct meta_create > { typedef make_nary_proto_expr< typename boost::variant::types , proto::tag::bitwise_or, karma::domain > make_proto_expr; typedef typename make_proto_expr::type type; static type call() { return make_proto_expr::call(); } }; /////////////////////////////////////////////////////////////////////////// // predefined specializations for primitive components // character generator template <> struct meta_create { typedef spirit::standard::char_type type; static type const& call() { return spirit::standard::char_; } }; template <> struct meta_create { typedef spirit::standard::char_type type; static type const& call() { return spirit::standard::char_; } }; template <> struct meta_create { typedef spirit::standard_wide::char_type type; static type const& call() { return spirit::standard_wide::char_; } }; template <> struct meta_create { typedef spirit::standard::char_type type; static type const& call() { return spirit::standard::char_; } }; // boolean generator template <> struct meta_create { typedef spirit::bool__type type; static type const& call() { return spirit::bool_; } }; // integral generators template <> struct meta_create { typedef spirit::int__type type; static type const& call() { return spirit::int_; } }; template <> struct meta_create { typedef spirit::short__type type; static type const& call() { return spirit::short_; } }; template <> struct meta_create { typedef spirit::long__type type; static type const& call() { return spirit::long_; } }; template <> struct meta_create { typedef spirit::uint__type type; static type const& call() { return spirit::uint_; } }; #if !defined(BOOST_NO_INTRINSIC_WCHAR_T) template <> struct meta_create { typedef spirit::ushort__type type; static type const& call() { return spirit::ushort_; } }; #endif template <> struct meta_create { typedef spirit::ulong__type type; static type const& call() { return spirit::ulong_; } }; #ifdef BOOST_HAS_LONG_LONG template <> struct meta_create { typedef spirit::long_long_type type; static type const& call() { return spirit::long_long; } }; template <> struct meta_create { typedef spirit::ulong_long_type type; static type const& call() { return spirit::ulong_long; } }; #endif // floating point generators template <> struct meta_create { typedef spirit::float__type type; static type const& call() { return spirit::float_; } }; template <> struct meta_create { typedef spirit::double__type type; static type const& call() { return spirit::double_; } }; template <> struct meta_create { typedef spirit::long_double_type type; static type const& call() { return spirit::long_double; } }; }}} /////////////////////////////////////////////////////////////////////////////// namespace boost { namespace spirit { namespace traits { /////////////////////////////////////////////////////////////////////////// // main customization point for create_generator template struct create_generator : karma::meta_create {}; /////////////////////////////////////////////////////////////////////////// // dispatch this to the karma related specializations template struct meta_create : create_generator::type> {}; /////////////////////////////////////////////////////////////////////////// // Check whether a valid mapping exits for the given data type to a Karma // component template struct meta_create_exists : mpl::not_::type > > {}; }}} #endif