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_ITERATORS_HPP_STRING_CONCATENATOR_ITERATOR
00049 #define STLSOFT_INCL_STLSOFT_ITERATORS_HPP_STRING_CONCATENATOR_ITERATOR
00050
00051 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00052 # define STLSOFT_VER_STLSOFT_ITERATORS_HPP_STRING_CONCATENATOR_ITERATOR_MAJOR 2
00053 # define STLSOFT_VER_STLSOFT_ITERATORS_HPP_STRING_CONCATENATOR_ITERATOR_MINOR 3
00054 # define STLSOFT_VER_STLSOFT_ITERATORS_HPP_STRING_CONCATENATOR_ITERATOR_REVISION 3
00055 # define STLSOFT_VER_STLSOFT_ITERATORS_HPP_STRING_CONCATENATOR_ITERATOR_EDIT 41
00056 #endif
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072 #ifndef STLSOFT_INCL_STLSOFT_H_STLSOFT
00073 # include <stlsoft/stlsoft.h>
00074 #endif
00075 #ifndef STLSOFT_INCL_STLSOFT_SHIMS_ACCESS_HPP_STRING
00076 # include <stlsoft/shims/access/string.hpp>
00077 #endif
00078 #ifndef STLSOFT_INCL_STLSOFT_UTIL_STD_HPP_ITERATOR_HELPER
00079 # include <stlsoft/util/std/iterator_helper.hpp>
00080 #endif
00081 #ifndef STLSOFT_INCL_STLSOFT_STRING_HPP_STRING_TRAITS
00082 # include <stlsoft/string/string_traits.hpp>
00083 #endif
00084 #ifndef _STLSOFT_STRING_FUNCTIONALS_NO_STD
00085 # include <functional>
00086 #else
00087 # error Now need to write that std_binary_function stuff!!
00088 #endif
00089
00090 #ifdef STLSOFT_UNITTEST
00091 # include <algorithm>
00092 # include <string>
00093 # include <vector>
00094 #endif
00095
00096
00097
00098
00099
00100 #ifndef _STLSOFT_NO_NAMESPACE
00101 namespace stlsoft
00102 {
00103 #endif
00104
00105 #ifdef __SYNSOFT_DBS_COMPILER_SUPPORTS_PRAGMA_MESSAGE
00106 # pragma message(_sscomp_fileline_message("TODO: Need a function that can do quoting (or anything else)"))
00107 #endif
00108
00109
00110
00111
00112
00122 template< ss_typename_param_k S
00123 , ss_typename_param_k D
00124 >
00125
00126 class string_concatenator_iterator
00127 : public stlsoft_ns_qual(iterator_base)<stlsoft_ns_qual_std(output_iterator_tag), void, void, void, void>
00128 {
00131 public:
00132 typedef S string_type;
00133 typedef D delimiter_type;
00134 typedef string_concatenator_iterator<S, D> class_type;
00136
00139 private:
00140 #if defined(STLSOFT_COMPILER_IS_MSVC) && \
00141 _MSC_VER < 1310
00142 public:
00143 #endif
00144 string_concatenator_iterator(string_type* s, delimiter_type const* delim)
00145 : m_s(s)
00146 , m_delim(delim)
00147 {}
00148 public:
00149 static class_type create(string_type& s, delimiter_type const& delim)
00150 {
00151 return class_type(&s, &delim);
00152 }
00153 private:
00154 class deref_proxy;
00155 friend class deref_proxy;
00157
00160 public:
00161 deref_proxy operator *()
00162 {
00163 return deref_proxy(this);
00164 }
00165 class_type& operator ++()
00166 {
00167 return *this;
00168 }
00169 class_type& operator ++(int)
00170 {
00171 return *this;
00172 }
00174
00177 private:
00178 class deref_proxy
00179 {
00180 public:
00181 deref_proxy(string_concatenator_iterator* it)
00182 : m_it(it)
00183 {}
00184
00185 public:
00186 template <ss_typename_param_k S3>
00187 void operator =(S3 const& value)
00188 {
00189 #if defined(STLSOFT_COMPILER_IS_BORLAND)
00190
00191
00192
00193 m_it->invoke_(c_str_ptr(value));
00194 #else
00195
00196
00197
00198
00199
00200
00201
00202
00203 typedef ss_typename_type_k string_traits<string_type>::char_type char_t;
00204
00205 STLSOFT_STATIC_ASSERT(sizeof(char) == sizeof(char_t) || sizeof(wchar_t) == sizeof(char_t));
00206
00207 m_it->invoke_(value, char_t());
00208 #endif
00209 }
00210
00211 private:
00212 string_concatenator_iterator *const m_it;
00213
00214
00215 private:
00216 void operator =(deref_proxy const&);
00217 };
00218
00219 #if defined(STLSOFT_COMPILER_IS_BORLAND)
00220 template <ss_typename_param_k C2>
00221 void invoke_(C2 const* value)
00222 {
00223 this->invoke_(value, *value);
00224 }
00225 #endif
00226
00227 #if 0
00228 template <ss_typename_param_k S3>
00229 void invoke_(S3 const& value)
00230 {
00231 STLSOFT_ASSERT(NULL != m_s);
00232 STLSOFT_ASSERT(NULL != m_delim);
00233
00234 if(0 != c_str_len(*m_s))
00235 {
00236
00237 *m_s += c_str_ptr(*m_delim);
00238 }
00239 *m_s += c_str_ptr(value);
00240 }
00241 #else
00242 template <ss_typename_param_k S3>
00243 void invoke_(S3 const& value, ss_char_a_t)
00244 {
00245 STLSOFT_ASSERT(NULL != m_s);
00246 STLSOFT_ASSERT(NULL != m_delim);
00247
00248 if(0 != c_str_len(*m_s))
00249 {
00250
00251 *m_s += c_str_ptr_a(*m_delim);
00252 }
00253 *m_s += c_str_ptr_a(value);
00254 }
00255 template <ss_typename_param_k S3>
00256 void invoke_(S3 const& value, ss_char_w_t)
00257 {
00258 STLSOFT_ASSERT(NULL != m_s);
00259 STLSOFT_ASSERT(NULL != m_delim);
00260
00261 if(0 != c_str_len(*m_s))
00262 {
00263
00264 *m_s += c_str_ptr_w(*m_delim);
00265 }
00266 *m_s += c_str_ptr_w(value);
00267 }
00268 #endif
00270
00273 private:
00274 string_type *m_s;
00275 delimiter_type const *m_delim;
00277 };
00278
00279
00280
00281
00282
00292 template< ss_typename_param_k S
00293 , ss_typename_param_k D
00294 >
00295 inline string_concatenator_iterator<S, D> make_string_concatenator_iterator(S& s, D const& delim)
00296 {
00297 return string_concatenator_iterator<S, D>::create(s, delim);
00298 }
00299
00311 template< ss_typename_param_k S
00312 , ss_typename_param_k D
00313 >
00314 inline string_concatenator_iterator<S, D> string_concatenator(S& s, D const& delim)
00315 {
00316 #if defined(STLSOFT_COMPILER_IS_INTEL) || \
00317 defined(STLSOFT_COMPILER_IS_MSVC)
00318 return string_concatenator_iterator<S, D>::create(s, delim);
00319 #else
00320 return make_string_concatenator_iterator(s, delim);
00321 #endif
00322 }
00323
00325
00326
00327 #ifdef STLSOFT_UNITTEST
00328 # include "./unittest/string_concatenator_iterator_unittest_.h"
00329 #endif
00330
00331
00332
00333 #ifndef _STLSOFT_NO_NAMESPACE
00334 }
00335 #endif
00336
00337
00338
00339 #endif
00340
00341