aboutsummaryrefslogtreecommitdiff
path: root/odb/shared-ptr/base.hxx
blob: 8c1b62b1c5623ef33727584d3a84850e3669fd6d (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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// file      : odb/shared-ptr/base.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_SHARED_PTR_BASE_HXX
#define ODB_SHARED_PTR_BASE_HXX

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

#include <odb/exception.hxx>

namespace odb
{
  struct share
  {
    explicit
    share (char id);

    bool
    operator== (share) const;

  private:
    char id_;
  };
}

extern odb::share shared;
extern odb::share exclusive;

void*
operator new (std::size_t, odb::share) throw (std::bad_alloc);

void
operator delete (void*, odb::share) throw ();

namespace odb
{
  struct not_shared: exception
  {
    virtual char const*
    what () const throw ();
  };

  struct shared_base
  {
    shared_base ();
    shared_base (shared_base const&);
    shared_base&
    operator= (shared_base const&);

    void
    _inc_ref ();

    bool
    _dec_ref ();

    std::size_t
    _ref_count () const;

    void*
    operator new (std::size_t, share) throw (std::bad_alloc);

    void
    operator delete (void*, share) throw ();

    void
    operator delete (void*) throw ();

  protected:
    std::size_t counter_;
  };

  template <typename X>
  inline X*
  inc_ref (X*);

  template <typename X>
  inline void
  dec_ref (X*);

  template <typename X>
  inline std::size_t
  ref_count (X const*);
}

#include <odb/shared-ptr/base.ixx>
#include <odb/shared-ptr/base.txx>

#endif // ODB_SHARED_PTR_BASE_HXX