blob: e991bb6e6671c3f24d731f9f50a10f867879203a [file] [log] [blame]
Jeff Thompson86b6d642013-10-17 15:01:56 -07001/*
2 *
3 * Copyright (c) 2003
4 * John Maddock
5 *
6 * Use, modification and distribution are subject to the
7 * Boost Software License, Version 1.0. (See accompanying file
8 * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 *
10 */
11
12 /*
13 * LOCATION: see http://www.boost.org for most recent version.
14 * FILE regex_traits.hpp
15 * VERSION see <ndnboost/version.hpp>
16 * DESCRIPTION: Declares regular expression traits classes.
17 */
18
19#ifndef NDNBOOST_REGEX_TRAITS_HPP_INCLUDED
20#define NDNBOOST_REGEX_TRAITS_HPP_INCLUDED
21
22#ifndef NDNBOOST_REGEX_CONFIG_HPP
23#include <ndnboost/regex/config.hpp>
24#endif
25#ifndef NDNBOOST_REGEX_WORKAROUND_HPP
26#include <ndnboost/regex/v4/regex_workaround.hpp>
27#endif
28#ifndef NDNBOOST_REGEX_SYNTAX_TYPE_HPP
29#include <ndnboost/regex/v4/syntax_type.hpp>
30#endif
31#ifndef NDNBOOST_REGEX_ERROR_TYPE_HPP
32#include <ndnboost/regex/v4/error_type.hpp>
33#endif
34#ifndef NDNBOOST_REGEX_TRAITS_DEFAULTS_HPP_INCLUDED
35#include <ndnboost/regex/v4/regex_traits_defaults.hpp>
36#endif
37#ifndef NDNBOOST_NO_STD_LOCALE
38# ifndef NDNBOOST_CPP_REGEX_TRAITS_HPP_INCLUDED
39# include <ndnboost/regex/v4/cpp_regex_traits.hpp>
40# endif
41#endif
42#if !NDNBOOST_WORKAROUND(__BORLANDC__, < 0x560)
43# ifndef NDNBOOST_C_REGEX_TRAITS_HPP_INCLUDED
44# include <ndnboost/regex/v4/c_regex_traits.hpp>
45# endif
46#endif
47#if defined(_WIN32) && !defined(NDNBOOST_REGEX_NO_W32)
48# ifndef NDNBOOST_W32_REGEX_TRAITS_HPP_INCLUDED
49# include <ndnboost/regex/v4/w32_regex_traits.hpp>
50# endif
51#endif
52#ifndef NDNBOOST_REGEX_FWD_HPP_INCLUDED
53#include <ndnboost/regex_fwd.hpp>
54#endif
55
56#include "ndnboost/mpl/has_xxx.hpp"
57#include <ndnboost/static_assert.hpp>
58
59#ifdef NDNBOOST_MSVC
60#pragma warning(push)
61#pragma warning(disable: 4103)
62#endif
63#ifdef NDNBOOST_HAS_ABI_HEADERS
64# include NDNBOOST_ABI_PREFIX
65#endif
66#ifdef NDNBOOST_MSVC
67#pragma warning(pop)
68#endif
69
70namespace ndnboost{
71
72template <class charT, class implementationT >
73struct regex_traits : public implementationT
74{
75 regex_traits() : implementationT() {}
76};
77
78//
79// class regex_traits_wrapper.
80// this is what our implementation will actually store;
81// it provides default implementations of the "optional"
82// interfaces that we support, in addition to the
83// required "standard" ones:
84//
85namespace re_detail{
86#if !defined(NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !NDNBOOST_WORKAROUND(__HP_aCC, < 60000)
87NDNBOOST_MPL_HAS_XXX_TRAIT_DEF(boost_extensions_tag)
88#else
89template<class T>
90struct has_boost_extensions_tag
91{
92 NDNBOOST_STATIC_CONSTANT(bool, value = false);
93};
94#endif
95
96template <class BaseT>
97struct default_wrapper : public BaseT
98{
99 typedef typename BaseT::char_type char_type;
100 std::string error_string(::ndnboost::regex_constants::error_type e)const
101 {
102 return ::ndnboost::re_detail::get_default_error_string(e);
103 }
104 ::ndnboost::regex_constants::syntax_type syntax_type(char_type c)const
105 {
106 return ((c & 0x7f) == c) ? get_default_syntax_type(static_cast<char>(c)) : ::ndnboost::regex_constants::syntax_char;
107 }
108 ::ndnboost::regex_constants::escape_syntax_type escape_syntax_type(char_type c)const
109 {
110 return ((c & 0x7f) == c) ? get_default_escape_syntax_type(static_cast<char>(c)) : ::ndnboost::regex_constants::escape_type_identity;
111 }
112 int toi(const char_type*& p1, const char_type* p2, int radix)const
113 {
114 return ::ndnboost::re_detail::global_toi(p1, p2, radix, *this);
115 }
116 char_type translate(char_type c, bool icase)const
117 {
118 return (icase ? this->translate_nocase(c) : this->translate(c));
119 }
120 char_type translate(char_type c)const
121 {
122 return BaseT::translate(c);
123 }
124 char_type tolower(char_type c)const
125 {
126 return ::ndnboost::re_detail::global_lower(c);
127 }
128 char_type toupper(char_type c)const
129 {
130 return ::ndnboost::re_detail::global_upper(c);
131 }
132};
133
134template <class BaseT, bool has_extensions>
135struct compute_wrapper_base
136{
137 typedef BaseT type;
138};
139#if !defined(NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !NDNBOOST_WORKAROUND(__HP_aCC, < 60000)
140template <class BaseT>
141struct compute_wrapper_base<BaseT, false>
142{
143 typedef default_wrapper<BaseT> type;
144};
145#else
146template <>
147struct compute_wrapper_base<c_regex_traits<char>, false>
148{
149 typedef default_wrapper<c_regex_traits<char> > type;
150};
151#ifndef NDNBOOST_NO_WREGEX
152template <>
153struct compute_wrapper_base<c_regex_traits<wchar_t>, false>
154{
155 typedef default_wrapper<c_regex_traits<wchar_t> > type;
156};
157#endif
158#endif
159
160} // namespace re_detail
161
162template <class BaseT>
163struct regex_traits_wrapper
164 : public ::ndnboost::re_detail::compute_wrapper_base<
165 BaseT,
166 ::ndnboost::re_detail::has_boost_extensions_tag<BaseT>::value
167 >::type
168{
169 regex_traits_wrapper(){}
170private:
171 regex_traits_wrapper(const regex_traits_wrapper&);
172 regex_traits_wrapper& operator=(const regex_traits_wrapper&);
173};
174
175} // namespace ndnboost
176
177#ifdef NDNBOOST_MSVC
178#pragma warning(push)
179#pragma warning(disable: 4103)
180#endif
181#ifdef NDNBOOST_HAS_ABI_HEADERS
182# include NDNBOOST_ABI_SUFFIX
183#endif
184#ifdef NDNBOOST_MSVC
185#pragma warning(pop)
186#endif
187
188#endif // include
189