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
b5e52ce2
Commit
b5e52ce2
authored
Dec 22, 2014
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve opencl::smart_ptr and coding style nitpicks
parent
78f4e19d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
25 deletions
+40
-25
libcaf_opencl/caf/opencl/smart_ptr.hpp
libcaf_opencl/caf/opencl/smart_ptr.hpp
+40
-25
No files found.
libcaf_opencl/caf/opencl/smart_ptr.hpp
View file @
b5e52ce2
...
...
@@ -27,30 +27,30 @@
namespace
caf
{
namespace
opencl
{
template
<
typename
T
,
cl_int
(
*
ref
)(
T
),
cl_int
(
*
deref
)(
T
)>
template
<
class
T
,
cl_int
(
*
ref
)(
T
),
cl_int
(
*
deref
)(
T
)>
class
smart_ptr
{
public:
using
element_type
=
typename
std
::
remove_pointer
<
T
>::
type
;
using
pointer
=
element_type
*
;
using
reference
=
element_type
&
;
using
const_pointer
=
const
element_type
*
;
using
const_reference
=
const
element_type
&
;
public:
smart_ptr
(
pointer
ptr
=
nullptr
)
:
m_ptr
(
ptr
)
{
if
(
m_ptr
)
ref
(
m_ptr
);
smart_ptr
(
pointer
ptr
=
nullptr
,
bool
inc_ref_count
=
true
)
:
m_ptr
(
nullptr
)
{
reset
(
ptr
,
inc_ref_count
);
}
~
smart_ptr
()
{
reset
();
}
~
smart_ptr
()
{
reset
();
}
smart_ptr
(
const
smart_ptr
&
other
)
:
m_ptr
(
other
.
m_ptr
)
{
if
(
m_ptr
)
ref
(
m_ptr
);
smart_ptr
(
smart_ptr
&&
other
)
:
m_ptr
(
nullptr
)
{
swap
(
other
);
}
smart_ptr
(
smart_ptr
&&
other
)
:
m_ptr
(
other
.
m_ptr
)
{
other
.
m_ptr
=
nullptr
;
}
smart_ptr
(
const
smart_ptr
&
other
)
:
m_ptr
(
nullptr
)
{
reset
(
other
.
m_ptr
);
}
smart_ptr
&
operator
=
(
pointer
ptr
)
{
reset
(
ptr
);
...
...
@@ -58,39 +58,54 @@ class smart_ptr {
}
smart_ptr
&
operator
=
(
smart_ptr
&&
other
)
{
s
td
::
swap
(
m_ptr
,
other
.
m_pt
r
);
s
wap
(
othe
r
);
return
*
this
;
}
smart_ptr
&
operator
=
(
const
smart_ptr
&
other
)
{
smart_ptr
tmp
{
other
};
s
td
::
swap
(
m_ptr
,
tmp
.
m_ptr
);
s
wap
(
tmp
);
return
*
this
;
}
inline
void
reset
(
pointer
ptr
=
nullptr
)
{
if
(
m_ptr
)
void
swap
(
smart_ptr
&
other
)
{
std
::
swap
(
m_ptr
,
other
.
m_ptr
);
}
void
reset
(
pointer
ptr
=
nullptr
,
bool
inc_ref_count
=
true
)
{
if
(
m_ptr
)
{
deref
(
m_ptr
);
}
m_ptr
=
ptr
;
if
(
ptr
)
if
(
ptr
&&
inc_ref_count
)
{
ref
(
ptr
);
}
}
// does not modify reference count of ptr
inline
void
adopt
(
pointer
ptr
)
{
reset
();
m_ptr
=
ptr
;
void
adopt
(
pointer
ptr
)
{
reset
(
ptr
,
false
);
}
inline
pointer
get
()
const
{
return
m_ptr
;
}
pointer
get
()
const
{
return
m_ptr
;
}
inline
pointer
operator
->
()
const
{
return
m_ptr
;
}
pointer
operator
->
()
const
{
return
m_ptr
;
}
inline
reference
operator
*
()
const
{
return
*
m_ptr
;
}
reference
operator
*
()
const
{
return
*
m_ptr
;
}
inline
bool
operator
!
()
const
{
return
m_ptr
==
nullptr
;
}
bool
operator
!
()
const
{
return
m_ptr
==
nullptr
;
}
inline
explicit
operator
bool
()
const
{
return
m_ptr
!=
nullptr
;
}
explicit
operator
bool
()
const
{
return
m_ptr
!=
nullptr
;
}
private:
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