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_OSTREAM_ITERATOR
00049 #define STLSOFT_INCL_STLSOFT_ITERATORS_HPP_OSTREAM_ITERATOR
00050
00051 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00052 # define STLSOFT_VER_STLSOFT_ITERATORS_HPP_OSTREAM_ITERATOR_MAJOR 1
00053 # define STLSOFT_VER_STLSOFT_ITERATORS_HPP_OSTREAM_ITERATOR_MINOR 3
00054 # define STLSOFT_VER_STLSOFT_ITERATORS_HPP_OSTREAM_ITERATOR_REVISION 3
00055 # define STLSOFT_VER_STLSOFT_ITERATORS_HPP_OSTREAM_ITERATOR_EDIT 36
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_UTIL_STD_HPP_ITERATOR_HELPER
00066 # include <stlsoft/util/std/iterator_helper.hpp>
00067 #endif
00068 #ifndef STLSOFT_INCL_STLSOFT_SHIMS_ACCESS_HPP_STRING
00069 # include <stlsoft/shims/access/string.hpp>
00070 #endif
00071
00072 #ifndef STLSOFT_INCL_STRING
00073 # define STLSOFT_INCL_STRING
00074 # include <string>
00075 #endif
00076
00077
00078 #if defined(STLSOFT_COMPILER_IS_MSVC) && \
00079 _MSC_VER == 1200
00080 # include <iterator>
00081 # include <stlsoft/string/char_traits.hpp>
00082 #endif
00083
00084 #ifdef STLSOFT_UNITTEST
00085 # include <algorithm>
00086 # include <sstream>
00087 #endif
00088
00089
00090
00091
00092
00093 #ifndef _STLSOFT_NO_NAMESPACE
00094 namespace stlsoft
00095 {
00096 #endif
00097
00098
00099
00100
00101
00148 template< ss_typename_param_k V
00149 , ss_typename_param_k C = char
00150 , ss_typename_param_k T = stlsoft_ns_qual_std(char_traits)<C>
00151 , ss_typename_param_k S = stlsoft_ns_qual_std(basic_string)<C, T>
00152 >
00153
00154 class ostream_iterator
00155 : public stlsoft_ns_qual(iterator_base)<stlsoft_ns_qual_std(output_iterator_tag), void, void, void, void>
00156 {
00159 public:
00161 typedef V assigned_type;
00163 typedef C char_type;
00165 typedef T traits_type;
00167 typedef S string_type;
00169 typedef stlsoft_ns_qual_std(basic_ostream)<
00170 char_type
00171 , traits_type
00172 > ostream_type;
00174 typedef ostream_iterator<V, C, T, S> class_type;
00175 private:
00176 class deref_proxy;
00177 friend class deref_proxy;
00179
00182 public:
00186 ss_explicit_k ostream_iterator(ostream_type &os)
00187 : m_stm(&os)
00188 , m_prefix()
00189 , m_suffix()
00190 {}
00194 template <ss_typename_param_k S1>
00195 ostream_iterator(ostream_type &os, S1 const& suffix)
00196 : m_stm(&os)
00197 , m_prefix()
00198 , m_suffix(get_string_(suffix))
00199 {}
00201 template <ss_typename_param_k S1, ss_typename_param_k S2>
00202 ostream_iterator(ostream_type &os, S1 const& prefix, S2 const& suffix)
00203 : m_stm(&os)
00204 , m_prefix(get_string_(prefix))
00205 , m_suffix(get_string_(suffix))
00206 {}
00210 ostream_iterator(class_type const& rhs)
00211 : m_stm(rhs.m_stm)
00212 , m_prefix(rhs.m_prefix)
00213 , m_suffix(rhs.m_suffix)
00214 {}
00215 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00216 ~ostream_iterator() stlsoft_throw_0()
00217 {}
00218 #endif
00220
00223 private:
00224 class deref_proxy
00225 {
00226 public:
00227 deref_proxy(ostream_iterator* it)
00228 : m_it(it)
00229 {}
00230
00231 public:
00232 void operator =(assigned_type const& value)
00233 {
00234 m_it->invoke_(value);
00235 }
00236
00237 private:
00238 ostream_iterator* const m_it;
00239
00240
00241 private:
00242 void operator =(deref_proxy const&);
00243 };
00244
00245 void invoke_(assigned_type const& value)
00246 {
00247 *m_stm << m_prefix << value << m_suffix;
00248 }
00250
00253 public:
00255 deref_proxy operator *()
00256 {
00257 return deref_proxy(this);
00258 }
00260 class_type& operator ++()
00261 {
00262 return *this;
00263 }
00265 class_type& operator ++(int)
00266 {
00267 return *this;
00268 }
00270
00273 private:
00274 template <ss_typename_param_k S2>
00275 static string_type get_string_(S2 const& s)
00276 {
00277 return stlsoft::c_str_ptr(s);
00278 }
00279 #if !defined(STLSOFT_COMPILER_IS_MSVC) || \
00280 _MSC_VER > 1300
00281 static string_type const& get_string_(string_type const& s)
00282 {
00283 return s;
00284 }
00285 #endif
00287
00290 private:
00291 ostream_type* m_stm;
00292 string_type m_prefix;
00293 string_type m_suffix;
00295 };
00296
00298
00299
00300 #ifdef STLSOFT_UNITTEST
00301 # include "./unittest/ostream_iterator_unittest_.h"
00302 #endif
00303
00304
00305
00306 #ifndef _STLSOFT_NO_NAMESPACE
00307 }
00308 #endif
00309
00310
00311
00312 #endif
00313
00314