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
00043 #error This file is not ready
00044
00050 #ifndef FASTFORMAT_INCL_FASTFORMAT_SINK_HPP_STRING_ARRAY
00051 #define FASTFORMAT_INCL_FASTFORMAT_SINK_HPP_STRING_ARRAY
00052
00053
00054
00055
00056
00057 #ifndef FASTFORMAT_DOCUMENTATION_SKIP_SECTION
00058 # define FASTFORMAT_VER_FASTFORMAT_SINK_HPP_STRING_ARRAY_MAJOR 0
00059 # define FASTFORMAT_VER_FASTFORMAT_SINK_HPP_STRING_ARRAY_MINOR 0
00060 # define FASTFORMAT_VER_FASTFORMAT_SINK_HPP_STRING_ARRAY_REVISION 1
00061 # define FASTFORMAT_VER_FASTFORMAT_SINK_HPP_STRING_ARRAY_EDIT 3
00062 #endif
00063
00064
00065
00066
00067
00068 #ifndef __cplusplus
00069 # error This file can only be included in C++ compilation units
00070 #endif
00071
00072
00073
00074
00075
00076 #include <fastformat/fastformat.h>
00077 #include <fastformat/internal/stlsoft.h>
00078 #include <fastformat/quality/contract.h>
00079 #include <fastformat/format/standard_flags.hpp>
00080
00081 #include <platformstl/error/exceptions.hpp>
00082 #include <stlsoft/memory/auto_buffer.hpp>
00083
00084 #include <string>
00085
00086
00087
00088
00089
00090 #if !defined(FASTFORMAT_NO_NAMESPACE)
00091 namespace fastformat
00092 {
00093 namespace sinks
00094 {
00095 #endif
00096
00097
00098
00099
00100
00103 class string_array_sink
00104 {
00105 public:
00107 typedef string_array_sink class_type;
00108
00109 public:
00111 string_array_sink(int fh)
00112 : m_fh(fh)
00113 , m_delim()
00114 {}
00116 string_array_sink(int fh, char const* delim)
00117 : m_fh(fh)
00118 , m_delim(delim)
00119 {}
00120
00121 public:
00123 class_type& write(size_t numResults, ff_string_slice_t const* results, int flags)
00124 {
00125 stlsoft::auto_buffer<iovec> vectors(numResults + 2);
00126 ff_string_slice_t crlf = fastformat_getNewlineForPlatform();
00127
00128 #ifdef STLSOFT_CF_THROW_BAD_ALLOC
00129 if(!vectors.empty())
00130 #endif
00131 {
00132 STLSOFT_ASSERT(vectors.size() == numResults + 2);
00133
00134 { for(size_t i = 0; i != vectors.size() - 2; ++i)
00135 {
00136 vectors[i].iov_base = const_cast<char*>(results[i].ptr);
00137 vectors[i].iov_len = results[i].len;
00138 }}
00139
00140 if(!m_delim.empty())
00141 {
00142 vectors[vectors.size() - 2].iov_base = const_cast<char*>(m_delim.data());
00143 vectors[vectors.size() - 2].iov_len = m_delim.size();
00144 }
00145 else
00146 {
00147 vectors.resize(vectors.size() - 1);
00148 }
00149
00150 if(flags::ff_newLine & flags)
00151 {
00152 vectors[vectors.size() - 1].iov_base = const_cast<char*>(crlf.ptr);
00153 vectors[vectors.size() - 1].iov_len = crlf.len;
00154 }
00155 else
00156 {
00157 vectors.resize(vectors.size() - 1);
00158 }
00159
00160 if(::writev(m_fh, &vectors[0], static_cast<int>(vectors.size())) < 0)
00161 {
00162 #ifdef STLSOFT_CF_EXCEPTION_SUPPORT
00163 throw platformstl::platform_exception("failed to write vector payload", errno);
00164 #endif
00165 }
00166
00167 #if 0
00168 if(flags::ff_flush & flags)
00169 {
00170 ::flush(m_fh);
00171 }
00172 #endif
00173 }
00174
00175 return *this;
00176 }
00177
00178 private:
00179 int m_fh;
00180 std::string m_delim;
00181 };
00182
00183
00184
00185
00186
00190 inline string_array_sink& fmt_slices(string_array_sink& sink, int flags, size_t , size_t numResults, ff_string_slice_t const* results)
00191 {
00192 return sink.write(numResults, results, flags);
00193 }
00194
00195
00196
00197
00198
00199 #if !defined(FASTFORMAT_NO_NAMESPACE)
00200 }
00201 }
00202 #endif
00203
00204
00205
00206 #endif
00207
00208