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
00041
00048 #ifndef STLSOFT_INCL_STLSOFT_UTIL_HPP_EXCEPTION_STRING
00049 #define STLSOFT_INCL_STLSOFT_UTIL_HPP_EXCEPTION_STRING
00050
00051 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00052 # define STLSOFT_VER_STLSOFT_UTIL_HPP_EXCEPTION_STRING_MAJOR 1
00053 # define STLSOFT_VER_STLSOFT_UTIL_HPP_EXCEPTION_STRING_MINOR 4
00054 # define STLSOFT_VER_STLSOFT_UTIL_HPP_EXCEPTION_STRING_REVISION 1
00055 # define STLSOFT_VER_STLSOFT_UTIL_HPP_EXCEPTION_STRING_EDIT 21
00056 #endif
00057
00058
00059
00060
00061
00062 #ifndef STLSOFT_INCL_STLSOFT_H_STLSOFT
00063 # include <stlsoft/stlsoft.h>
00064 #endif
00065 #ifndef STLSOFT_INCL_STLSOFT_MEMORY_HPP_ALLOCATOR_SELECTOR
00066 # include <stlsoft/memory/allocator_selector.hpp>
00067 #endif
00068 #ifndef STLSOFT_INCL_STLSOFT_HPP_MEMORY_AUTO_BUFFER
00069 # include <stlsoft/memory/auto_buffer.hpp>
00070 #endif
00071 #ifndef STLSOFT_INCL_STLSOFT_STRING_HPP_CHAR_TRAITS
00072 # include <stlsoft/string/char_traits.hpp>
00073 #endif
00074
00075 #ifdef STLSOFT_UNITTEST
00076 # include <string.h>
00077 #endif
00078
00079
00080
00081
00082
00083 #ifndef _STLSOFT_NO_NAMESPACE
00084 namespace stlsoft
00085 {
00086 #endif
00087
00088
00089
00090
00091
00096 class exception_string
00097 {
00100 public:
00102 typedef char char_type;
00104 typedef stlsoft_char_traits<char_type> traits_type;
00106 typedef allocator_selector<char_type>::allocator_type allocator_type;
00108 typedef exception_string class_type;
00110 typedef ss_size_t size_type;
00111 private:
00112 typedef auto_buffer_old<char_type, allocator_type, 96> buffer_type_;
00114
00117 public:
00119 exception_string()
00120 : m_message(1)
00121 {
00122 m_message[0] = '\0';
00123 }
00125 ss_explicit_k exception_string(char_type const* message)
00126 : m_message(1 + ((NULL == message) ? 0 : traits_type::length(message)))
00127 {
00128 traits_type::copy(&m_message[0], message, m_message.size() - 1);
00129 m_message[m_message.size() - 1] = '\0';
00130 }
00132 exception_string(char_type const* message, size_type len)
00133 : m_message(1 + len)
00134 {
00135 traits_type::copy(&m_message[0], message, m_message.size() - 1);
00136 m_message[m_message.size() - 1] = '\0';
00137 }
00139 exception_string(class_type const& rhs)
00140 : m_message(rhs.m_message.size())
00141 {
00142 traits_type::copy(&m_message[0], &rhs.m_message[0], m_message.size());
00143 m_message[m_message.size() - 1] = '\0';
00144 }
00145
00147 void operator +=(char_type const* s)
00148 {
00149 const ss_size_t n = traits_type::length(s);
00150 const ss_size_t currLen = this->length();
00151
00152 if(m_message.resize(m_message.size() + n))
00153 {
00154 traits_type::copy(&m_message[currLen], s, n);
00155 m_message[m_message.size() - 1] = '\0';
00156 }
00157 }
00159 void operator +=(class_type const& rhs)
00160 {
00161 const ss_size_t n = rhs.length();
00162 const ss_size_t currLen = this->length();
00163
00164 if(m_message.resize(m_message.size() + n))
00165 {
00166 traits_type::copy(&m_message[currLen], rhs.c_str(), n);
00167 m_message[m_message.size() - 1] = '\0';
00168 }
00169 }
00171 void operator +=(char_type ch)
00172 {
00173 const ss_size_t n = 1;
00174 const ss_size_t currLen = this->length();
00175
00176 if(m_message.resize(m_message.size() + n))
00177 {
00178 traits_type::copy(&m_message[currLen], &ch, n);
00179 m_message[m_message.size() - 1] = '\0';
00180 }
00181 }
00182
00189 void truncate(size_type n)
00190 {
00191 if(n < m_message.size() - 1)
00192 {
00193 if(m_message.resize(n + 1))
00194 {
00195 m_message[m_message.size() - 1] = '\0';
00196 }
00197 }
00198 }
00200
00203 public:
00206 char_type const* c_str() const
00207 {
00208 return data();
00209 }
00212 char_type const* data() const
00213 {
00214 return m_message.data();
00215 }
00217 size_type length() const
00218 {
00219 return size();
00220 }
00222 size_type size() const
00223 {
00224 STLSOFT_ASSERT(m_message.size() > 0);
00225
00226 return m_message.size() - 1;
00227 }
00229 ss_bool_t empty() const
00230 {
00231 return 0 == this->length();
00232 }
00234
00237 private:
00238 buffer_type_ m_message;
00240
00243 private:
00244 class_type& operator =(class_type const&);
00246 };
00247
00248
00249
00250
00251
00252 inline exception_string::char_type const* c_str_data(exception_string const& xs)
00253 {
00254 return xs.data();
00255 }
00256
00257 inline exception_string::size_type c_str_len(exception_string const& xs)
00258 {
00259 return xs.size();
00260 }
00261
00262 inline exception_string::char_type const* c_str_ptr(exception_string const& xs)
00263 {
00264 return xs.c_str();
00265 }
00266
00267 inline exception_string::char_type const* c_str_data_a(exception_string const& xs)
00268 {
00269 return c_str_data(xs);
00270 }
00271
00272 inline exception_string::size_type c_str_len_a(exception_string const& xs)
00273 {
00274 return c_str_len(xs);
00275 }
00276
00277 inline exception_string::char_type const* c_str_ptr_a(exception_string const& xs)
00278 {
00279 return c_str_ptr(xs);
00280 }
00281
00282
00283
00284
00285
00290 inline exception_string operator +(exception_string const& lhs, exception_string::char_type const* rhs)
00291 {
00292 exception_string s(lhs);
00293
00294 s += rhs;
00295
00296 return s;
00297 }
00298
00303 inline exception_string operator +(exception_string::char_type lhs, exception_string const& rhs)
00304 {
00305 exception_string::char_type lhs_[2] = { lhs, '\0' };
00306 exception_string s(lhs_);
00307
00308 s += rhs;
00309
00310 return s;
00311 }
00312
00317 inline exception_string operator +(exception_string const& lhs, exception_string::char_type rhs)
00318 {
00319 exception_string s(lhs);
00320
00321 s += rhs;
00322
00323 return s;
00324 }
00325
00330 inline exception_string operator +(exception_string::char_type const* lhs, exception_string const& rhs)
00331 {
00332 exception_string s(lhs);
00333
00334 s += rhs;
00335
00336 return s;
00337 }
00338
00343 inline exception_string operator +(exception_string const& lhs, exception_string const& rhs)
00344 {
00345 exception_string s(lhs);
00346
00347 s += rhs;
00348
00349 return s;
00350 }
00351
00353
00354
00355 #ifdef STLSOFT_UNITTEST
00356 # include "./unittest/exception_string_unittest_.h"
00357 #endif
00358
00359
00360
00361 #ifndef _STLSOFT_NO_NAMESPACE
00362 }
00363 #endif
00364
00365
00366
00367 #endif
00368
00369