Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
GeoModel
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GeoModelDev
GeoModel
Commits
d33772c7
Commit
d33772c7
authored
1 year ago
by
Johannes Junggeburth
Browse files
Options
Downloads
Patches
Plain Diff
GeoIntrusivePtr - Fix move semantics + add test
parent
d8a0a07a
No related branches found
No related tags found
1 merge request
!278
GeoIntrusivePtr - Fix move semantics + add test
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
GeoModelCore/GeoModelKernel/GeoModelKernel/GeoIntrusivePtr.h
+19
-21
19 additions, 21 deletions
GeoModelCore/GeoModelKernel/GeoModelKernel/GeoIntrusivePtr.h
GeoModelCore/GeoModelKernel/tests/testGeoIntrusivePtr.cxx
+34
-0
34 additions, 0 deletions
GeoModelCore/GeoModelKernel/tests/testGeoIntrusivePtr.cxx
with
53 additions
and
21 deletions
GeoModelCore/GeoModelKernel/GeoModelKernel/GeoIntrusivePtr.h
+
19
−
21
View file @
d33772c7
...
@@ -15,14 +15,14 @@ class GeoIntrusivePtr{
...
@@ -15,14 +15,14 @@ class GeoIntrusivePtr{
public:
public:
template
<
typename
GeoTypeGrp
>
friend
class
GeoIntrusivePtr
;
template
<
typename
GeoTypeGrp
>
friend
class
GeoIntrusivePtr
;
GeoIntrusivePtr
()
noexcept
=
default
;
GeoIntrusivePtr
()
noexcept
=
default
;
// Standard constructor taking a bare pointer
// Standard constructor taking a bare pointer
GeoIntrusivePtr
(
GeoType
*
obj
)
noexcept
:
GeoIntrusivePtr
(
GeoType
*
obj
)
noexcept
:
m_ptr
{
obj
}
{
m_ptr
{
obj
}
{
if
(
m_ptr
)
obj
->
ref
();
if
(
m_ptr
)
obj
->
ref
();
}
}
/// Copy constructor
/// Copy constructor
explicit
GeoIntrusivePtr
(
const
GeoIntrusivePtr
&
other
)
noexcept
:
GeoIntrusivePtr
(
const
GeoIntrusivePtr
&
other
)
noexcept
:
GeoIntrusivePtr
{
other
.
get
()}
{}
GeoIntrusivePtr
{
other
.
get
()}
{}
/// Copy constructor for derived types
/// Copy constructor for derived types
...
@@ -32,16 +32,16 @@ class GeoIntrusivePtr{
...
@@ -32,16 +32,16 @@ class GeoIntrusivePtr{
GeoIntrusivePtr
{
other
.
get
()}
{}
GeoIntrusivePtr
{
other
.
get
()}
{}
/// Move constructor
/// Move constructor
explicit
GeoIntrusivePtr
(
GeoIntrusivePtr
&&
other
)
noexcept
:
GeoIntrusivePtr
(
GeoIntrusivePtr
&&
other
)
noexcept
:
m_ptr
{
other
.
m_p
tr
}
{
GeoIntrusiveP
tr
{
}
{
other
.
m_ptr
=
nullptr
;
move
(
std
::
move
(
other
))
;
}
}
/// Move constructor for derived types
/// Move constructor for derived types
template
<
typename
GeoTypeGrp
,
template
<
typename
GeoTypeGrp
,
typename
=
typename
std
::
enable_if
<!
std
::
is_same
<
GeoType
,
GeoTypeGrp
>
::
value
,
bool
>>
typename
=
typename
std
::
enable_if
<!
std
::
is_same
<
GeoType
,
GeoTypeGrp
>
::
value
,
bool
>>
GeoIntrusivePtr
(
GeoIntrusivePtr
<
GeoTypeGrp
>&&
other
)
noexcept
:
GeoIntrusivePtr
(
GeoIntrusivePtr
<
GeoTypeGrp
>&&
other
)
noexcept
:
m_ptr
{
other
.
m_p
tr
}
{
GeoIntrusiveP
tr
{
}
{
other
.
m_ptr
=
nullptr
;
move
(
std
::
move
(
other
))
;
}
}
...
@@ -62,24 +62,14 @@ class GeoIntrusivePtr{
...
@@ -62,24 +62,14 @@ class GeoIntrusivePtr{
return
*
this
;
return
*
this
;
}
}
/// Move assignment operator
/// Move assignment operator
GeoIntrusivePtr
&
operator
=
(
GeoIntrusivePtr
&&
other
)
{
GeoIntrusivePtr
&
operator
=
(
GeoIntrusivePtr
&&
other
)
noexcept
{
if
(
m_ptr
&&
m_ptr
==
other
.
get
())
{
move
(
std
::
move
(
other
));
m_ptr
->
unref
();
}
else
{
m_ptr
=
other
.
get
();
}
other
.
m_ptr
=
nullptr
;
return
*
this
;
return
*
this
;
}
}
template
<
typename
GeoTypeGrp
,
template
<
typename
GeoTypeGrp
,
typename
=
typename
std
::
enable_if
<!
std
::
is_same
<
GeoType
,
GeoTypeGrp
>
::
value
,
bool
>>
typename
=
typename
std
::
enable_if
<!
std
::
is_same
<
GeoType
,
GeoTypeGrp
>
::
value
,
bool
>>
GeoIntrusivePtr
&
operator
=
(
GeoIntrusivePtr
<
GeoTypeGrp
>&&
other
)
{
GeoIntrusivePtr
&
operator
=
(
GeoIntrusivePtr
<
GeoTypeGrp
>&&
other
)
noexcept
{
if
(
m_ptr
&&
m_ptr
==
other
.
get
())
{
move
(
std
::
move
(
other
));
m_ptr
->
unref
();
}
else
{
m_ptr
=
other
.
get
();
}
other
.
m_ptr
=
nullptr
;
return
*
this
;
return
*
this
;
}
}
/// Reset the pointer
/// Reset the pointer
...
@@ -89,6 +79,14 @@ class GeoIntrusivePtr{
...
@@ -89,6 +79,14 @@ class GeoIntrusivePtr{
m_ptr
=
ptr
;
m_ptr
=
ptr
;
if
(
m_ptr
)
m_ptr
->
ref
();
if
(
m_ptr
)
m_ptr
->
ref
();
}
}
template
<
class
GeoTypeGrp
>
void
move
(
GeoIntrusivePtr
<
GeoTypeGrp
>&&
obj
)
{
if
(
m_ptr
!=
obj
.
get
())
{
if
(
m_ptr
)
m_ptr
->
unref
();
m_ptr
=
obj
.
m_ptr
;
}
obj
.
m_ptr
=
nullptr
;
}
/// Destructor
/// Destructor
~
GeoIntrusivePtr
()
{
~
GeoIntrusivePtr
()
{
if
(
m_ptr
)
m_ptr
->
unref
();
if
(
m_ptr
)
m_ptr
->
unref
();
...
...
This diff is collapsed.
Click to expand it.
GeoModelCore/GeoModelKernel/tests/testGeoIntrusivePtr.cxx
+
34
−
0
View file @
d33772c7
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
#include
<GeoModelKernel/GeoFullPhysVol.h>
#include
<GeoModelKernel/GeoFullPhysVol.h>
#include
<GeoModelKernel/GeoTransform.h>
#include
<GeoModelKernel/GeoPhysVol.h>
#include
<GeoModelKernel/GeoPhysVol.h>
#include
<GeoModelKernel/GeoBox.h>
#include
<GeoModelKernel/GeoBox.h>
#include
<iostream>
#include
<iostream>
...
@@ -65,6 +66,39 @@ int main(int argc, char *argv[]){
...
@@ -65,6 +66,39 @@ int main(int argc, char *argv[]){
physVol4
=
std
::
move
(
physVol3
);
physVol4
=
std
::
move
(
physVol3
);
CHECKCOUNT
(
physVol4
,
2
);
CHECKCOUNT
(
physVol4
,
2
);
}
}
GeoIntrusivePtr
<
GeoPhysVol
>
world
{
new
GeoPhysVol
(
nullptr
)};
world
->
add
(
new
GeoTransform
(
GeoTrf
::
Translate3D
(
0.
,
0.
,
0
)));
{
GeoIntrusivePtr
<
GeoFullPhysVol
>
childVol
{
new
GeoFullPhysVol
(
nullptr
)};
world
->
add
(
childVol
);
CHECKCOUNT
(
world
,
1
);
CHECKCOUNT
(
childVol
,
2
);
CHECKCOUNT
(
world
,
1
);
childVol
->
getAbsoluteTransform
();
CHECKCOUNT
(
childVol
,
2
);
CHECKCOUNT
(
world
,
1
);
childVol
->
getX
();
CHECKCOUNT
(
world
,
1
);
childVol
->
getDefX
();
CHECKCOUNT
(
world
,
1
);
childVol
->
getDefAbsoluteTransform
();
CHECKCOUNT
(
world
,
1
);
}
{
GeoIntrusivePtr
<
GeoPhysVol
>
childVol
{
new
GeoPhysVol
(
nullptr
)};
world
->
add
(
childVol
);
CHECKCOUNT
(
world
,
1
);
CHECKCOUNT
(
childVol
,
2
);
CHECKCOUNT
(
world
,
1
);
childVol
->
getX
();
CHECKCOUNT
(
world
,
1
);
childVol
->
getDefX
();
CHECKCOUNT
(
world
,
1
);
}
CHECKCOUNT
(
world
,
1
);
return
EXIT_SUCCESS
;
return
EXIT_SUCCESS
;
}
}
#pragma clang diagnostic pop
#pragma clang diagnostic pop
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment