blob: da868d0622f829a473a77135ab4767fe42d2158f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
// file : odb/details/buffer.hxx
// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC
// 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_);
}
};
typedef basic_buffer<char> buffer;
typedef basic_buffer<unsigned char> ubuffer;
}
}
#include <odb/post.hxx>
#endif // ODB_BUFFER_DETAILS_HXX
|