OpenCores
URL https://opencores.org/ocsvn/altor32/altor32/trunk

Subversion Repositories altor32

[/] [altor32/] [trunk/] [gcc-x64/] [or1knd-elf/] [or1knd-elf/] [include/] [c++/] [4.8.0/] [bits/] [locale_classes.tcc] - Blame information for rev 35

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 35 ultra_embe
// Locale support -*- C++ -*-
2
 
3
// Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012
4
// Free Software Foundation, Inc.
5
//
6
// This file is part of the GNU ISO C++ Library.  This library is free
7
// software; you can redistribute it and/or modify it under the
8
// terms of the GNU General Public License as published by the
9
// Free Software Foundation; either version 3, or (at your option)
10
// any later version.
11
 
12
// This library is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
// GNU General Public License for more details.
16
 
17
// Under Section 7 of GPL version 3, you are granted additional
18
// permissions described in the GCC Runtime Library Exception, version
19
// 3.1, as published by the Free Software Foundation.
20
 
21
// You should have received a copy of the GNU General Public License and
22
// a copy of the GCC Runtime Library Exception along with this program;
23
// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
24
// .
25
 
26
/** @file bits/locale_classes.tcc
27
 *  This is an internal header file, included by other library headers.
28
 *  Do not attempt to use it directly. @headername{locale}
29
 */
30
 
31
//
32
// ISO C++ 14882: 22.1  Locales
33
//
34
 
35
#ifndef _LOCALE_CLASSES_TCC
36
#define _LOCALE_CLASSES_TCC 1
37
 
38
#pragma GCC system_header
39
 
40
namespace std _GLIBCXX_VISIBILITY(default)
41
{
42
_GLIBCXX_BEGIN_NAMESPACE_VERSION
43
 
44
  template
45
    locale::
46
    locale(const locale& __other, _Facet* __f)
47
    {
48
      _M_impl = new _Impl(*__other._M_impl, 1);
49
 
50
      __try
51
        { _M_impl->_M_install_facet(&_Facet::id, __f); }
52
      __catch(...)
53
        {
54
          _M_impl->_M_remove_reference();
55
          __throw_exception_again;
56
        }
57
      delete [] _M_impl->_M_names[0];
58
      _M_impl->_M_names[0] = 0;   // Unnamed.
59
    }
60
 
61
  template
62
    locale
63
    locale::
64
    combine(const locale& __other) const
65
    {
66
      _Impl* __tmp = new _Impl(*_M_impl, 1);
67
      __try
68
        {
69
          __tmp->_M_replace_facet(__other._M_impl, &_Facet::id);
70
        }
71
      __catch(...)
72
        {
73
          __tmp->_M_remove_reference();
74
          __throw_exception_again;
75
        }
76
      return locale(__tmp);
77
    }
78
 
79
  template
80
    bool
81
    locale::
82
    operator()(const basic_string<_CharT, _Traits, _Alloc>& __s1,
83
               const basic_string<_CharT, _Traits, _Alloc>& __s2) const
84
    {
85
      typedef std::collate<_CharT> __collate_type;
86
      const __collate_type& __collate = use_facet<__collate_type>(*this);
87
      return (__collate.compare(__s1.data(), __s1.data() + __s1.length(),
88
                                __s2.data(), __s2.data() + __s2.length()) < 0);
89
    }
90
 
91
  /**
92
   *  @brief  Test for the presence of a facet.
93
   *  @ingroup locales
94
   *
95
   *  has_facet tests the locale argument for the presence of the facet type
96
   *  provided as the template parameter.  Facets derived from the facet
97
   *  parameter will also return true.
98
   *
99
   *  @tparam  _Facet  The facet type to test the presence of.
100
   *  @param  __loc  The locale to test.
101
   *  @return  true if @p __loc contains a facet of type _Facet, else false.
102
  */
103
  template
104
    bool
105
    has_facet(const locale& __loc) throw()
106
    {
107
      const size_t __i = _Facet::id._M_id();
108
      const locale::facet** __facets = __loc._M_impl->_M_facets;
109
      return (__i < __loc._M_impl->_M_facets_size
110
#ifdef __GXX_RTTI
111
              && dynamic_cast(__facets[__i]));
112
#else
113
              && static_cast(__facets[__i]));
114
#endif
115
    }
116
 
117
  /**
118
   *  @brief  Return a facet.
119
   *  @ingroup locales
120
   *
121
   *  use_facet looks for and returns a reference to a facet of type Facet
122
   *  where Facet is the template parameter.  If has_facet(locale) is true,
123
   *  there is a suitable facet to return.  It throws std::bad_cast if the
124
   *  locale doesn't contain a facet of type Facet.
125
   *
126
   *  @tparam  _Facet  The facet type to access.
127
   *  @param  __loc  The locale to use.
128
   *  @return  Reference to facet of type Facet.
129
   *  @throw  std::bad_cast if @p __loc doesn't contain a facet of type _Facet.
130
  */
131
  template
132
    const _Facet&
133
    use_facet(const locale& __loc)
134
    {
135
      const size_t __i = _Facet::id._M_id();
136
      const locale::facet** __facets = __loc._M_impl->_M_facets;
137
      if (__i >= __loc._M_impl->_M_facets_size || !__facets[__i])
138
        __throw_bad_cast();
139
#ifdef __GXX_RTTI
140
      return dynamic_cast(*__facets[__i]);
141
#else
142
      return static_cast(*__facets[__i]);
143
#endif
144
    }
145
 
146
 
147
  // Generic version does nothing.
148
  template
149
    int
150
    collate<_CharT>::_M_compare(const _CharT*, const _CharT*) const throw ()
151
    { return 0; }
152
 
153
  // Generic version does nothing.
154
  template
155
    size_t
156
    collate<_CharT>::_M_transform(_CharT*, const _CharT*, size_t) const throw ()
157
    { return 0; }
158
 
159
  template
160
    int
161
    collate<_CharT>::
162
    do_compare(const _CharT* __lo1, const _CharT* __hi1,
163
               const _CharT* __lo2, const _CharT* __hi2) const
164
    {
165
      // strcoll assumes zero-terminated strings so we make a copy
166
      // and then put a zero at the end.
167
      const string_type __one(__lo1, __hi1);
168
      const string_type __two(__lo2, __hi2);
169
 
170
      const _CharT* __p = __one.c_str();
171
      const _CharT* __pend = __one.data() + __one.length();
172
      const _CharT* __q = __two.c_str();
173
      const _CharT* __qend = __two.data() + __two.length();
174
 
175
      // strcoll stops when it sees a nul character so we break
176
      // the strings into zero-terminated substrings and pass those
177
      // to strcoll.
178
      for (;;)
179
        {
180
          const int __res = _M_compare(__p, __q);
181
          if (__res)
182
            return __res;
183
 
184
          __p += char_traits<_CharT>::length(__p);
185
          __q += char_traits<_CharT>::length(__q);
186
          if (__p == __pend && __q == __qend)
187
            return 0;
188
          else if (__p == __pend)
189
            return -1;
190
          else if (__q == __qend)
191
            return 1;
192
 
193
          __p++;
194
          __q++;
195
        }
196
    }
197
 
198
  template
199
    typename collate<_CharT>::string_type
200
    collate<_CharT>::
201
    do_transform(const _CharT* __lo, const _CharT* __hi) const
202
    {
203
      string_type __ret;
204
 
205
      // strxfrm assumes zero-terminated strings so we make a copy
206
      const string_type __str(__lo, __hi);
207
 
208
      const _CharT* __p = __str.c_str();
209
      const _CharT* __pend = __str.data() + __str.length();
210
 
211
      size_t __len = (__hi - __lo) * 2;
212
 
213
      _CharT* __c = new _CharT[__len];
214
 
215
      __try
216
        {
217
          // strxfrm stops when it sees a nul character so we break
218
          // the string into zero-terminated substrings and pass those
219
          // to strxfrm.
220
          for (;;)
221
            {
222
              // First try a buffer perhaps big enough.
223
              size_t __res = _M_transform(__c, __p, __len);
224
              // If the buffer was not large enough, try again with the
225
              // correct size.
226
              if (__res >= __len)
227
                {
228
                  __len = __res + 1;
229
                  delete [] __c, __c = 0;
230
                  __c = new _CharT[__len];
231
                  __res = _M_transform(__c, __p, __len);
232
                }
233
 
234
              __ret.append(__c, __res);
235
              __p += char_traits<_CharT>::length(__p);
236
              if (__p == __pend)
237
                break;
238
 
239
              __p++;
240
              __ret.push_back(_CharT());
241
            }
242
        }
243
      __catch(...)
244
        {
245
          delete [] __c;
246
          __throw_exception_again;
247
        }
248
 
249
      delete [] __c;
250
 
251
      return __ret;
252
    }
253
 
254
  template
255
    long
256
    collate<_CharT>::
257
    do_hash(const _CharT* __lo, const _CharT* __hi) const
258
    {
259
      unsigned long __val = 0;
260
      for (; __lo < __hi; ++__lo)
261
        __val =
262
          *__lo + ((__val << 7)
263
                   | (__val >> (__gnu_cxx::__numeric_traits::
264
                                __digits - 7)));
265
      return static_cast(__val);
266
    }
267
 
268
  // Inhibit implicit instantiations for required instantiations,
269
  // which are defined via explicit instantiations elsewhere.
270
#if _GLIBCXX_EXTERN_TEMPLATE
271
  extern template class collate;
272
  extern template class collate_byname;
273
 
274
  extern template
275
    const collate&
276
    use_facet >(const locale&);
277
 
278
  extern template
279
    bool
280
    has_facet >(const locale&);
281
 
282
#ifdef _GLIBCXX_USE_WCHAR_T
283
  extern template class collate;
284
  extern template class collate_byname;
285
 
286
  extern template
287
    const collate&
288
    use_facet >(const locale&);
289
 
290
  extern template
291
    bool
292
    has_facet >(const locale&);
293
#endif
294
#endif
295
 
296
_GLIBCXX_END_NAMESPACE_VERSION
297
} // namespace std
298
 
299
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.