Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
Actor Framework
Commits
165b3e03
Commit
165b3e03
authored
Feb 09, 2015
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use `intrusive_ptr_*` functions properly
parent
1dfbd621
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
19 deletions
+30
-19
libcaf_core/caf/intrusive_ptr.hpp
libcaf_core/caf/intrusive_ptr.hpp
+30
-19
No files found.
libcaf_core/caf/intrusive_ptr.hpp
View file @
165b3e03
...
...
@@ -25,6 +25,7 @@
#include <stdexcept>
#include <type_traits>
#include "caf/ref_counted.hpp"
#include "caf/detail/comparable.hpp"
namespace
caf
{
...
...
@@ -37,9 +38,7 @@ template <class T>
class
intrusive_ptr
:
detail
::
comparable
<
intrusive_ptr
<
T
>>
,
detail
::
comparable
<
intrusive_ptr
<
T
>
,
const
T
*>
,
detail
::
comparable
<
intrusive_ptr
<
T
>
,
std
::
nullptr_t
>
{
public:
using
pointer
=
T
*
;
using
const_pointer
=
const
T
*
;
using
element_type
=
T
;
...
...
@@ -70,11 +69,11 @@ class intrusive_ptr : detail::comparable<intrusive_ptr<T>>,
~
intrusive_ptr
()
{
if
(
m_ptr
)
{
m_ptr
->
deref
(
);
intrusive_ptr_release
(
m_ptr
);
}
}
inline
void
swap
(
intrusive_ptr
&
other
)
{
void
swap
(
intrusive_ptr
&
other
)
{
std
::
swap
(
m_ptr
,
other
.
m_ptr
);
}
...
...
@@ -92,7 +91,7 @@ class intrusive_ptr : detail::comparable<intrusive_ptr<T>>,
auto
old
=
m_ptr
;
set_ptr
(
new_value
,
add_ref
);
if
(
old
)
{
old
->
deref
(
);
intrusive_ptr_release
(
old
);
}
}
...
...
@@ -124,22 +123,35 @@ class intrusive_ptr : detail::comparable<intrusive_ptr<T>>,
return
*
this
;
}
inline
pointer
get
()
const
{
return
m_ptr
;
}
inline
pointer
operator
->
()
const
{
return
m_ptr
;
}
inline
reference
operator
*
()
const
{
return
*
m_ptr
;
}
pointer
get
()
const
{
return
m_ptr
;
}
pointer
operator
->
()
const
{
return
m_ptr
;
}
reference
operator
*
()
const
{
return
*
m_ptr
;
}
inline
bool
operator
!
()
const
{
return
m_ptr
==
nullptr
;
}
inline
explicit
operator
bool
()
const
{
return
m_ptr
!=
nullptr
;
}
bool
operator
!
()
const
{
return
m_ptr
==
nullptr
;
}
inline
ptrdiff_t
compare
(
const_pointer
ptr
)
const
{
explicit
operator
bool
()
const
{
return
m_ptr
!=
nullptr
;
}
ptrdiff_t
compare
(
const_pointer
ptr
)
const
{
return
static_cast
<
ptrdiff_t
>
(
get
()
-
ptr
);
}
inline
ptrdiff_t
compare
(
const
intrusive_ptr
&
other
)
const
{
ptrdiff_t
compare
(
const
intrusive_ptr
&
other
)
const
{
return
compare
(
other
.
get
());
}
inline
ptrdiff_t
compare
(
std
::
nullptr_t
)
const
{
ptrdiff_t
compare
(
std
::
nullptr_t
)
const
{
return
reinterpret_cast
<
ptrdiff_t
>
(
get
());
}
...
...
@@ -154,15 +166,14 @@ class intrusive_ptr : detail::comparable<intrusive_ptr<T>>,
}
private:
pointer
m_ptr
;
inline
void
set_ptr
(
pointer
raw_ptr
,
bool
add_ref
)
{
void
set_ptr
(
pointer
raw_ptr
,
bool
add_ref
)
{
m_ptr
=
raw_ptr
;
if
(
raw_ptr
&&
add_ref
)
{
raw_ptr
->
ref
(
);
intrusive_ptr_add_ref
(
raw_ptr
);
}
}
pointer
m_ptr
;
};
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment