diff options
-rw-r--r-- | odb/details/buffer.cxx | 4 | ||||
-rw-r--r-- | 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<char*> (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<char*> (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 <typename T> + class basic_buffer: public basic_buffer_base + { + public: + + T* + data () + { + return static_cast<T*> (data_); + } + + const T* + data () const + { + return static_cast<T*> (data_); + } + }; + + typedef basic_buffer<char> buffer; + typedef basic_buffer<unsigned char> ubuffer; } } |