delpi
0.0.1
DElta-complete LP solver
Toggle main menu visibility
Loading...
Searching...
No Matches
intrusive_ptr.hpp
1
8
#pragma once
9
10
#include <utility>
11
12
namespace
delpi
{
13
21
template
<
class
T>
22
class
intrusive_ptr {
23
public
:
24
typedef
T
element_type
;
25
27
intrusive_ptr() :
ptr_
{nullptr} {}
28
39
explicit
intrusive_ptr
(T* p,
const
bool
add_ref =
true
) :
ptr_
{p} {
40
if
(
ptr_
&& add_ref)
ptr_
->AddRef();
41
}
42
53
intrusive_ptr
(
const
intrusive_ptr& ip) :
ptr_
{ip.
ptr_
} {
54
if
(
ptr_
)
ptr_
->AddRef();
55
}
56
60
intrusive_ptr
(intrusive_ptr&& ip) noexcept :
ptr_
{ip.ptr_} { ip.ptr_ =
nullptr
; }
61
63
~intrusive_ptr
() {
64
if
(
ptr_
)
ptr_
->Release();
65
}
66
76
intrusive_ptr&
operator=
(
const
intrusive_ptr& ip) {
77
intrusive_ptr{ip}.
swap
(*
this
);
78
return
*
this
;
79
}
80
86
intrusive_ptr&
operator=
(intrusive_ptr&& ip)
noexcept
{
87
// NOLINTNEXTLINE(runtime/explicit) per C++ standard concept definition
88
intrusive_ptr(
static_cast<
intrusive_ptr&&
>
(ip)).swap(*
this
);
89
return
*
this
;
90
}
91
100
intrusive_ptr&
operator=
(T* ptr) {
101
intrusive_ptr{ptr}.
swap
(*
this
);
102
return
*
this
;
103
}
104
106
T& operator*()
const
{
return
*
ptr_
; }
111
T* operator->()
const
{
return
ptr_
; }
113
[[nodiscard]] T* get()
const
{
return
ptr_
; }
114
116
void
reset
() { intrusive_ptr{}.swap(*
this
); }
117
123
void
swap
(intrusive_ptr& ip)
noexcept
{ std::swap(
ptr_
, ip.ptr_); }
124
131
*/
132
void
attach
(T* ptr) {
133
T*
const
temp_ptr =
ptr_
;
134
ptr_
= ptr;
135
if
(temp_ptr) temp_ptr->Release();
136
}
137
144
*/
145
T*
detach
() {
146
T*
const
pTemp =
ptr_
;
147
ptr_
=
nullptr
;
148
return
pTemp;
149
}
150
151
typedef
element_type
*
intrusive_ptr
::* bool_;
164
operator
bool_() const noexcept {
return
ptr_
? &
intrusive_ptr::ptr_
:
nullptr
; }
165
bool
operator!
()
const
{
return
ptr_
==
nullptr
; }
166
167
protected
:
168
T*
ptr_
;
169
};
170
171
}
// namespace delpi
delpi::intrusive_ptr
Pointer to a generic object that supports intrusive reference counting.
Definition
intrusive_ptr.hpp:22
delpi::intrusive_ptr::element_type
T element_type
The type this intrusive_ptr points to.
Definition
intrusive_ptr.hpp:24
delpi::intrusive_ptr::operator=
intrusive_ptr & operator=(const intrusive_ptr &ip)
Copy assignment operator.
Definition
intrusive_ptr.hpp:76
delpi::intrusive_ptr::~intrusive_ptr
~intrusive_ptr()
Destruct the intrusive_ptr object, releasing the owned pointer.
Definition
intrusive_ptr.hpp:63
delpi::intrusive_ptr::detach
T * detach()
Surrenders the reference held by an intrusive_ptr pointer.
Definition
intrusive_ptr.hpp:144
delpi::intrusive_ptr::ptr_
T * ptr_
Raw pointer to the data.
Definition
intrusive_ptr.hpp:167
delpi::intrusive_ptr::reset
void reset()
Release the owned pointer, decrementing the reference count and setting ptr_ to null.
Definition
intrusive_ptr.hpp:115
delpi::intrusive_ptr::intrusive_ptr
intrusive_ptr(T *p, const bool add_ref=true)
Construct a new intrusive_ptr object wrapping the given pointer p.
Definition
intrusive_ptr.hpp:39
delpi::intrusive_ptr::operator=
intrusive_ptr & operator=(intrusive_ptr &&ip) noexcept
Move assignment operator.
Definition
intrusive_ptr.hpp:86
delpi::intrusive_ptr::swap
void swap(intrusive_ptr &ip) noexcept
Exchanges the owned pointer between two intrusive_ptr objects.
Definition
intrusive_ptr.hpp:122
delpi::intrusive_ptr::attach
void attach(T *ptr)
Sets the owned pointer to the given pointer ptr without incrementing the reference count.
Definition
intrusive_ptr.hpp:131
delpi::intrusive_ptr::intrusive_ptr
intrusive_ptr(intrusive_ptr &&ip) noexcept
Construct a new intrusive_ptr object from another intrusive_ptr object using move semantics.
Definition
intrusive_ptr.hpp:60
delpi::intrusive_ptr::operator=
intrusive_ptr & operator=(T *ptr)
Copy assignment operator.
Definition
intrusive_ptr.hpp:100
delpi::intrusive_ptr::intrusive_ptr
intrusive_ptr(const intrusive_ptr &ip)
Construct a new intrusive_ptr object from another intrusive_ptr object.
Definition
intrusive_ptr.hpp:53
delpi
Global namespace for the delpi library.
delpi::operator!
LpRowSense operator!(const LpRowSense sense)
Invert the sense with delta == 0.
Definition
LpRowSense.cpp:59
delpi
util
intrusive_ptr.hpp
Generated by
1.17.0