#ifndef boost_mpl_string_h_included #define boost_mpl_string_h_included /////////////////////////////////////////////////////////////////////////////// // // Copyright 2008 Eric Niebler. 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) #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include // Define mpl::char_ #include #include BOOST_MPL_AUX_ADL_BARRIER_NAMESPACE_OPEN template< BOOST_MPL_AUX_NTTP_DECL(char, N) > struct char_; BOOST_MPL_AUX_ADL_BARRIER_NAMESPACE_CLOSE BOOST_MPL_AUX_ADL_BARRIER_DECL(char_) #define AUX_WRAPPER_VALUE_TYPE char #include #include namespace boost { namespace mpl { //#define BOOST_MPL_STRING_MAX_LENGTH 128 #define BOOST_MPL_STRING_MAX_LENGTH 32 #define BOOST_MPL_STRING_MAX_PARAMS BOOST_PP_DIV(BOOST_MPL_STRING_MAX_LENGTH, 4) #define BOOST_MPL_MULTICHAR_LENGTH(c) ((std::size_t)((c>0xffffff)+(c>0xffff)+(c>0xff)+1)) #define BOOST_MPL_MULTICHAR_AT(c,i) (char)((c)>>(8*(BOOST_MPL_MULTICHAR_LENGTH(c)-((std::size_t)(i))-1))) struct string_tag; struct string_iterator_tag; template struct string; template struct string_iterator; template struct sequence_tag; template struct size_impl; template<> struct size_impl { template struct apply : mpl::size_t {}; }; template struct at_impl; template<> struct at_impl { template struct apply : Sequence::template at {}; }; template struct begin_impl; template<> struct begin_impl { template struct apply { typedef string_iterator type; }; }; template struct end_impl; template<> struct end_impl { template struct apply { typedef string_iterator type; }; }; template struct push_back_impl; template<> struct push_back_impl { template struct apply; template struct apply, Value> { typedef string<(char)Value::value> type; }; #define M0(z,n,data) \ template \ struct apply, Value> \ { \ typedef string< \ BOOST_PP_ENUM_PARAMS_Z(z, BOOST_PP_DEC(n), C) \ BOOST_PP_COMMA_IF(BOOST_PP_DEC(n)) \ (BOOST_PP_CAT(C,BOOST_PP_DEC(n))>0xffffff) \ ?BOOST_PP_CAT(C,BOOST_PP_DEC(n)) \ :(BOOST_PP_CAT(C,BOOST_PP_DEC(n))<<8)|(unsigned char)Value::value \ , (BOOST_PP_CAT(C,BOOST_PP_DEC(n))>0xffffff) \ ?(char)Value::value \ :0 \ > type; \ }; BOOST_PP_REPEAT_FROM_TO(1, BOOST_PP_DEC(BOOST_MPL_STRING_MAX_PARAMS), M0, ~) #undef M0 template struct apply, Value> { BOOST_MPL_ASSERT_RELATION(BOOST_PP_CAT(C,BOOST_PP_DEC(BOOST_MPL_STRING_MAX_PARAMS)), <=, 0xffffff); typedef string< BOOST_PP_ENUM_PARAMS(BOOST_PP_DEC(BOOST_MPL_STRING_MAX_PARAMS), C) , (BOOST_PP_CAT(C,BOOST_PP_DEC(BOOST_MPL_STRING_MAX_PARAMS))<<8)|(unsigned char)Value::value > type; }; }; template struct push_front_impl; template<> struct push_front_impl { template struct apply; template struct apply, Value, 1> { typedef string<(char)Value::value> type; }; #define M0(z,n,data) \ template \ struct apply, Value, N> \ { \ typedef string< \ ((((unsigned char)Value::value)<<(N*8))|C0) \ BOOST_PP_COMMA_IF(BOOST_PP_DEC(n)) \ BOOST_PP_ENUM_SHIFTED_PARAMS_Z(z, n, C) \ > type; \ }; \ template \ struct apply, Value, 4> \ { \ typedef string< \ (char)Value::value \ BOOST_PP_ENUM_TRAILING_PARAMS_Z(z, n, C) \ > type; \ }; BOOST_PP_REPEAT_FROM_TO(1, BOOST_PP_DEC(BOOST_MPL_STRING_MAX_PARAMS), M0, ~) #undef M0 template struct apply, Value, N> { BOOST_MPL_ASSERT_RELATION(C0, <=, 0xffffff); typedef string< (((unsigned char)Value::value)<<(N*8))|C0 , BOOST_PP_ENUM_SHIFTED_PARAMS(BOOST_MPL_STRING_MAX_PARAMS, C) > type; }; }; template struct insert_range_impl; template<> struct insert_range_impl { template struct apply : copy< joint_view< iterator_range< string_iterator , Pos > , joint_view< Range , iterator_range< Pos , string_iterator > > > , back_inserter > > {}; }; template struct insert_impl; template<> struct insert_impl { template struct apply : insert_range > {}; }; template struct erase_impl; template<> struct erase_impl { template struct apply : copy< joint_view< iterator_range< string_iterator , First > , iterator_range< typename if_na::type>::type , string_iterator > > , back_inserter > > {}; }; template struct clear_impl; template<> struct clear_impl { template struct apply { typedef string<> type; }; }; template struct advance_impl; template<> struct advance_impl { template struct apply { typedef string_iterator< typename Iterator::string_type , Iterator::index + N::value > type; }; }; template struct distance_impl; template<> struct distance_impl { template struct apply { typedef mpl::long_ type; }; }; template struct string_iterator : Sequence::template at { typedef string_iterator_tag tag; typedef std::random_access_iterator_tag category; typedef Sequence string_type; static long const index = N; typedef string_iterator next; typedef string_iterator prior; }; template struct string { /// INTERNAL ONLY static unsigned int const head_ = C0; /// INTERNAL ONLY typedef string tail_; typedef string_tag tag; static std::size_t const size = BOOST_MPL_MULTICHAR_LENGTH(C0) + tail_::size; template struct at : boost::mpl::char_ {}; template struct at : tail_::template at {}; static char const c_str[]; }; template char const string::c_str[] = { #define M0(z, n, data) at::value BOOST_PP_ENUM(BOOST_MPL_STRING_MAX_LENGTH, M0, ~) #undef M0 , '\0' // to ensure the string is null-terminated }; template std::size_t const string::size; template unsigned int const string::head_; template<> struct string<> { /// INTERNAL ONLY static unsigned int const head_ = 0; /// INTERNAL ONLY typedef string tail_; typedef string_tag tag; static std::size_t const size = 0; template struct at : boost::mpl::char_<'\0'> {}; static char const c_str[]; }; char const string<>::c_str[] = {'\0'}; std::size_t const string<>::size; unsigned int const string<>::head_; }} // namespace boost #endif // !boost_mpl_string_h_included