Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
HEPnOS
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
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
sds
HEP
HEPnOS
Commits
f23ea01e
Commit
f23ea01e
authored
Nov 07, 2018
by
Matthieu Dorier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed problem with pointer
parent
fa9f6119
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
6 deletions
+42
-6
include/hepnos/Ptr.hpp
include/hepnos/Ptr.hpp
+30
-6
test/PtrTest.cpp
test/PtrTest.cpp
+12
-0
No files found.
include/hepnos/Ptr.hpp
View file @
f23ea01e
...
...
@@ -30,7 +30,7 @@ class Ptr {
private:
DataStore
*
m_datastore
=
nullptr
;
DataStore
*
m_datastore
=
nullptr
;
ProductID
m_product_id
=
ProductID
();
std
::
size_t
m_index
=
0
;
bool
m_is_in_container
=
false
;
...
...
@@ -42,13 +42,15 @@ class Ptr {
:
m_datastore
(
datastore
)
,
m_product_id
(
product_id
)
,
m_index
(
0
)
,
m_is_in_container
(
false
)
{}
,
m_is_in_container
(
false
)
,
m_refcount
(
new
size_t
(
1
))
{}
Ptr
(
DataStore
*
datastore
,
const
ProductID
&
product_id
,
std
::
size_t
index
)
:
m_datastore
(
datastore
)
,
m_product_id
(
product_id
)
,
m_index
(
index
)
,
m_is_in_container
(
true
)
{};
,
m_is_in_container
(
true
)
,
m_refcount
(
new
size_t
(
1
))
{};
public:
...
...
@@ -101,7 +103,7 @@ class Ptr {
if
(
&
other
==
this
)
return
*
this
;
if
(
other
.
m_data
==
m_data
)
return
*
this
;
if
(
m_data
)
{
this
->~
Ptr
();
reset
();
}
m_datastore
=
other
.
m_datastore
;
m_product_id
=
other
.
m_product_id
;
...
...
@@ -126,7 +128,7 @@ class Ptr {
if
(
&
other
==
this
)
return
*
this
;
if
(
other
.
m_data
==
m_data
)
return
*
this
;
if
(
m_data
)
{
this
->~
Ptr
();
reset
();
}
m_datastore
=
other
.
m_datastore
;
m_product_id
=
std
::
move
(
other
.
m_product_id
);
...
...
@@ -145,6 +147,13 @@ class Ptr {
* @brief Destructor.
*/
~
Ptr
()
{
reset
();
}
/**
* @brief Reset the pointer to NULL.
*/
void
reset
()
{
if
(
m_refcount
)
{
*
m_refcount
-=
1
;
if
(
*
m_refcount
==
0
)
{
...
...
@@ -156,6 +165,13 @@ class Ptr {
}
}
}
m_datastore
=
nullptr
;
m_product_id
=
ProductID
();
m_index
=
0
;
m_is_in_container
=
false
;
m_container
=
nullptr
;
m_data
=
nullptr
;
m_refcount
=
nullptr
;
}
/**
...
...
@@ -237,6 +253,10 @@ class Ptr {
template
<
typename
Archive
>
void
save
(
Archive
&
ar
,
const
unsigned
int
version
)
const
{
ar
&
m_product_id
;
ar
&
m_is_in_container
;
if
(
m_is_in_container
)
{
ar
&
m_index
;
}
}
/**
...
...
@@ -248,8 +268,12 @@ class Ptr {
*/
template
<
typename
Archive
>
void
load
(
Archive
&
ar
,
const
unsigned
int
version
)
{
ar
&
m_product_id
;
m_datastore
=
ar
.
getDataStore
();
ar
&
m_product_id
;
ar
&
m_is_in_container
;
if
(
m_is_in_container
)
{
ar
&
m_index
;
}
}
BOOST_SERIALIZATION_SPLIT_MEMBER
()
...
...
test/PtrTest.cpp
View file @
f23ea01e
...
...
@@ -132,4 +132,16 @@ void PtrTest::testPtrLoadFromArray() {
auto
ptrToMapA
=
datastore
->
makePtr
<
TestObjectA
,
std
::
map
<
unsigned
,
TestObjectA
>>
(
prodIDmap
,
1
);
CPPUNIT_ASSERT
(
mapA
[
1
]
==
*
ptrToMapA
);
event
.
store
(
"somekey"
,
ptrToVecA
);
event
.
store
(
"somekey"
,
ptrToMapA
);
decltype
(
ptrToVecA
)
ptrToVecAReloaded
;
decltype
(
ptrToMapA
)
ptrToMapAReloaded
;
event
.
load
(
"somekey"
,
ptrToVecAReloaded
);
event
.
load
(
"somekey"
,
ptrToMapAReloaded
);
CPPUNIT_ASSERT
(
vecA
[
1
]
==
*
ptrToVecAReloaded
);
CPPUNIT_ASSERT
(
mapA
[
1
]
==
*
ptrToMapAReloaded
);
}
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