On x86 compilers without fastcall, simulate it when invoking traces and un-simulate...
[wine-gecko.git] / xpcom / tests / StringFactoringTests / nsStdStringWrapper.h
blob06505f118d9d7f9fd56b90fe2d05ce1578011fca
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
23 * Scott Collins <scc@mozilla.org>
25 * Alternatively, the contents of this file may be used under the terms of
26 * either of the GNU General Public License Version 2 or later (the "GPL"),
27 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 #ifndef nsStdStringWrapper_h___
40 #define nsStdStringWrapper_h___
42 #include <string>
44 #ifndef nsAString_h___
45 #include "nsAString.h"
46 #endif
49 template <class T>
50 class nsStringAllocator
51 : public std::allocator<T> // temporarily
53 // ...
57 template < class CharT, class TraitsT = nsCharTraits<CharT>, class AllocatorT = nsStringAllocator<CharT> >
58 class basic_nsStdStringWrapper
59 : public basic_nsAString<CharT>
61 ...
64 protected:
65 std::basic_string<CharT, TraitsT, AllocatorT> mRawString;
67 typedef std::basic_string<CharT, TraitsT, AllocatorT> basic_string_t;
69 using typename basic_string_t::traits_type;
70 using typename basic_string_t::value_type;
71 using typename basic_string_t::allocator_type;
72 using typename basic_string_t::size_type;
73 using typename basic_string_t::difference_type;
74 using typename basic_string_t::reference;
75 using typename basic_string_t::const_reference;
76 using typename basic_string_t::pointer;
77 using typename basic_string_t::const_pointer;
78 using typename basic_string_t::iterator;
79 using typename basic_string_t::const_iterator;
80 using typename basic_string_t::reverse_iterator;
81 using typename basic_string_t::const_reverse_iterator;
83 static const size_type npos = size_type(-1);
85 protected:
86 virtual const void* Implementation() const;
88 virtual const CharT* GetReadableFragment( nsReadableFragment<CharT>&, nsFragmentRequest, PRUint32 ) const;
89 virtual CharT* GetWritableFragment( nsWritableFragment<CharT>&, nsFragmentRequest, PRUint32 );
91 public:
92 basic_nsStdStringWrapper() { }
94 #if 0
95 explicit
96 basic_nsStdStringWrapper( const AllocatorT& a = AllocatorT() )
97 : mRawString(a)
100 #endif
102 explicit
103 basic_nsStdStringWrapper( const basic_nsAString<CharT>& str )
105 Assign(str);
108 #if 0
109 explicit
110 basic_nsStdStringWrapper( const basic_string_t& str, size_type pos = 0, size_type n = npos )
111 : mRawString(str, pos, n)
115 basic_nsStdStringWrapper( const basic_string_t& str, size_type pos, size_type n, const AllocatorT& a )
116 : mRawString(str, pos, n, a)
119 #endif
121 basic_nsStdStringWrapper( const CharT* s, size_type n, const AllocatorT& a = AllocatorT() )
122 : mRawString(s, n, a)
126 explicit
127 basic_nsStdStringWrapper( const CharT* s, const AllocatorT& a = AllocatorT() )
128 : mRawString(s, a)
132 #if 0
133 basic_nsStdStringWrapper( size_type n, CharT c, const AllocatorT& a = AllocatorT() )
134 : mRawString(n, c, a)
137 #endif
139 virtual
140 PRUint32
141 Length() const
143 return mRawString.length();
146 virtual
147 void
148 SetCapacity( PRUint32 aNewCapacity )
150 mRawString.reserve(aNewCapacity);
153 virtual
154 void
155 SetLength( PRUint32 aNewLength )
157 mRawString.resize(aNewLength);
160 protected:
161 virtual void do_AssignFromReadable( const basic_nsAString<CharT>& );
163 // ...
166 NS_DEF_TEMPLATE_STRING_COMPARISON_OPERATORS(basic_nsStdStringWrapper<CharT>, CharT)
170 template <class CharT, class TraitsT, class AllocatorT>
171 const void*
172 basic_nsStdStringWrapper<CharT, TraitsT, AllocatorT>::Implementation() const
174 static const char* implementation = "nsStdStringWrapper";
175 return implementation;
179 template <class CharT, class TraitsT, class AllocatorT>
180 const CharT*
181 basic_nsStdStringWrapper<CharT, TraitsT, AllocatorT>::GetReadableFragment( nsReadableFragment<CharT>& aFragment, nsFragmentRequest aRequest, PRUint32 aOffset ) const
183 switch ( aRequest )
185 case kFirstFragment:
186 case kLastFragment:
187 case kFragmentAt:
188 aFragment.mEnd = (aFragment.mStart = mRawString.data()) + mRawString.length();
189 return aFragment.mStart + aOffset;
191 case kPrevFragment:
192 case kNextFragment:
193 default:
194 return 0;
198 template <class CharT, class TraitsT, class AllocatorT>
199 CharT*
200 basic_nsStdStringWrapper<CharT, TraitsT, AllocatorT>::GetWritableFragment( nsWritableFragment<CharT>& aFragment, nsFragmentRequest aRequest, PRUint32 aOffset )
202 switch ( aRequest )
204 case kFirstFragment:
205 case kLastFragment:
206 case kFragmentAt:
207 aFragment.mEnd = (aFragment.mStart = const_cast<CharT*>(mRawString.data())) + mRawString.length();
208 return aFragment.mStart + aOffset;
210 case kPrevFragment:
211 case kNextFragment:
212 default:
213 return 0;
217 template <class CharT, class TraitsT, class AllocatorT>
218 void
219 basic_nsStdStringWrapper<CharT, TraitsT, AllocatorT>::do_AssignFromReadable( const basic_nsAString<CharT>& rhs )
221 typedef basic_nsStdStringWrapper<CharT, TraitsT, AllocatorT> this_t;
223 if ( SameImplementation(*this, rhs) )
224 mRawString = static_cast<this_t>(rhs).mRawString;
225 else
226 basic_nsAString<CharT>::do_AssignFromReadable(rhs);
230 typedef basic_nsStdStringWrapper<PRUnichar> nsStdString;
231 typedef basic_nsStdStringWrapper<char> nsStdCString;
234 #endif // !defined(nsStdStringWrapper_h___)