aboutsummaryrefslogtreecommitdiff
path: root/odb/buffer.hxx
blob: 4f4ce0b9af5483cf263efc51e9bbe1958aa79c6f (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
// file      : odb/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_HXX
#define ODB_BUFFER_HXX

#include <new>
#include <cstddef> // std::size_t

namespace odb
{
  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_HXX