Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
libcifpp
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open
libcifpp
Commits
4db37327
Unverified
Commit
4db37327
authored
Aug 02, 2022
by
Maarten L. Hekkelman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move construction and operators =
parent
07131e8b
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
80 additions
and
16 deletions
+80
-16
include/cif++/v2/category.hpp
+63
-16
test/unit-v2-test.cpp
+17
-0
No files found.
include/cif++/v2/category.hpp
View file @
4db37327
...
@@ -147,8 +147,15 @@ class category_t
...
@@ -147,8 +147,15 @@ class category_t
insert_impl
(
cend
(),
clone_row
(
*
r
));
insert_impl
(
cend
(),
clone_row
(
*
r
));
}
}
category_t
(
category_t
&&
)
category_t
(
category_t
&&
rhs
)
:
m_allocator
(
std
::
move
(
rhs
.
m_allocator
))
,
m_name
(
std
::
move
(
rhs
.
m_name
))
,
m_columns
(
std
::
move
(
rhs
.
m_columns
))
,
m_head
(
rhs
.
m_head
)
,
m_tail
(
rhs
.
m_tail
)
{
{
rhs
.
m_head
=
nullptr
;
rhs
.
m_tail
=
nullptr
;
}
}
template
<
typename
Alloc2
>
template
<
typename
Alloc2
>
...
@@ -165,31 +172,47 @@ class category_t
...
@@ -165,31 +172,47 @@ class category_t
{
{
}
}
category_t
&
operator
=
(
const
category_t
&
)
category_t
&
operator
=
(
const
category_t
&
rhs
)
{
{
if
(
this
!=
&
rhs
)
{
if
(
not
empty
())
clear
();
m_allocator
=
std
::
allocator_traits
<
allocator_type
>::
select_on_container_copy_construction
(
rhs
.
get_allocator
());
m_name
=
rhs
.
m_name
;
m_columns
=
rhs
.
m_columns
;
for
(
auto
r
=
rhs
.
m_head
;
r
!=
nullptr
;
r
=
r
->
m_next
)
insert_impl
(
cend
(),
clone_row
(
*
r
));
}
}
category_t
&
operator
=
(
category_t
&&
)
return
*
this
;
{
}
}
~
category_t
()
category_t
&
operator
=
(
category_t
&&
rhs
)
{
auto
r
=
m_head
;
while
(
r
!=
nullptr
)
{
{
auto
i
=
r
->
m_head
;
if
(
this
!=
&
rhs
)
while
(
i
!=
nullptr
)
{
{
auto
ti
=
i
->
m_next
;
if
(
not
empty
())
delete_item
(
i
);
clear
();
i
=
ti
;
m_allocator
=
std
::
move
(
rhs
.
m_allocator
);
m_name
=
std
::
move
(
rhs
.
m_name
);
m_columns
=
std
::
move
(
rhs
.
m_columns
);
m_head
=
rhs
.
m_head
;
m_tail
=
rhs
.
m_tail
;
rhs
.
m_head
=
rhs
.
m_tail
=
nullptr
;
}
}
auto
t
=
r
->
m_next
;
return
*
this
;
delete_row
(
r
);
r
=
t
;
}
}
~
category_t
()
{
clear
();
}
}
// --------------------------------------------------------------------
// --------------------------------------------------------------------
...
@@ -365,6 +388,19 @@ class category_t
...
@@ -365,6 +388,19 @@ class category_t
// mIndex->insert(nr);
// mIndex->insert(nr);
}
}
void
clear
()
{
auto
i
=
m_head
;
while
(
i
!=
nullptr
)
{
auto
t
=
i
;
i
=
i
->
m_next
;
delete_row
(
t
);
}
m_head
=
m_tail
=
nullptr
;
}
// --------------------------------------------------------------------
// --------------------------------------------------------------------
/// \brief Return the index number for \a column_name
/// \brief Return the index number for \a column_name
...
@@ -508,10 +544,21 @@ class category_t
...
@@ -508,10 +544,21 @@ class category_t
void
delete_row
(
row
*
r
)
void
delete_row
(
row
*
r
)
{
{
if
(
r
!=
nullptr
)
{
auto
i
=
r
->
m_head
;
while
(
i
!=
nullptr
)
{
auto
t
=
i
;
i
=
i
->
m_next
;
delete_item
(
t
);
}
row_allocator_type
ra
(
get_allocator
());
row_allocator_type
ra
(
get_allocator
());
row_allocator_traits
::
destroy
(
ra
,
r
);
row_allocator_traits
::
destroy
(
ra
,
r
);
row_allocator_traits
::
deallocate
(
ra
,
r
,
1
);
row_allocator_traits
::
deallocate
(
ra
,
r
,
1
);
}
}
}
struct
item_column
struct
item_column
{
{
...
...
test/unit-v2-test.cpp
View file @
4db37327
...
@@ -221,6 +221,23 @@ BOOST_AUTO_TEST_CASE(c_2)
...
@@ -221,6 +221,23 @@ BOOST_AUTO_TEST_CASE(c_2)
BOOST_CHECK
(
not
c2
.
empty
());
BOOST_CHECK
(
not
c2
.
empty
());
BOOST_CHECK_EQUAL
(
c2
.
size
(),
3
);
BOOST_CHECK_EQUAL
(
c2
.
size
(),
3
);
cif
::
v2
::
category
c3
(
std
::
move
(
c
));
BOOST_CHECK
(
not
c3
.
empty
());
BOOST_CHECK_EQUAL
(
c3
.
size
(),
3
);
BOOST_CHECK
(
c
.
empty
());
BOOST_CHECK_EQUAL
(
c
.
size
(),
0
);
c
=
c3
;
BOOST_CHECK
(
not
c
.
empty
());
BOOST_CHECK_EQUAL
(
c
.
size
(),
3
);
c
=
std
::
move
(
c2
);
BOOST_CHECK
(
not
c
.
empty
());
BOOST_CHECK_EQUAL
(
c
.
size
(),
3
);
}
}
// --------------------------------------------------------------------
// --------------------------------------------------------------------
...
...
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