diff options
author | Constantin Michael <constantin@codesynthesis.com> | 2011-05-31 16:37:21 +0200 |
---|---|---|
committer | Constantin Michael <constantin@codesynthesis.com> | 2011-07-05 14:40:26 +0200 |
commit | 718c1eafff379b6d1b3c217d00d0efb9f5b16c83 (patch) | |
tree | 71da230e7ef28f8d6881fecdff9a095fc3d154f0 | |
parent | c89d2d34e27f674720c3c497bbd18a26a5bf9f38 (diff) |
Convert buffer to templated basic_buffer
-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; } } |