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

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libstdc++-v3/] [include/] [ext/] [vstring_util.h] - Blame information for rev 17

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 17 jlechner
// Versatile string utility -*- C++ -*-
2
 
3
// Copyright (C) 2005, 2006 Free Software Foundation, Inc.
4
//
5
// This file is part of the GNU ISO C++ Library.  This library is free
6
// software; you can redistribute it and/or modify it under the
7
// terms of the GNU General Public License as published by the
8
// Free Software Foundation; either version 2, or (at your option)
9
// any later version.
10
 
11
// This library is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
// GNU General Public License for more details.
15
 
16
// You should have received a copy of the GNU General Public License along
17
// with this library; see the file COPYING.  If not, write to the Free
18
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19
// USA.
20
 
21
// As a special exception, you may use this file as part of a free software
22
// library without restriction.  Specifically, if other files instantiate
23
// templates or use macros or inline functions from this file, or you compile
24
// this file and link it with other files to produce an executable, this
25
// file does not by itself cause the resulting executable to be covered by
26
// the GNU General Public License.  This exception does not however
27
// invalidate any other reasons why the executable file might be covered by
28
// the GNU General Public License.
29
 
30
/** @file ext/vstring_util.h
31
 *  This file is a GNU extension to the Standard C++ Library.
32
 *  This is an internal header file, included by other library headers.
33
 *  You should not attempt to use it directly.
34
 */
35
 
36
#ifndef _VSTRING_UTIL_H
37
#define _VSTRING_UTIL_H 1
38
 
39
#pragma GCC system_header
40
 
41
#include <ext/vstring_fwd.h>
42
#include <debug/debug.h>
43
#include <bits/stl_function.h>  // For less
44
#include <bits/functexcept.h>
45
#include <locale>
46
#include <algorithm> // For std::distance, srd::search.
47
 
48
namespace __gnu_cxx
49
{
50
  template<typename _CharT, typename _Traits, typename _Alloc>
51
    struct __vstring_utility
52
    {
53
      typedef typename _Alloc::template rebind<_CharT>::other _CharT_alloc_type;
54
 
55
      typedef _Traits                                       traits_type;
56
      typedef typename _Traits::char_type                   value_type;
57
      typedef typename _CharT_alloc_type::size_type         size_type;
58
      typedef typename _CharT_alloc_type::pointer           pointer;
59
      typedef typename _CharT_alloc_type::const_pointer     const_pointer;
60
 
61
      // For __sso_string.
62
      typedef __gnu_cxx::
63
      __normal_iterator<pointer, __gnu_cxx::
64
                        __versa_string<_CharT, _Traits, _Alloc,
65
                                       __sso_string_base> >
66
        __sso_iterator;
67
      typedef __gnu_cxx::
68
      __normal_iterator<const_pointer, __gnu_cxx::
69
                        __versa_string<_CharT, _Traits, _Alloc,
70
                                       __sso_string_base> >
71
        __const_sso_iterator;
72
 
73
      // For __rc_string.
74
      typedef __gnu_cxx::
75
      __normal_iterator<pointer, __gnu_cxx::
76
                        __versa_string<_CharT, _Traits, _Alloc,
77
                                       __rc_string_base> >
78
        __rc_iterator;
79
      typedef __gnu_cxx::
80
      __normal_iterator<const_pointer, __gnu_cxx::
81
                        __versa_string<_CharT, _Traits, _Alloc,
82
                                       __rc_string_base> >
83
        __const_rc_iterator;
84
 
85
      // NB:  When the allocator is empty, deriving from it saves space 
86
      // (http://www.cantrip.org/emptyopt.html).
87
      template<typename _Alloc1>
88
        struct _Alloc_hider
89
        : public _Alloc1
90
        {
91
          _Alloc_hider(const _Alloc1& __a, _CharT* __ptr)
92
          : _Alloc1(__a), _M_p(__ptr) { }
93
 
94
          _CharT*  _M_p; // The actual data.
95
        };
96
 
97
      // For use in _M_construct (_S_construct) forward_iterator_tag.
98
      template<typename _Type>
99
        static bool
100
        _S_is_null_pointer(_Type* __ptr)
101
        { return __ptr == 0; }
102
 
103
      template<typename _Type>
104
        static bool
105
        _S_is_null_pointer(_Type)
106
        { return false; }
107
 
108
      // When __n = 1 way faster than the general multichar
109
      // traits_type::copy/move/assign.
110
      static void
111
      _S_copy(_CharT* __d, const _CharT* __s, size_type __n)
112
      {
113
        if (__n == 1)
114
          traits_type::assign(*__d, *__s);
115
        else
116
          traits_type::copy(__d, __s, __n);
117
      }
118
 
119
      static void
120
      _S_move(_CharT* __d, const _CharT* __s, size_type __n)
121
      {
122
        if (__n == 1)
123
          traits_type::assign(*__d, *__s);
124
        else
125
          traits_type::move(__d, __s, __n);
126
      }
127
 
128
      static void
129
      _S_assign(_CharT* __d, size_type __n, _CharT __c)
130
      {
131
        if (__n == 1)
132
          traits_type::assign(*__d, __c);
133
        else
134
          traits_type::assign(__d, __n, __c);
135
      }
136
 
137
      // _S_copy_chars is a separate template to permit specialization
138
      // to optimize for the common case of pointers as iterators.
139
      template<typename _Iterator>
140
        static void
141
        _S_copy_chars(_CharT* __p, _Iterator __k1, _Iterator __k2)
142
        {
143
          for (; __k1 != __k2; ++__k1, ++__p)
144
            traits_type::assign(*__p, *__k1); // These types are off.
145
        }
146
 
147
      static void
148
      _S_copy_chars(_CharT* __p, __sso_iterator __k1, __sso_iterator __k2)
149
      { _S_copy_chars(__p, __k1.base(), __k2.base()); }
150
 
151
      static void
152
      _S_copy_chars(_CharT* __p, __const_sso_iterator __k1,
153
                    __const_sso_iterator __k2)
154
      { _S_copy_chars(__p, __k1.base(), __k2.base()); }
155
 
156
      static void
157
      _S_copy_chars(_CharT* __p, __rc_iterator __k1, __rc_iterator __k2)
158
      { _S_copy_chars(__p, __k1.base(), __k2.base()); }
159
 
160
      static void
161
      _S_copy_chars(_CharT* __p, __const_rc_iterator __k1,
162
                    __const_rc_iterator __k2)
163
      { _S_copy_chars(__p, __k1.base(), __k2.base()); }
164
 
165
      static void
166
      _S_copy_chars(_CharT* __p, _CharT* __k1, _CharT* __k2)
167
      { _S_copy(__p, __k1, __k2 - __k1); }
168
 
169
      static void
170
      _S_copy_chars(_CharT* __p, const _CharT* __k1, const _CharT* __k2)
171
      { _S_copy(__p, __k1, __k2 - __k1); }
172
    };
173
} // namespace __gnu_cxx
174
 
175
namespace std
176
{
177
  // To implement Option 3 of DR 431 (vstring only in 4_1-branch).
178
  template<typename _Alloc, bool = std::__is_empty<_Alloc>::__value>
179
    struct __alloc_swap
180
    { static void _S_do_it(_Alloc&, _Alloc&) { } };
181
 
182
  template<typename _Alloc>
183
    struct __alloc_swap<_Alloc, false>
184
    {
185
      static void
186
      _S_do_it(_Alloc& __one, _Alloc& __two)
187
      {
188
        // Precondition: swappable allocators.
189
        if (__one != __two)
190
          swap(__one, __two);
191
      }
192
    };
193
}
194
 
195
#endif /* _VSTRING_UTIL_H */

powered by: WebSVN 2.1.0

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