From 74bd3bbc7edf0c067ba9eafe51b463d2e0e121bd Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 28 Mar 2011 11:40:14 +0200 Subject: Factor out common buffer implementation --- mysql/types/test.hxx | 81 ++------------------------------------------------ mysql/types/traits.hxx | 2 +- 2 files changed, 3 insertions(+), 80 deletions(-) (limited to 'mysql') diff --git a/mysql/types/test.hxx b/mysql/types/test.hxx index 80d1423..207d8b3 100644 --- a/mysql/types/test.hxx +++ b/mysql/types/test.hxx @@ -9,11 +9,11 @@ #include #include #include // std::auto_ptr -#include // std::size_t -#include // std::{memcmp,memcpy} #include +#include + struct date_time { date_time () @@ -59,83 +59,6 @@ struct date_time unsigned int second; }; -struct buffer -{ - ~buffer () - { - delete[] data_; - } - - buffer () - : data_ (0), size_ (0) - { - } - - buffer (const void* data, std::size_t size) - : data_ (0), size_ (size) - { - data_ = new char[size_]; - std::memcpy (data_, data, size_); - } - - buffer (const buffer& y) - : data_ (0), size_ (0) - { - assign (y.data_, y.size_); - } - - buffer& - operator= (const buffer& y) - { - if (this != &y) - assign (y.data_, y.size_); - - return *this; - } - - void - assign (const void* data, std::size_t size) - { - if (size_ < size) - { - char* p (new char[size]); - delete[] data_; - data_ = p; - } - - std::memcpy (data_, data, size); - size_ = size; - } - - char* - data () - { - return data_; - } - - const char* - data () const - { - return data_; - } - - std::size_t - size () const - { - return size_; - } - - bool - operator== (const buffer& y) const - { - return size_ == y.size_ && std::memcmp (data_, y.data_, size_) == 0; - } - -private: - char* data_; - std::size_t size_; -}; - struct bitfield { unsigned int a: 1; diff --git a/mysql/types/traits.hxx b/mysql/types/traits.hxx index df105e7..b05b2c4 100644 --- a/mysql/types/traits.hxx +++ b/mysql/types/traits.hxx @@ -10,7 +10,7 @@ #include -#include "test.hxx" // date_time, buffer +#include "test.hxx" // date_time, buffer, string_ptr namespace odb { -- cgit v1.1