aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--odb/buffer.cxx34
-rw-r--r--odb/buffer.hxx27
-rw-r--r--odb/makefile1
3 files changed, 60 insertions, 2 deletions
diff --git a/odb/buffer.cxx b/odb/buffer.cxx
new file mode 100644
index 0000000..f920258
--- /dev/null
+++ b/odb/buffer.cxx
@@ -0,0 +1,34 @@
+// file : odb/buffer.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#include <cstring> // std::memcpy
+
+#include <odb/buffer.hxx>
+
+using namespace std;
+
+namespace odb
+{
+ void buffer::
+ 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)));
+
+ if (data_ != 0)
+ {
+ if (data_size != 0)
+ memcpy (d, data_, data_size);
+
+ operator delete (data_);
+ }
+
+ data_ = d;
+ capacity_ = n;
+ }
+ }
+}
diff --git a/odb/buffer.hxx b/odb/buffer.hxx
index 99482ae..2a07735 100644
--- a/odb/buffer.hxx
+++ b/odb/buffer.hxx
@@ -6,6 +6,7 @@
#ifndef ODB_BUFFER_HXX
#define ODB_BUFFER_HXX
+#include <new>
#include <cstddef> // std::size_t
namespace odb
@@ -13,10 +14,32 @@ namespace odb
class buffer
{
public:
- buffer ();
+ ~buffer ()
+ {
+ if (data_)
+ operator delete (data_);
+ }
+
+ buffer ()
+ : capacity_ (512)
+ {
+ data_ = static_cast<char*> (operator new (capacity_));
+ }
+
+ char*
+ data ()
+ {
+ return data_;
+ }
+
+ std::size_t
+ capacity () const
+ {
+ return capacity_;
+ }
void
- grow (std::size_t new_capacity, std::size_t data_size);
+ capacity (std::size_t, std::size_t data_size = 0);
private:
char* data_;
diff --git a/odb/makefile b/odb/makefile
index fdeb6ea..bae84e0 100644
--- a/odb/makefile
+++ b/odb/makefile
@@ -7,6 +7,7 @@ include $(dir $(lastword $(MAKEFILE_LIST)))../build/bootstrap.make
cxx_tun := \
shared-ptr/base.cxx \
+buffer.cxx \
exception.cxx \
exceptions.cxx \
database.cxx \