aboutsummaryrefslogtreecommitdiff
path: root/odb/details
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2010-08-18 18:26:33 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2010-08-18 18:26:33 +0200
commitdce5d0658e67ced4d5fa64f98f598b86917927a7 (patch)
treee910d86848a672ef4d0e3977d351e21d3f633227 /odb/details
parent854af2dbb1ee01f6e1c8d4f8f513ff2bad7da4f0 (diff)
Move buffer to the details namespace
Diffstat (limited to 'odb/details')
-rw-r--r--odb/details/buffer.cxx37
-rw-r--r--odb/details/buffer.hxx59
2 files changed, 96 insertions, 0 deletions
diff --git a/odb/details/buffer.cxx b/odb/details/buffer.cxx
new file mode 100644
index 0000000..0d02460
--- /dev/null
+++ b/odb/details/buffer.cxx
@@ -0,0 +1,37 @@
+// file : odb/details/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/details/buffer.hxx>
+
+using namespace std;
+
+namespace odb
+{
+ namespace details
+ {
+ 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/details/buffer.hxx b/odb/details/buffer.hxx
new file mode 100644
index 0000000..4393114
--- /dev/null
+++ b/odb/details/buffer.hxx
@@ -0,0 +1,59 @@
+// file : odb/details/buffer.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef ODB_BUFFER_DETAILS_HXX
+#define ODB_BUFFER_DETAILS_HXX
+
+#include <new>
+#include <cstddef> // std::size_t
+
+namespace odb
+{
+ namespace details
+ {
+ class buffer
+ {
+ public:
+ ~buffer ()
+ {
+ if (data_)
+ operator delete (data_);
+ }
+
+ buffer ()
+ : capacity_ (512)
+ {
+ data_ = static_cast<char*> (operator new (capacity_));
+ }
+
+ char*
+ data ()
+ {
+ return data_;
+ }
+
+ const char*
+ data () const
+ {
+ return data_;
+ }
+
+ std::size_t
+ capacity () const
+ {
+ return capacity_;
+ }
+
+ void
+ capacity (std::size_t, std::size_t data_size = 0);
+
+ private:
+ char* data_;
+ std::size_t capacity_;
+ };
+ }
+}
+
+#endif // ODB_BUFFER_DETAILS_HXX