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
00042
00048 #ifndef FASTFORMAT_INCL_FASTFORMAT_ITERATORS_HPP_FORMAT_ITERATOR
00049 #define FASTFORMAT_INCL_FASTFORMAT_ITERATORS_HPP_FORMAT_ITERATOR
00050
00051
00052
00053
00054
00055 #ifndef FASTFORMAT_DOCUMENTATION_SKIP_SECTION
00056 # define FASTFORMAT_VER_FASTFORMAT_ITERATORS_HPP_FORMAT_ITERATOR_MAJOR 1
00057 # define FASTFORMAT_VER_FASTFORMAT_ITERATORS_HPP_FORMAT_ITERATOR_MINOR 1
00058 # define FASTFORMAT_VER_FASTFORMAT_ITERATORS_HPP_FORMAT_ITERATOR_REVISION 1
00059 # define FASTFORMAT_VER_FASTFORMAT_ITERATORS_HPP_FORMAT_ITERATOR_EDIT 2
00060 #endif
00061
00062
00063
00064
00065
00066 #ifndef __cplusplus
00067 # error This file can only be included in C++ compilation units
00068 #endif
00069
00070
00071
00072
00073
00074 #include <fastformat/fastformat.hpp>
00075 #include <fastformat/internal/stlsoft.h>
00076 #include <fastformat/quality/contract.h>
00077
00078 #include <stlsoft/shims/access/string.hpp>
00079 #include <stlsoft/util/std/iterator_helper.hpp>
00080
00081
00082
00083
00084
00085 #if !defined(FASTFORMAT_NO_NAMESPACE)
00086 namespace fastformat
00087 {
00088 namespace iterators
00089 {
00090 #endif
00091
00092
00093
00094
00095
00096 #ifndef FASTFORMAT_DOCUMENTATION_SKIP_SECTION
00097
00098 namespace impl
00099 {
00100
00101 struct no_arg_t
00102 {};
00103
00104 template <typename T>
00105 struct ref_helper
00106 {
00107 public:
00108 static T const& get_ref(T const& t)
00109 {
00110 return t;
00111 }
00112 };
00113 struct ref_helper<no_arg_t>
00114 {
00115 static ff_char_t const* get_ref(no_arg_t const&)
00116 {
00117 static ff_char_t s_empty[] = { '\0' };
00118
00119 return s_empty;
00120 }
00121 };
00122
00123 }
00124
00125 #endif
00126
00127
00128
00129
00130
00137 template< typename S
00138 , typename F
00139 , typename A1
00140 , typename A2
00141 , typename A3
00142 , typename A4
00143 , typename A5
00144 , typename A6
00145 , typename A7
00146 , typename A8
00147 >
00148 class format_output_iterator
00149 : public stlsoft_ns_qual(iterator_base)<stlsoft_ns_qual_std(output_iterator_tag), void, void, void, void>
00150 {
00151 public:
00153 typedef format_output_iterator<S, F, A1, A2, A3, A4, A5, A6, A7, A8> class_type;
00155 typedef S sink_type;
00157 typedef F format_type;
00158 private:
00159 typedef std::basic_string<ff_char_t> string_type_;
00160
00161 private:
00162 class deref_proxy;
00163 friend class deref_proxy;
00164
00165 public:
00167 format_output_iterator(sink_type& sink, format_type const& format)
00168 : m_sink(sink)
00169 , m_format(::stlsoft::c_str_data(format), ::stlsoft::c_str_len(format))
00170 , m_n(0)
00171 , m_arg1(impl::no_arg_t())
00172 , m_arg2(impl::no_arg_t())
00173 , m_arg3(impl::no_arg_t())
00174 , m_arg4(impl::no_arg_t())
00175 , m_arg5(impl::no_arg_t())
00176 , m_arg6(impl::no_arg_t())
00177 , m_arg7(impl::no_arg_t())
00178 , m_arg8(impl::no_arg_t())
00179 {}
00181 format_output_iterator(
00182 sink_type& sink
00183 , format_type const& format
00184 , unsigned n
00185 , A1 const& arg1
00186 , A2 const& arg2 = impl::no_arg_t()
00187 , A3 const& arg3 = impl::no_arg_t()
00188 , A4 const& arg4 = impl::no_arg_t()
00189 , A5 const& arg5 = impl::no_arg_t()
00190 , A6 const& arg6 = impl::no_arg_t()
00191 , A7 const& arg7 = impl::no_arg_t()
00192 , A8 const& arg8 = impl::no_arg_t()
00193 )
00194 : m_sink(sink)
00195 , m_format(::stlsoft::c_str_data(format), ::stlsoft::c_str_len(format))
00196 , m_n(n)
00197 , m_arg1(arg1)
00198 , m_arg2(arg2)
00199 , m_arg3(arg3)
00200 , m_arg4(arg4)
00201 , m_arg5(arg5)
00202 , m_arg6(arg6)
00203 , m_arg7(arg7)
00204 , m_arg8(arg8)
00205 {}
00206
00207 private:
00211 class deref_proxy
00212 {
00213 public:
00214 deref_proxy(format_output_iterator* it)
00215 : m_it(it)
00216 {}
00217
00218 public:
00219 template <typename A>
00220 void operator =(A const& value)
00221 {
00222 m_it->invoke_(value);
00223 }
00224
00225 private:
00226 format_output_iterator* const m_it;
00227
00228 private:
00229 void operator =(deref_proxy const&);
00230 };
00231
00232 template <typename A>
00233 void invoke_(A const& value)
00234 {
00235 switch(m_n)
00236 {
00237 case 0:
00238 fmt(m_sink, m_format, value);
00239 break;
00240 case 1:
00241 fmt(m_sink, m_format, value, impl::ref_helper<A1>::get_ref(m_arg1));
00242 break;
00243 case 2:
00244 fmt(m_sink, m_format, value, impl::ref_helper<A1>::get_ref(m_arg1), impl::ref_helper<A2>::get_ref(m_arg2));
00245 break;
00246 case 3:
00247 fmt(m_sink, m_format, value, impl::ref_helper<A1>::get_ref(m_arg1), impl::ref_helper<A2>::get_ref(m_arg2), impl::ref_helper<A3>::get_ref(m_arg3));
00248 break;
00249 case 4:
00250 fmt(m_sink, m_format, value, impl::ref_helper<A1>::get_ref(m_arg1), impl::ref_helper<A2>::get_ref(m_arg2), impl::ref_helper<A3>::get_ref(m_arg3), impl::ref_helper<A4>::get_ref(m_arg4));
00251 break;
00252 case 5:
00253 fmt(m_sink, m_format, value, impl::ref_helper<A1>::get_ref(m_arg1), impl::ref_helper<A2>::get_ref(m_arg2), impl::ref_helper<A3>::get_ref(m_arg3), impl::ref_helper<A4>::get_ref(m_arg4), impl::ref_helper<A5>::get_ref(m_arg5));
00254 break;
00255 case 6:
00256 fmt(m_sink, m_format, value, impl::ref_helper<A1>::get_ref(m_arg1), impl::ref_helper<A2>::get_ref(m_arg2), impl::ref_helper<A3>::get_ref(m_arg3), impl::ref_helper<A4>::get_ref(m_arg4), impl::ref_helper<A5>::get_ref(m_arg5), impl::ref_helper<A6>::get_ref(m_arg6));
00257 break;
00258 case 7:
00259 fmt(m_sink, m_format, value, impl::ref_helper<A1>::get_ref(m_arg1), impl::ref_helper<A2>::get_ref(m_arg2), impl::ref_helper<A3>::get_ref(m_arg3), impl::ref_helper<A4>::get_ref(m_arg4), impl::ref_helper<A5>::get_ref(m_arg5), impl::ref_helper<A6>::get_ref(m_arg6), impl::ref_helper<A7>::get_ref(m_arg7));
00260 break;
00261 case 8:
00262 fmt(m_sink, m_format, value, impl::ref_helper<A1>::get_ref(m_arg1), impl::ref_helper<A2>::get_ref(m_arg2), impl::ref_helper<A3>::get_ref(m_arg3), impl::ref_helper<A4>::get_ref(m_arg4), impl::ref_helper<A5>::get_ref(m_arg5), impl::ref_helper<A6>::get_ref(m_arg6), impl::ref_helper<A7>::get_ref(m_arg7), impl::ref_helper<A8>::get_ref(m_arg8));
00263 break;
00264 }
00265 }
00266
00267 public:
00269 deref_proxy operator *()
00270 {
00271 return deref_proxy(this);
00272 }
00274 class_type& operator ++()
00275 {
00276 return *this;
00277 }
00279 class_type& operator ++(int)
00280 {
00281 return *this;
00282 }
00283
00284 private:
00285 sink_type& m_sink;
00286 const string_type_ m_format;
00287 const unsigned m_n;
00288 A1 const& m_arg1;
00289 A2 const& m_arg2;
00290 A3 const& m_arg3;
00291 A4 const& m_arg4;
00292 A5 const& m_arg5;
00293 A6 const& m_arg6;
00294 A7 const& m_arg7;
00295 A8 const& m_arg8;
00296 };
00297
00298 #ifdef FASTFORMAT_DOCUMENTATION_SKIP_SECTION
00299
00341 template< typename S
00342 , typename F
00343 , typename A1
00344 , typename A2
00345 , typename A3
00346 , typename A4
00347 , typename A5
00348 , typename A6
00349 , typename A7
00350 , typename A8
00351 >
00352 format_output_iterator<S, F, A1, A2, A3, A4, A5, A6, A7, A8> format_iterator(S& sink, F const& format, ...)
00353 {}
00354 #else
00355 template< typename S
00356 , typename F
00357 >
00358 inline format_output_iterator<S, F, impl::no_arg_t, impl::no_arg_t, impl::no_arg_t, impl::no_arg_t, impl::no_arg_t, impl::no_arg_t, impl::no_arg_t, impl::no_arg_t> format_iterator(S& sink, F const& format)
00359 {
00360 return format_output_iterator<S, F, impl::no_arg_t, impl::no_arg_t, impl::no_arg_t, impl::no_arg_t, impl::no_arg_t, impl::no_arg_t, impl::no_arg_t, impl::no_arg_t>(sink, format);
00361 }
00362 template< typename S
00363 , typename F
00364 , typename A1
00365 >
00366 inline format_output_iterator<S, F, A1, impl::no_arg_t, impl::no_arg_t, impl::no_arg_t, impl::no_arg_t, impl::no_arg_t, impl::no_arg_t, impl::no_arg_t> format_iterator(
00367 S& sink
00368 , F const& format
00369 , A1 const& arg1
00370 )
00371 {
00372 return format_output_iterator<S, F, A1, impl::no_arg_t, impl::no_arg_t, impl::no_arg_t, impl::no_arg_t, impl::no_arg_t, impl::no_arg_t, impl::no_arg_t>(sink, format, 1u, arg1);
00373 }
00374 template< typename S
00375 , typename F
00376 , typename A1
00377 , typename A2
00378 >
00379 inline format_output_iterator<S, F, A1, A2, impl::no_arg_t, impl::no_arg_t, impl::no_arg_t, impl::no_arg_t, impl::no_arg_t, impl::no_arg_t> format_iterator(
00380 S& sink
00381 , F const& format
00382 , A1 const& arg1
00383 , A2 const& arg2
00384 )
00385 {
00386 return format_output_iterator<S, F, A1, A2, impl::no_arg_t, impl::no_arg_t, impl::no_arg_t, impl::no_arg_t, impl::no_arg_t, impl::no_arg_t>(sink, format, 2u, arg1, arg2);
00387 }
00388
00389 template< typename S
00390 , typename F
00391 , typename A1
00392 , typename A2
00393 , typename A3
00394 >
00395 inline format_output_iterator<S, F, A1, A2, A3, impl::no_arg_t, impl::no_arg_t, impl::no_arg_t, impl::no_arg_t, impl::no_arg_t> format_iterator(
00396 S& sink
00397 , F const& format
00398 , A1 const& arg1
00399 , A2 const& arg2
00400 , A3 const& arg3
00401 )
00402 {
00403 return format_output_iterator<S, F, A1, A2, A3, impl::no_arg_t, impl::no_arg_t, impl::no_arg_t, impl::no_arg_t, impl::no_arg_t>(sink, format, 3u, arg1, arg2, arg3);
00404 }
00405 template< typename S
00406 , typename F
00407 , typename A1
00408 , typename A2
00409 , typename A3
00410 , typename A4
00411 >
00412 inline format_output_iterator<S, F, A1, A2, A3, A4, impl::no_arg_t, impl::no_arg_t, impl::no_arg_t, impl::no_arg_t> format_iterator(
00413 S& sink
00414 , F const& format
00415 , A1 const& arg1
00416 , A2 const& arg2
00417 , A3 const& arg3
00418 , A4 const& arg4
00419 )
00420 {
00421 return format_output_iterator<S, F, A1, A2, A3, A4, impl::no_arg_t, impl::no_arg_t, impl::no_arg_t, impl::no_arg_t>(sink, format, 4u, arg1, arg2, arg3, arg4);
00422 }
00423 template< typename S
00424 , typename F
00425 , typename A1
00426 , typename A2
00427 , typename A3
00428 , typename A4
00429 , typename A5
00430 >
00431 inline format_output_iterator<S, F, A1, A2, A3, A4, A5, impl::no_arg_t, impl::no_arg_t, impl::no_arg_t> format_iterator(
00432 S& sink
00433 , F const& format
00434 , A1 const& arg1
00435 , A2 const& arg2
00436 , A3 const& arg3
00437 , A4 const& arg4
00438 , A5 const& arg5
00439 )
00440 {
00441 return format_output_iterator<S, F, A1, A2, A3, A4, A5, impl::no_arg_t, impl::no_arg_t, impl::no_arg_t>(sink, format, 5u, arg1, arg2, arg3, arg4, arg5);
00442 }
00443 template< typename S
00444 , typename F
00445 , typename A1
00446 , typename A2
00447 , typename A3
00448 , typename A4
00449 , typename A5
00450 , typename A6
00451 >
00452 inline format_output_iterator<S, F, A1, A2, A3, A4, A5, A6, impl::no_arg_t, impl::no_arg_t> format_iterator(
00453 S& sink
00454 , F const& format
00455 , A1 const& arg1
00456 , A2 const& arg2
00457 , A3 const& arg3
00458 , A4 const& arg4
00459 , A5 const& arg5
00460 , A6 const& arg6
00461 )
00462 {
00463 return format_output_iterator<S, F, A1, A2, A3, A4, A5, A6, impl::no_arg_t, impl::no_arg_t>(sink, format, 6u, arg1, arg2, arg3, arg4, arg5, arg6);
00464 }
00465 template< typename S
00466 , typename F
00467 , typename A1
00468 , typename A2
00469 , typename A3
00470 , typename A4
00471 , typename A5
00472 , typename A6
00473 , typename A7
00474 >
00475 inline format_output_iterator<S, F, A1, A2, A3, A4, A5, A6, A7, impl::no_arg_t> format_iterator(
00476 S& sink
00477 , F const& format
00478 , A1 const& arg1
00479 , A2 const& arg2
00480 , A3 const& arg3
00481 , A4 const& arg4
00482 , A5 const& arg5
00483 , A6 const& arg6
00484 , A7 const& arg7
00485 )
00486 {
00487 return format_output_iterator<S, F, A1, A2, A3, A4, A5, A6, A7, impl::no_arg_t>(sink, format, 7u, arg1, arg2, arg3, arg4, arg5, arg6, arg7);
00488 }
00489 template< typename S
00490 , typename F
00491 , typename A1
00492 , typename A2
00493 , typename A3
00494 , typename A4
00495 , typename A5
00496 , typename A6
00497 , typename A7
00498 , typename A8
00499 >
00500 inline format_output_iterator<S, F, A1, A2, A3, A4, A5, A6, A7, A8> format_iterator(
00501 S& sink
00502 , F const& format
00503 , A1 const& arg1
00504 , A2 const& arg2
00505 , A3 const& arg3
00506 , A4 const& arg4
00507 , A5 const& arg5
00508 , A6 const& arg6
00509 , A7 const& arg7
00510 , A8 const& arg8
00511 )
00512 {
00513 return format_output_iterator<S, F, A1, A2, A3, A4, A5, A6, A7, A8>(sink, format, 8u, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
00514 }
00515 #endif
00516
00517
00518
00519
00520
00521 #if !defined(FASTFORMAT_NO_NAMESPACE)
00522 }
00523 using ::fastformat::iterators::format_iterator;
00524 }
00525 #endif
00526
00527
00528
00529
00530
00531 #ifdef STLSOFT_CF_PRAGMA_ONCE_SUPPORT
00532 # pragma once
00533 #endif
00534
00535
00536
00537 #endif
00538
00539