1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240
|
///////////////////////////////////////////////////////////////////////////////
// transmogrify.hpp
//
// 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)
#ifndef BOOST_XPRESSIVE_DETAIL_STATIC_TRANSMOGRIFY_HPP_EAN_10_04_2005
#define BOOST_XPRESSIVE_DETAIL_STATIC_TRANSMOGRIFY_HPP_EAN_10_04_2005
// MS compatible compilers support #pragma once
#if defined(_MSC_VER)
# pragma once
#endif
#include <cstring> // for std::strlen
#include <boost/mpl/if.hpp>
#include <boost/mpl/or.hpp>
#include <boost/mpl/bool.hpp>
#include <boost/mpl/assert.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/xpressive/detail/detail_fwd.hpp>
#include <boost/xpressive/detail/core/matchers.hpp>
#include <boost/xpressive/detail/static/placeholders.hpp>
#include <boost/xpressive/detail/utility/dont_care.hpp>
#include <boost/xpressive/detail/utility/traits_utils.hpp>
namespace boost { namespace xpressive { namespace detail
{
template<typename T, typename Char>
struct is_char_literal
: mpl::or_<is_same<T, Char>, is_same<T, char> >
{};
///////////////////////////////////////////////////////////////////////////////
// transmogrify
//
template<typename BidiIter, typename ICase, typename Traits, typename Matcher, typename EnableIf = void>
struct default_transmogrify
{
typedef typename Traits::char_type char_type;
typedef typename Traits::string_type string_type;
typedef typename mpl::if_c
<
is_char_literal<Matcher, char_type>::value
, literal_matcher<Traits, ICase, mpl::false_>
, string_matcher<Traits, ICase>
>::type type;
template<typename Matcher2, typename Visitor>
static type call(Matcher2 const &m, Visitor &visitor)
{
return default_transmogrify::call_(m, visitor, is_char_literal<Matcher2, char_type>());
}
template<typename Matcher2, typename Visitor>
static type call_(Matcher2 const &m, Visitor &visitor, mpl::true_)
{
char_type ch = char_cast<char_type>(m, visitor.traits());
return type(ch, visitor.traits());
}
template<typename Matcher2, typename Visitor>
static type call_(Matcher2 const &m, Visitor &visitor, mpl::false_)
{
string_type str = string_cast<string_type>(m, visitor.traits());
return type(str, visitor.traits());
}
};
template<typename BidiIter, typename ICase, typename Traits, typename Matcher>
struct default_transmogrify<BidiIter, ICase, Traits, Matcher, typename Matcher::is_boost_xpressive_xpression_>
{
typedef Matcher type;
template<typename Matcher2>
static Matcher2 const &call(Matcher2 const &m, dont_care)
{
return m;
}
};
template<typename BidiIter, typename ICase, typename Traits, typename Matcher>
struct transmogrify
: default_transmogrify<BidiIter, ICase, Traits, Matcher>
{};
template<typename BidiIter, typename ICase, typename Traits>
struct transmogrify<BidiIter, ICase, Traits, assert_bol_placeholder >
{
typedef assert_bol_matcher<Traits> type;
template<typename Matcher2, typename Visitor>
static type call(Matcher2, Visitor &visitor)
{
return type(visitor.traits());
}
};
template<typename BidiIter, typename ICase, typename Traits>
struct transmogrify<BidiIter, ICase, Traits, assert_eol_placeholder >
{
typedef assert_eol_matcher<Traits> type;
template<typename Matcher2, typename Visitor>
static type call(Matcher2, Visitor &visitor)
{
return type(visitor.traits());
}
};
template<typename BidiIter, typename ICase, typename Traits>
struct transmogrify<BidiIter, ICase, Traits, logical_newline_placeholder >
{
typedef logical_newline_matcher<Traits> type;
template<typename Matcher2, typename Visitor>
static type call(Matcher2, Visitor &visitor)
{
return type(visitor.traits());
}
};
template<typename BidiIter, typename ICase, typename Traits, typename Char>
struct transmogrify<BidiIter, ICase, Traits, range_placeholder<Char> >
{
// By design, we don't widen character ranges.
typedef typename iterator_value<BidiIter>::type char_type;
BOOST_MPL_ASSERT((is_same<Char, char_type>));
typedef range_matcher<Traits, ICase> type;
template<typename Matcher2, typename Visitor>
static type call(Matcher2 const &m, Visitor &visitor)
{
return type(m.ch_min_, m.ch_max_, m.not_, visitor.traits());
}
};
template<typename BidiIter, typename ICase, typename Traits>
struct transmogrify<BidiIter, ICase, Traits, mark_placeholder >
{
typedef mark_matcher<Traits, ICase> type;
template<typename Matcher2, typename Visitor>
static type call(Matcher2 const &m, Visitor &visitor)
{
return type(m.mark_number_, visitor.traits());
}
};
template<typename BidiIter, typename ICase, typename Traits>
struct transmogrify<BidiIter, ICase, Traits, posix_charset_placeholder >
{
typedef posix_charset_matcher<Traits> type;
template<typename Matcher2, typename Visitor>
static type call(Matcher2 const &m, Visitor &visitor)
{
char const *name_end = m.name_ + std::strlen(m.name_);
return type(visitor.traits().lookup_classname(m.name_, name_end, ICase::value), m.not_);
}
};
template<typename BidiIter, typename Traits, typename Size>
struct transmogrify<BidiIter, mpl::true_, Traits, set_matcher<Traits, Size> >
{
typedef set_matcher<Traits, Size> type;
template<typename Matcher2, typename Visitor>
static type call(Matcher2 m, Visitor &visitor)
{
m.nocase(visitor.traits());
return m;
}
};
template<typename BidiIter, typename ICase, typename Traits, typename Cond>
struct transmogrify<BidiIter, ICase, Traits, assert_word_placeholder<Cond> >
{
typedef assert_word_matcher<Cond, Traits> type;
template<typename Visitor>
static type call(dont_care, Visitor &visitor)
{
return type(visitor.traits());
}
};
template<typename BidiIter, typename ICase, typename Traits>
struct transmogrify<BidiIter, ICase, Traits, reference_wrapper<basic_regex<BidiIter> > >
{
typedef regex_byref_matcher<BidiIter> type;
template<typename Matcher2>
static type call(Matcher2 const &m, dont_care)
{
return type(detail::core_access<BidiIter>::get_regex_impl(m.get()));
}
};
template<typename BidiIter, typename ICase, typename Traits>
struct transmogrify<BidiIter, ICase, Traits, reference_wrapper<basic_regex<BidiIter> const> >
{
typedef regex_byref_matcher<BidiIter> type;
template<typename Matcher2>
static type call(Matcher2 const &m, dont_care)
{
return type(detail::core_access<BidiIter>::get_regex_impl(m.get()));
}
};
template<typename BidiIter, typename ICase, typename Traits>
struct transmogrify<BidiIter, ICase, Traits, tracking_ptr<regex_impl<BidiIter> > >
{
typedef regex_matcher<BidiIter> type;
template<typename Matcher2>
static type call(Matcher2 const &m, dont_care)
{
return type(m.get());
}
};
template<typename BidiIter, typename ICase, typename Traits>
struct transmogrify<BidiIter, ICase, Traits, self_placeholder >
{
typedef regex_byref_matcher<BidiIter> type;
template<typename Matcher2, typename Visitor>
static type call(Matcher2, Visitor &visitor)
{
return type(visitor.self());
}
};
}}}
#endif
|