00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00048 #ifndef STLSOFT_INCL_STLSOFT_STRING_HPP_SHIM_STRING
00049 # error shim_string_vc5_.hpp can not be included in isolation: include stlsoft/string/shim_string.hpp instead
00050 #endif
00051
00052 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00053 # define STLSOFT_VER_STLSOFT_STRING_HPP_SHIM_STRING_VC5__MAJOR 1
00054 # define STLSOFT_VER_STLSOFT_STRING_HPP_SHIM_STRING_VC5_MINOR 1
00055 # define STLSOFT_VER_STLSOFT_STRING_HPP_SHIM_STRING_VC5_REVISION 1
00056 # define STLSOFT_VER_STLSOFT_STRING_HPP_SHIM_STRING_VC5_EDIT 12
00057 #endif
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074 #ifndef STLSOFT_INCL_STLSOFT_H_STLSOFT
00075 # include <stlsoft/stlsoft.h>
00076 #endif
00077
00078 #ifndef STLSOFT_INCL_STLSOFT_MEMORY_HPP_ALLOCATOR_SELECTOR
00079 # include <stlsoft/memory/allocator_selector.hpp>
00080 #endif
00081 #ifndef STLSOFT_INCL_STLSOFT_STRING_HPP_CHAR_TRAITS
00082 # include <stlsoft/string/char_traits.hpp>
00083 #endif
00084 #ifndef STLSOFT_INCL_STLSOFT_UTIL_HPP_STD_SWAP
00085 # include <stlsoft/util/std_swap.hpp>
00086 #endif
00087
00088 #ifndef STLSOFT_INCL_NEW
00089 # define STLSOFT_INCL_NEW
00090 # include <new>
00091 #endif
00092
00093
00094
00095
00096
00097 #ifndef _STLSOFT_NO_NAMESPACE
00098 namespace stlsoft
00099 {
00100 #endif
00101
00102
00103
00104
00105
00106 template< ss_typename_param_k C
00107 , ss_size_t N = 64
00108 , ss_bool_t U = false
00109 >
00110 class basic_shim_string
00111 {
00112 public:
00113 typedef C char_type;
00114 typedef ss_size_t size_type;
00115 typedef basic_shim_string<C, N, U> class_type;
00116 typedef stlsoft_char_traits<C> traits_type;
00117
00118 public:
00119 ss_explicit_k basic_shim_string(ss_size_t n)
00120 : m_buffer(NULL)
00121 , m_length(0)
00122 {
00123 if(NULL == (m_buffer = static_cast<char_type*>(::malloc(sizeof(char_type) * (1 + n)))))
00124 {
00125 #ifdef STLSOFT_CF_EXCEPTION_SUPPORT
00126 STLSOFT_THROW_X(stlsoft_ns_qual_std(bad_alloc)());
00127 #endif
00128 }
00129 else
00130 {
00131 m_length = n;
00132 m_buffer[0] = '\0';
00133 m_buffer[n] = '\0';
00134 }
00135 }
00136
00137 basic_shim_string(char_type const* s, size_type n)
00138 : m_buffer(NULL)
00139 , m_length(0)
00140 {
00141 if(NULL == (m_buffer = static_cast<char_type*>(::malloc(sizeof(char_type) * (1 + n)))))
00142 {
00143 #ifdef STLSOFT_CF_EXCEPTION_SUPPORT
00144 STLSOFT_THROW_X(stlsoft_ns_qual_std(bad_alloc)());
00145 #endif
00146 }
00147 else
00148 {
00149 m_length = n;
00150 if(NULL == s)
00151 {
00152 m_buffer[0] = '\0';
00153 }
00154 else
00155 {
00156 traits_type::copy(&m_buffer[0], s, n);
00157 }
00158 m_buffer[n] = '\0';
00159 }
00160 }
00161
00162 basic_shim_string(char_type const* s)
00163 : m_buffer(NULL)
00164 , m_length(0)
00165 {
00166 const ss_size_t n = (NULL == s) ? 0 : traits_type::length(s);
00167
00168 if(NULL == (m_buffer = static_cast<char_type*>(::malloc(sizeof(char_type) * (1 + n)))))
00169 {
00170 #ifdef STLSOFT_CF_EXCEPTION_SUPPORT
00171 STLSOFT_THROW_X(stlsoft_ns_qual_std(bad_alloc)());
00172 #endif
00173 }
00174 else
00175 {
00176 m_length = n;
00177 traits_type::copy(&m_buffer[0], s, n);
00178 m_buffer[n] = '\0';
00179 }
00180 }
00181
00182 #if 0
00183 basic_shim_string(class_type const& rhs)
00184 : m_buffer(NULL)
00185 , m_length(0)
00186 {
00187 if(NULL == (m_buffer = static_cast<char_type*>(::malloc(sizeof(char_type) * (1 + rhs.size())))))
00188 {
00189 #ifdef STLSOFT_CF_EXCEPTION_SUPPORT
00190 STLSOFT_THROW_X(stlsoft_ns_qual_std(bad_alloc)());
00191 #endif
00192 }
00193 else
00194 {
00195 m_length = rhs.size();
00196 traits_type::copy(&m_buffer[0], &rhs.m_buffer[0], rhs.size());
00197 m_buffer[rhs.size()] = '\0';
00198 }
00199 }
00200 #else
00201 basic_shim_string(class_type& rhs)
00202 : m_buffer(rhs.m_buffer)
00203 , m_length(rhs.m_length)
00204 {
00205 rhs.m_buffer = NULL;
00206 rhs.m_length = 0;
00207 }
00208 #endif
00209
00210 ~basic_shim_string()
00211 {
00212 ::free(m_buffer);
00213 }
00214
00216 void swap(class_type& rhs) stlsoft_throw_0()
00217 {
00218 std_swap(m_buffer, rhs.m_buffer);
00219 std_swap(m_length, rhs.m_length);
00220 }
00221
00222 public:
00223 void write(char_type const* s)
00224 {
00225 traits_type::copy(&m_buffer[0], s, m_buffer.size());
00226 m_buffer[m_buffer.size() - 1] = '\0';
00227 }
00228
00229 void truncate(size_type n)
00230 {
00231 STLSOFT_MESSAGE_ASSERT("shim_string truncation size must be <= current size", n <= size());
00232
00233 m_buffer[n] = '\0';
00234 }
00235
00236 public:
00237 size_type size() const
00238 {
00239 return m_length;
00240 }
00241 char_type *data()
00242 {
00243 return m_buffer;
00244 }
00245 char_type const* data() const
00246 {
00247 return m_buffer;
00248 }
00249
00250 operator char_type const* () const
00251 {
00252 const volatile ss_bool_t b = U;
00253
00254 return (!b || '\0' != m_buffer[0]) ? data() : NULL;
00255 }
00256
00257 private:
00258
00259
00260 private:
00261 char_type* m_buffer;
00262 ss_size_t m_length;
00263
00264 private:
00265 class_type& operator =(class_type const&);
00266 };
00267
00268
00269
00270
00271
00272 template< ss_typename_param_k C
00273 >
00274 inline C const* c_str_data(basic_shim_string<C> const& ss)
00275 {
00276 return ss.data();
00277 }
00278
00279 inline ss_char_a_t const* c_str_data_a(basic_shim_string<ss_char_a_t> const& ss)
00280 {
00281 return ss.data();
00282 }
00283
00284 inline ss_char_w_t const* c_str_data_w(basic_shim_string<ss_char_w_t> const& ss)
00285 {
00286 return ss.data();
00287 }
00288
00289
00290
00291 template< ss_typename_param_k C
00292 >
00293 inline ss_size_t c_str_len(basic_shim_string<C> const& ss)
00294 {
00295 return ss.size();
00296 }
00297
00298 inline ss_size_t c_str_len_a(basic_shim_string<ss_char_a_t> const& ss)
00299 {
00300 return ss.size();
00301 }
00302
00303 inline ss_size_t c_str_len_w(basic_shim_string<ss_char_w_t> const& ss)
00304 {
00305 return ss.size();
00306 }
00307
00308
00309
00310 template< ss_typename_param_k C
00311 >
00312 inline C const* c_str_ptr(basic_shim_string<C> const& ss)
00313 {
00314 return ss.data();
00315 }
00316
00317 inline ss_char_a_t const* c_str_ptr_a(basic_shim_string<ss_char_a_t> const& ss)
00318 {
00319 return ss.data();
00320 }
00321
00322 inline ss_char_w_t const* c_str_ptr_w(basic_shim_string<ss_char_w_t> const& ss)
00323 {
00324 return ss.data();
00325 }
00326
00327
00328
00329 template< ss_typename_param_k S
00330 , ss_typename_param_k C
00331 >
00332 inline S& operator <<(S& s, basic_shim_string<C> const& ss)
00333 {
00334 s << ss.data();
00335
00336 return s;
00337 }
00338
00339
00340
00341 #ifndef _STLSOFT_NO_NAMESPACE
00342 }
00343 #endif
00344
00345