コード例 #1
0
    /// Writes the results, according to the given flags
    class_type& write(size_t numResults, ff_string_slice_t const* results, int flags)
    {
        stlsoft::auto_buffer<iovec>     vectors(numResults + 2);
        ff_string_slice_t               crlf = fastformat_getNewlineForPlatform();

#ifdef STLSOFT_CF_THROW_BAD_ALLOC
        if(!vectors.empty())
#endif /* STLSOFT_CF_THROW_BAD_ALLOC */
        {
            STLSOFT_ASSERT(vectors.size() == numResults + 2);

            { for(size_t i = 0; i != vectors.size() - 2; ++i)
            {
                vectors[i].iov_base =   const_cast<char*>(results[i].ptr);
                vectors[i].iov_len  =   results[i].len;
            }}

            if(!m_delim.empty())
            {
                vectors[vectors.size() - 2].iov_base    =   const_cast<char*>(m_delim.data());
                vectors[vectors.size() - 2].iov_len     =   m_delim.size();
            }
            else
            {
                vectors.resize(vectors.size() - 1);
            }

            if(flags::ff_newLine & flags)
            {
                vectors[vectors.size() - 1].iov_base    =   const_cast<char*>(crlf.ptr);
                vectors[vectors.size() - 1].iov_len     =   crlf.len;
            }
            else
            {
                vectors.resize(vectors.size() - 1);
            }

            if(::writev(m_fh, &vectors[0], static_cast<int>(vectors.size())) < 0)
            {
#ifdef STLSOFT_CF_EXCEPTION_SUPPORT
                throw platformstl::platform_exception("failed to write vector payload", errno);
#endif /* STLSOFT_CF_EXCEPTION_SUPPORT */
            }

#if 0
            if(flags::ff_flush & flags)
            {
                ::flush(m_fh);
            }
#endif /* 0 */
        }

        return *this;
    }
コード例 #2
0
ファイル: char_buffer.hpp プロジェクト: JerYme/fastformat
    /// Outputs the results, according to the given flags
    class_type& write(size_type cchTotal, size_type numResults, ff_string_slice_t const* results, int flags)
    {
        const ff_string_slice_t crlf            =   fastformat_getNewlineForPlatform();

        const size_type         requiredSize    =   size()
                                                    +   cchTotal
                                                    +   ((flags::ff_newLine & flags) ? crlf.len : 0)
                                                    ;

        if(requiredSize > capacity())
        {
            throw std::out_of_range("character buffer sink capacity exceeded");
        }
        else
        {
            char_type* p = &m_buffer[0] + size();

            // next we concatenate all the slices

            { for(size_type i = 0; i < numResults; ++i)
            {
                ff_string_slice_t const& slice = results[i];

                ::memcpy(p, slice.ptr, slice.len * sizeof(char_type));
                p += slice.len;
            }}

            m_len += cchTotal;

            // then append the new line, if required

            if(flags::ff_newLine & flags)
            {
                ::memcpy(p, crlf.ptr, crlf.len * sizeof(char_type));
                p += crlf.len;

                m_len += crlf.len;
            }

            FASTFORMAT_CONTRACT_ENFORCE_POSTCONDITION_STATE_APPL_LAYER(p == &m_buffer[0] + size(), "char_buffer sink writing logic failed: write pointer in wrong place");
        }

        return *this;
    }