From 718c1eafff379b6d1b3c217d00d0efb9f5b16c83 Mon Sep 17 00:00:00 2001 From: Constantin Michael Date: Tue, 31 May 2011 16:37:21 +0200 Subject: Convert buffer to templated basic_buffer --- odb/details/buffer.cxx | 4 ++-- odb/details/buffer.hxx | 50 +++++++++++++++++++++++++++++--------------------- 2 files changed, 31 insertions(+), 23 deletions(-) diff --git a/odb/details/buffer.cxx b/odb/details/buffer.cxx index ea5b7a1..af863a9 100644 --- a/odb/details/buffer.cxx +++ b/odb/details/buffer.cxx @@ -13,13 +13,13 @@ namespace odb { namespace details { - void buffer:: + void basic_buffer_base:: capacity (size_t c, size_t data_size) { if (c > capacity_) { size_t n (capacity_ * 2 > c ? capacity_ * 2 : c); - char* d (static_cast (operator new (n))); + void* d (operator new (n)); if (data_ != 0) { diff --git a/odb/details/buffer.hxx b/odb/details/buffer.hxx index d19c06d..28c9cfa 100644 --- a/odb/details/buffer.hxx +++ b/odb/details/buffer.hxx @@ -17,31 +17,19 @@ namespace odb { namespace details { - class LIBODB_EXPORT buffer + class LIBODB_EXPORT basic_buffer_base { public: - ~buffer () + ~basic_buffer_base () { if (data_) operator delete (data_); } - buffer () - : capacity_ (512) + basic_buffer_base () + : capacity_ (512) { - data_ = static_cast (operator new (capacity_)); - } - - char* - data () - { - return data_; - } - - const char* - data () const - { - return data_; + data_ = operator new (capacity_); } std::size_t @@ -50,13 +38,33 @@ namespace odb return capacity_; } - void - capacity (std::size_t, std::size_t data_size = 0); + void capacity (std::size_t, std::size_t data_size = 0); - private: - char* data_; + protected: + void* data_; std::size_t capacity_; }; + + template + class basic_buffer: public basic_buffer_base + { + public: + + T* + data () + { + return static_cast (data_); + } + + const T* + data () const + { + return static_cast (data_); + } + }; + + typedef basic_buffer buffer; + typedef basic_buffer ubuffer; } } -- cgit v1.1