buffer -> basic_buffer

This commit is contained in:
Victor Zverovich 2017-02-14 12:08:37 -05:00
parent bb1c82ef7d
commit 6e568f3a08
6 changed files with 28 additions and 28 deletions

View File

@ -587,16 +587,16 @@ inline T *make_ptr(T *ptr, std::size_t) { return ptr; }
\endrst
*/
template <typename T>
class buffer {
class basic_buffer {
private:
FMT_DISALLOW_COPY_AND_ASSIGN(buffer);
FMT_DISALLOW_COPY_AND_ASSIGN(basic_buffer);
protected:
T *ptr_;
std::size_t size_;
std::size_t capacity_;
buffer(T *ptr = 0, std::size_t capacity = 0)
basic_buffer(T *ptr = 0, std::size_t capacity = 0)
: ptr_(ptr), size_(0), capacity_(capacity) {}
/**
@ -608,7 +608,7 @@ class buffer {
virtual void grow(std::size_t size) = 0;
public:
virtual ~buffer() {}
virtual ~basic_buffer() {}
/** Returns the size of this buffer. */
std::size_t size() const { return size_; }
@ -653,7 +653,7 @@ class buffer {
template <typename T>
template <typename U>
void buffer<T>::append(const U *begin, const U *end) {
void basic_buffer<T>::append(const U *begin, const U *end) {
std::size_t new_size = size_ + internal::to_unsigned(end - begin);
if (new_size > capacity_)
grow(new_size);
@ -667,7 +667,7 @@ namespace internal {
// A memory buffer for trivially copyable/constructible types with the first
// SIZE elements stored in the object itself.
template <typename T, std::size_t SIZE, typename Allocator = std::allocator<T> >
class MemoryBuffer : private Allocator, public buffer<T> {
class MemoryBuffer : private Allocator, public basic_buffer<T> {
private:
T data_[SIZE];
@ -681,7 +681,7 @@ class MemoryBuffer : private Allocator, public buffer<T> {
public:
explicit MemoryBuffer(const Allocator &alloc = Allocator())
: Allocator(alloc), buffer<T>(data_, SIZE) {}
: Allocator(alloc), basic_buffer<T>(data_, SIZE) {}
~MemoryBuffer() { deallocate(); }
#if FMT_USE_RVALUE_REFERENCES
@ -743,10 +743,10 @@ void MemoryBuffer<T, SIZE, Allocator>::grow(std::size_t size) {
// A fixed-size buffer.
template <typename Char>
class FixedBuffer : public fmt::buffer<Char> {
class FixedBuffer : public fmt::basic_buffer<Char> {
public:
FixedBuffer(Char *array, std::size_t size)
: fmt::buffer<Char>(array, size) {}
: fmt::basic_buffer<Char>(array, size) {}
protected:
FMT_API void grow(std::size_t size);
@ -2199,7 +2199,7 @@ class basic_writer {
private:
// Output buffer.
fmt::buffer<Char> &buffer_;
basic_buffer<Char> &buffer_;
FMT_DISALLOW_COPY_AND_ASSIGN(basic_writer);
@ -2302,7 +2302,7 @@ class basic_writer {
/**
Constructs a ``basic_writer`` object.
*/
explicit basic_writer(fmt::buffer<Char> &b) : buffer_(b) {}
explicit basic_writer(basic_buffer<Char> &b) : buffer_(b) {}
public:
/**
@ -2443,7 +2443,7 @@ class basic_writer {
void clear() FMT_NOEXCEPT { buffer_.clear(); }
fmt::buffer<Char> &buffer() FMT_NOEXCEPT { return buffer_; }
basic_buffer<Char> &buffer() FMT_NOEXCEPT { return buffer_; }
};
template <typename Char>

View File

@ -23,11 +23,11 @@ class FormatBuf : public std::basic_streambuf<Char> {
typedef typename std::basic_streambuf<Char>::int_type int_type;
typedef typename std::basic_streambuf<Char>::traits_type traits_type;
buffer<Char> &buffer_;
basic_buffer<Char> &buffer_;
Char *start_;
public:
FormatBuf(buffer<Char> &buffer) : buffer_(buffer), start_(&buffer[0]) {
FormatBuf(basic_buffer<Char> &buffer) : buffer_(buffer), start_(&buffer[0]) {
this->setp(start_, start_ + buffer_.capacity());
}

View File

@ -18,7 +18,7 @@ namespace internal {
// A buffer that stores data in ``std::string``.
template <typename Char>
class StringBuffer : public buffer<Char> {
class StringBuffer : public basic_buffer<Char> {
private:
std::basic_string<Char> data_;

View File

@ -27,7 +27,7 @@ void format_value(writer &w, const std::tm &tm, context &ctx) {
internal::MemoryBuffer<char, internal::INLINE_BUFFER_SIZE> format;
format.append(s, end + 1);
format[format.size() - 1] = '\0';
buffer<char> &buffer = w.buffer();
basic_buffer<char> &buffer = w.buffer();
std::size_t start = buffer.size();
for (;;) {
std::size_t size = buffer.capacity() - start;

View File

@ -135,7 +135,7 @@ TEST(OStreamTest, WriteToOStreamMaxSize) {
class TestWriter : public fmt::basic_writer<char> {
private:
struct TestBuffer : fmt::buffer<char> {
struct TestBuffer : fmt::basic_buffer<char> {
explicit TestBuffer(std::size_t size) { size_ = size; }
void grow(std::size_t) {}
} buffer_;

View File

@ -53,7 +53,7 @@
#undef max
using fmt::basic_arg;
using fmt::buffer;
using fmt::basic_buffer;
using fmt::StringRef;
using fmt::internal::MemoryBuffer;
using fmt::internal::value;
@ -106,24 +106,24 @@ TEST(AllocatorTest, AllocatorRef) {
#if FMT_USE_TYPE_TRAITS
TEST(BufferTest, Noncopyable) {
EXPECT_FALSE(std::is_copy_constructible<buffer<char> >::value);
EXPECT_FALSE(std::is_copy_assignable<buffer<char> >::value);
EXPECT_FALSE(std::is_copy_constructible<basic_buffer<char> >::value);
EXPECT_FALSE(std::is_copy_assignable<basic_buffer<char> >::value);
}
TEST(BufferTest, Nonmoveable) {
EXPECT_FALSE(std::is_move_constructible<buffer<char> >::value);
EXPECT_FALSE(std::is_move_assignable<buffer<char> >::value);
EXPECT_FALSE(std::is_move_constructible<basic_buffer<char> >::value);
EXPECT_FALSE(std::is_move_assignable<basic_buffer<char> >::value);
}
#endif
// A test buffer with a dummy grow method.
template <typename T>
struct TestBuffer : buffer<T> {
struct TestBuffer : basic_buffer<T> {
void grow(std::size_t size) { this->capacity_ = size; }
};
template <typename T>
struct MockBuffer : buffer<T> {
struct MockBuffer : basic_buffer<T> {
MOCK_METHOD1(do_grow, void (std::size_t size));
void grow(std::size_t size) {
@ -132,8 +132,8 @@ struct MockBuffer : buffer<T> {
}
MockBuffer() {}
MockBuffer(T *ptr) : buffer<T>(ptr) {}
MockBuffer(T *ptr, std::size_t capacity) : buffer<T>(ptr, capacity) {}
MockBuffer(T *ptr) : basic_buffer<T>(ptr) {}
MockBuffer(T *ptr, std::size_t capacity) : basic_buffer<T>(ptr, capacity) {}
};
TEST(BufferTest, Ctor) {
@ -169,7 +169,7 @@ TEST(BufferTest, VirtualDtor) {
typedef StrictMock<DyingBuffer> StictMockBuffer;
StictMockBuffer *mock_buffer = new StictMockBuffer();
EXPECT_CALL(*mock_buffer, die());
buffer<int> *buffer = mock_buffer;
basic_buffer<int> *buffer = mock_buffer;
delete buffer;
}
@ -180,7 +180,7 @@ TEST(BufferTest, Access) {
EXPECT_EQ(11, buffer[0]);
buffer[3] = 42;
EXPECT_EQ(42, *(&buffer[0] + 3));
const fmt::buffer<char> &const_buffer = buffer;
const fmt::basic_buffer<char> &const_buffer = buffer;
EXPECT_EQ(42, const_buffer[3]);
}