mirror of
https://github.com/enduro2d/enduro2d.git
synced 2025-12-15 08:15:38 +07:00
more buffer_view using
This commit is contained in:
@@ -27,6 +27,9 @@ namespace e2d
|
|||||||
template < typename T >
|
template < typename T >
|
||||||
buffer_view(const vector<T>& buffer) noexcept;
|
buffer_view(const vector<T>& buffer) noexcept;
|
||||||
|
|
||||||
|
template < typename Char >
|
||||||
|
buffer_view(const basic_string<Char>& buffer) noexcept;
|
||||||
|
|
||||||
template < typename T, std::size_t N >
|
template < typename T, std::size_t N >
|
||||||
buffer_view(const std::array<T,N>& buffer) noexcept;
|
buffer_view(const std::array<T,N>& buffer) noexcept;
|
||||||
|
|
||||||
@@ -57,6 +60,11 @@ namespace e2d
|
|||||||
: data_(buffer.data())
|
: data_(buffer.data())
|
||||||
, size_(buffer.size() * sizeof(T)) {}
|
, size_(buffer.size() * sizeof(T)) {}
|
||||||
|
|
||||||
|
template < typename Char >
|
||||||
|
buffer_view::buffer_view(const basic_string<Char>& buffer) noexcept
|
||||||
|
: data_(buffer.data())
|
||||||
|
, size_(buffer.size() * sizeof(Char)) {}
|
||||||
|
|
||||||
template < typename T, std::size_t N >
|
template < typename T, std::size_t N >
|
||||||
buffer_view::buffer_view(const std::array<T,N>& buffer) noexcept
|
buffer_view::buffer_view(const std::array<T,N>& buffer) noexcept
|
||||||
: data_(buffer.data())
|
: data_(buffer.data())
|
||||||
|
|||||||
@@ -7,6 +7,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "_utils.hpp"
|
#include "_utils.hpp"
|
||||||
|
|
||||||
|
#include "buffer.hpp"
|
||||||
|
#include "buffer_view.hpp"
|
||||||
#include "streams.hpp"
|
#include "streams.hpp"
|
||||||
|
|
||||||
namespace e2d
|
namespace e2d
|
||||||
@@ -73,9 +76,7 @@ namespace e2d::filesystem
|
|||||||
|
|
||||||
bool try_read_all(str& dst, str_view path) noexcept;
|
bool try_read_all(str& dst, str_view path) noexcept;
|
||||||
bool try_read_all(buffer& dst, str_view path) noexcept;
|
bool try_read_all(buffer& dst, str_view path) noexcept;
|
||||||
|
bool try_write_all(buffer_view src, str_view path, bool append) noexcept;
|
||||||
bool try_write_all(const str& src, str_view path, bool append) noexcept;
|
|
||||||
bool try_write_all(const buffer& src, str_view path, bool append) noexcept;
|
|
||||||
|
|
||||||
enum class predef_path {
|
enum class predef_path {
|
||||||
home,
|
home,
|
||||||
|
|||||||
@@ -8,6 +8,9 @@
|
|||||||
|
|
||||||
#include "_utils.hpp"
|
#include "_utils.hpp"
|
||||||
|
|
||||||
|
#include "buffer.hpp"
|
||||||
|
#include "buffer_view.hpp"
|
||||||
|
|
||||||
namespace e2d
|
namespace e2d
|
||||||
{
|
{
|
||||||
class bad_stream_operation final : public exception {
|
class bad_stream_operation final : public exception {
|
||||||
@@ -78,8 +81,7 @@ namespace e2d
|
|||||||
|
|
||||||
output_sequence& seek(std::ptrdiff_t offset, bool relative) noexcept;
|
output_sequence& seek(std::ptrdiff_t offset, bool relative) noexcept;
|
||||||
output_sequence& write(const void* src, std::size_t size) noexcept;
|
output_sequence& write(const void* src, std::size_t size) noexcept;
|
||||||
output_sequence& write_all(const str& src) noexcept;
|
output_sequence& write_all(buffer_view src) noexcept;
|
||||||
output_sequence& write_all(const buffer& src) noexcept;
|
|
||||||
|
|
||||||
output_sequence& flush() noexcept;
|
output_sequence& flush() noexcept;
|
||||||
output_sequence& flush_if(bool yesno) noexcept;
|
output_sequence& flush_if(bool yesno) noexcept;
|
||||||
@@ -112,11 +114,7 @@ namespace e2d::streams
|
|||||||
const input_stream_uptr& stream) noexcept;
|
const input_stream_uptr& stream) noexcept;
|
||||||
|
|
||||||
bool try_write_tail(
|
bool try_write_tail(
|
||||||
const str& src,
|
buffer_view src,
|
||||||
const output_stream_uptr& stream) noexcept;
|
|
||||||
|
|
||||||
bool try_write_tail(
|
|
||||||
const buffer& src,
|
|
||||||
const output_stream_uptr& stream) noexcept;
|
const output_stream_uptr& stream) noexcept;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -105,12 +105,7 @@ namespace e2d::filesystem
|
|||||||
dst, make_read_file(path));
|
dst, make_read_file(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool try_write_all(const str& src, str_view path, bool append) noexcept {
|
bool try_write_all(buffer_view src, str_view path, bool append) noexcept {
|
||||||
return streams::try_write_tail(
|
|
||||||
src, make_write_file(path, append));
|
|
||||||
}
|
|
||||||
|
|
||||||
bool try_write_all(const buffer& src, str_view path, bool append) noexcept {
|
|
||||||
return streams::try_write_tail(
|
return streams::try_write_tail(
|
||||||
src, make_write_file(path, append));
|
src, make_write_file(path, append));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
#include <enduro2d/utils/streams.hpp>
|
#include <enduro2d/utils/streams.hpp>
|
||||||
#include <enduro2d/utils/buffer.hpp>
|
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
@@ -171,18 +170,12 @@ namespace e2d
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
output_sequence& output_sequence::write_all(const buffer& src) noexcept {
|
output_sequence& output_sequence::write_all(buffer_view src) noexcept {
|
||||||
return success_
|
return success_
|
||||||
? write(src.data(), src.size())
|
? write(src.data(), src.size())
|
||||||
: *this;
|
: *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
output_sequence& output_sequence::write_all(const str& src) noexcept {
|
|
||||||
return success_
|
|
||||||
? write(src.c_str(), src.size())
|
|
||||||
: *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
output_sequence& output_sequence::flush() noexcept {
|
output_sequence& output_sequence::flush() noexcept {
|
||||||
try {
|
try {
|
||||||
if ( success_ ) {
|
if ( success_ ) {
|
||||||
@@ -229,15 +222,7 @@ namespace e2d::streams
|
|||||||
: false;
|
: false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool try_write_tail(const str& src, const output_stream_uptr& stream) noexcept {
|
bool try_write_tail(buffer_view src, const output_stream_uptr& stream) noexcept {
|
||||||
return stream
|
|
||||||
? output_sequence(*stream)
|
|
||||||
.write_all(src)
|
|
||||||
.success()
|
|
||||||
: false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool try_write_tail(const buffer& src, const output_stream_uptr& stream) noexcept {
|
|
||||||
return stream
|
return stream
|
||||||
? output_sequence(*stream)
|
? output_sequence(*stream)
|
||||||
.write_all(src)
|
.write_all(src)
|
||||||
|
|||||||
@@ -220,6 +220,11 @@ TEST_CASE("buffer_view") {
|
|||||||
buffer_view v5(b2);
|
buffer_view v5(b2);
|
||||||
REQUIRE(v5.data() == b2.data());
|
REQUIRE(v5.data() == b2.data());
|
||||||
REQUIRE(v5.size() == 20);
|
REQUIRE(v5.size() == 20);
|
||||||
|
|
||||||
|
str32 b3 = make_utf32("hello");
|
||||||
|
buffer_view v6(b3);
|
||||||
|
REQUIRE(v6.data() == b3.data());
|
||||||
|
REQUIRE(v6.size() == 20);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
const char* s0 = "hell";
|
const char* s0 = "hell";
|
||||||
|
|||||||
Reference in New Issue
Block a user