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
00047 #ifndef FASTFORMAT_INCL_FASTFORMAT_SINK_HPP_SHIM_STRING
00048 #define FASTFORMAT_INCL_FASTFORMAT_SINK_HPP_SHIM_STRING
00049
00050
00051
00052
00053
00054 #ifndef FASTFORMAT_DOCUMENTATION_SKIP_SECTION
00055 # define FASTFORMAT_VER_FASTFORMAT_SINK_HPP_SHIM_STRING_SINK_MAJOR 1
00056 # define FASTFORMAT_VER_FASTFORMAT_SINK_HPP_SHIM_STRING_SINK_MINOR 0
00057 # define FASTFORMAT_VER_FASTFORMAT_SINK_HPP_SHIM_STRING_SINK_REVISION 5
00058 # define FASTFORMAT_VER_FASTFORMAT_SINK_HPP_SHIM_STRING_SINK_EDIT 6
00059 #endif
00060
00061
00062
00063
00064
00065 #ifndef __cplusplus
00066 # error This file can only be included in C++ compilation units
00067 #endif
00068
00069
00070
00071
00072
00073 #include <fastformat/fastformat.h>
00074 #include <fastformat/quality/contract.h>
00075 #include <fastformat/util/sinks/helpers.hpp>
00076 #include <fastformat/format/standard_flags.hpp>
00077
00078 #include <stlsoft/shims/access/string/std/c_string.h>
00079 #include <stlsoft/string/shim_string.hpp>
00080
00081
00082
00083
00084
00085 #if !defined(FASTFORMAT_NO_NAMESPACE)
00086 namespace fastformat
00087 {
00088 namespace sinks
00089 {
00090 #endif
00091
00092
00093
00094
00095
00096 #if _STLSOFT_VER < 0x010a0000 && \
00097 defined(_STLSOFT_1_10_VER)
00098 # if _STLSOFT_1_10_VER < 0x010a0109
00099 # error This file cannot be used with STLSoft 1.10.1 alpha 1 - STLSoft 1.10.1 alpha 8, and is not necessary with STLSoft 1.10.1 alpha 9+ (for which it is not necessary)
00100 # endif
00101 #endif
00102
00103
00104
00105
00106
00130 class shim_string_sink
00131 : public stlsoft::basic_shim_string<ff_char_t>
00132 {
00133 public:
00134
00135 typedef shim_string_sink class_type;
00137 typedef stlsoft::basic_shim_string<ff_char_t> parent_class_type;
00139 typedef parent_class_type::size_type size_type;
00140 private:
00141
00142 public:
00143
00145 shim_string_sink()
00146 : parent_class_type(size_type(0))
00147 #if _STLSOFT_VER < 0x010a0000 && \
00148 !defined(_STLSOFT_1_10_VER)
00149 , m_len(0)
00150 #endif
00151 {}
00155 explicit shim_string_sink(size_type n)
00156 : parent_class_type(n)
00157 #if _STLSOFT_VER < 0x010a0000 && \
00158 !defined(_STLSOFT_1_10_VER)
00159 , m_len(0)
00160 #endif
00161 {}
00162 private:
00163 class_type& operator =(class_type const& rhs);
00164
00165 public:
00166
00170 void reserve(size_type n)
00171 {
00172 #if _STLSOFT_VER < 0x010a0000 && \
00173 !defined(_STLSOFT_1_10_VER)
00174
00175 parent_class_type::buffer_type& buffer = parent_class_type::get_buffer();
00176
00177 if(buffer.resize(n + 1))
00178 {
00179 buffer[n] = '\0';
00180 }
00181
00182 #else
00183 parent_class_type::reserve(n);
00184 #endif
00185 }
00186
00188 class_type& append(ff_char_t const* s, size_type n)
00189 {
00190 #if _STLSOFT_VER < 0x010a0000 && \
00191 !defined(_STLSOFT_1_10_VER)
00192
00193 parent_class_type::buffer_type& buffer = parent_class_type::get_buffer();
00194
00195 if(m_len + n + 1 > buffer.size())
00196 {
00197 if(!buffer.resize(m_len + n + 1))
00198 {
00199 buffer[0] = '\0';
00200 m_len = 0;
00201
00202 return *this;
00203 }
00204 }
00205
00206 ::memcpy(&buffer[0] + m_len, s, sizeof(ff_char_t) * n);
00207 m_len += n;
00208 buffer[m_len] = '\0';
00209
00210 #else
00211 parent_class_type::append(s, n);
00212 #endif
00213
00214 return *this;
00215 }
00216
00218 class_type& append(ff_char_t const* s)
00219 {
00220 #if _STLSOFT_VER < 0x010a0000 && \
00221 !defined(_STLSOFT_1_10_VER)
00222
00223 append(s, stlsoft::c_str_len(s));
00224
00225 #else
00226 parent_class_type::append(s);
00227 #endif
00228
00229 return *this;
00230 }
00231
00233 void truncate(size_type n)
00234 {
00235 parent_class_type::truncate(n);
00236 }
00237
00238 #if _STLSOFT_VER < 0x010a0000 && \
00239 !defined(_STLSOFT_1_10_VER)
00240
00241 public:
00242
00244 size_type size() const
00245 {
00246 STLSOFT_ASSERT(m_len < const_cast<class_type*>(this)->parent_class_type::get_buffer().size());
00247
00248 return m_len;
00249 }
00250
00252 operator size_type() const
00253 {
00254 return size();
00255 }
00256
00257 private:
00258 size_type m_len;
00259 #endif
00260 };
00261
00262
00263
00264
00265
00266
00267
00268
00269
00271 #ifdef FASTFORMAT_USE_WIDE_STRINGS
00272 inline wchar_t const* c_str_data_w(
00273 #else
00274 inline char const* c_str_data_a(
00275 #endif
00276 shim_string_sink const& sink
00277 )
00278 {
00279 return sink.data();
00280 }
00281
00283 inline ff_char_t const* c_str_data(
00284 shim_string_sink const& sink
00285 )
00286 {
00287 return sink.data();
00288 }
00289
00291 #ifdef FASTFORMAT_USE_WIDE_STRINGS
00292 inline size_t c_str_len_w(
00293 #else
00294 inline size_t c_str_len_a(
00295 #endif
00296 shim_string_sink const& sink
00297 )
00298 {
00299 return sink.size();
00300 }
00301
00303 inline size_t c_str_len(
00304 shim_string_sink const& sink
00305 )
00306 {
00307 return size_t(sink.size());
00308 }
00309
00310
00311
00312
00313
00314 #if !defined(FASTFORMAT_NO_NAMESPACE)
00315 }
00316 }
00317 #endif
00318
00319
00320
00321 #endif
00322
00323