diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2024-01-24 16:53:38 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2024-01-24 16:53:38 +0300 |
commit | 26e36b3a9d7b49d46ecfa69b447482251acba8ac (patch) | |
tree | 5436b7857fae9aee50d018ea0eef35a529fc03e4 /libodb/odb/details/buffer.hxx | |
parent | 0074faad1b27f3cd52a606c438e4f1375956d731 (diff) |
Turn libodb repository into package for muti-package repositorylibodb
Diffstat (limited to 'libodb/odb/details/buffer.hxx')
-rw-r--r-- | libodb/odb/details/buffer.hxx | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/libodb/odb/details/buffer.hxx b/libodb/odb/details/buffer.hxx new file mode 100644 index 0000000..558be9b --- /dev/null +++ b/libodb/odb/details/buffer.hxx @@ -0,0 +1,92 @@ +// file : odb/details/buffer.hxx +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_BUFFER_DETAILS_HXX +#define ODB_BUFFER_DETAILS_HXX + +#include <odb/pre.hxx> + +#include <new> +#include <cstddef> // std::size_t + +#include <odb/details/export.hxx> + +namespace odb +{ + namespace details + { + class LIBODB_EXPORT basic_buffer_base + { + public: + ~basic_buffer_base () + { + if (data_ != 0) + operator delete (data_); + } + + basic_buffer_base (std::size_t capacity) + : capacity_ (capacity) + { + data_ = capacity_ == 0 ? 0 : operator new (capacity_); + } + + std::size_t + capacity () const + { + return capacity_; + } + + void + capacity (std::size_t, std::size_t data_size = 0); + + protected: + void* data_; + std::size_t capacity_; + }; + + template <typename T> + class basic_buffer: public basic_buffer_base + { + public: + basic_buffer (std::size_t capacity = 256) + : basic_buffer_base (capacity) + { + } + + T* + data () + { + return static_cast<T*> (data_); + } + + const T* + data () const + { + return static_cast<T*> (data_); + } + + // Note that strictly speaking the return type should be void* const* + // but that would make using this function too awkward since we often + // store the result as void*. + // + void** + data_ptr () + { + return &data_; + } + + const void* const* + data_ptr () const + { + return &data_; + } + }; + + typedef basic_buffer<char> buffer; + typedef basic_buffer<unsigned char> ubuffer; + } +} + +#include <odb/post.hxx> + +#endif // ODB_BUFFER_DETAILS_HXX |