New ostream() returns dynamic buffer output stream (API Change):

This eliminates beast::write output for dynamic buffers and replaces
it with the function ostream() that wraps a caller provided dynamic
buffer and returns the result as a std::ostream derived object.
Callers may now produce formatted output into any object meeting the
requirements of DynamicBuffer using operator<< and the standard stream
modifiers such as std::endl.

This new technique is more efficient, as implementations of operator<<
can now write directly into the output using std::ostream::write and
std::ostream::put.

Example of use:

  beast::streambuf sb;
  beast::ostream(sb) << "Hello, world!" << std::endl;
This commit is contained in:
Vinnie Falco committed 2017-07-20 08:12:16 -07:00
1 parent 3f58d81fc4
commit 3add5f293c
16 files changed
+373 -337

No files matched your search

+1 -1
View File
@@ -22,6 +22,7 @@ add_executable (core-tests
handler_alloc.cpp
handler_concepts.cpp
handler_ptr.cpp
ostream.cpp
placeholders.cpp
prepare_buffer.cpp
prepare_buffers.cpp
@@ -30,7 +31,6 @@ add_executable (core-tests
stream_concepts.cpp
streambuf.cpp
to_string.cpp
write_dynabuf.cpp
base64.cpp
empty_base_optimization.cpp
get_lowest_layer.cpp
+32
View File
@@ -0,0 +1,32 @@
//
// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Test that header file is self-contained.
#include <beast/core/ostream.hpp>
#include <beast/core/streambuf.hpp>
#include <beast/unit_test/suite.hpp>
#include <ostream>
#include <beast/core/to_string.hpp>
namespace beast {
class ostream_test : public beast::unit_test::suite
{
public:
void run() override
{
streambuf sb;
ostream(sb) << "Hello, world!\n";
BEAST_EXPECT(to_string(sb.data()) == "Hello, world!\n");
}
};
BEAST_DEFINE_TESTSUITE(ostream,core,beast);
} // beast
-8
View File
@@ -273,13 +273,6 @@ public:
BEAST_EXPECT(test::buffer_count(sb.data()) == 4);
}
void testOutputStream()
{
streambuf sb;
sb << "x";
BEAST_EXPECT(to_string(sb.data()) == "x");
}
void testCapacity()
{
using boost::asio::buffer_size;
@@ -353,7 +346,6 @@ public:
testConsume();
testMatrix();
testIterators();
testOutputStream();
testCapacity();
}
};
-36
View File
@@ -1,36 +0,0 @@
//
// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Test that header file is self-contained.
#include <beast/core/write_dynabuf.hpp>
#include <beast/core/streambuf.hpp>
#include <beast/unit_test/suite.hpp>
namespace beast {
class write_dynabuf_test : public beast::unit_test::suite
{
public:
void run() override
{
streambuf sb;
std::string s;
write(sb, boost::asio::const_buffer{"", 0});
write(sb, boost::asio::mutable_buffer{nullptr, 0});
write(sb, boost::asio::null_buffers{});
write(sb, boost::asio::const_buffers_1{"", 0});
write(sb, boost::asio::mutable_buffers_1{nullptr, 0});
write(sb, s);
write(sb, 23);
pass();
}
};
BEAST_DEFINE_TESTSUITE(write_dynabuf,core,beast);
} // beast