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
d9db2fe2
Unverified
Commit
d9db2fe2
authored
Aug 07, 2022
by
Maarten L. Hekkelman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
insert
parent
19a89aeb
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
141 additions
and
64 deletions
+141
-64
CMakeLists.txt
+1
-1
cmake/FindAtomic.cmake
+0
-2
cmake/FindFilesystem.cmake
+0
-2
include/cif++/v2/category.hpp
+8
-0
include/cif++/v2/row.hpp
+5
-0
src/v2/category.cpp
+63
-59
src/v2/row.cpp
+17
-0
test/unit-v2-test.cpp
+47
-0
No files found.
CMakeLists.txt
View file @
d9db2fe2
...
@@ -25,7 +25,7 @@
...
@@ -25,7 +25,7 @@
cmake_minimum_required
(
VERSION 3.16
)
cmake_minimum_required
(
VERSION 3.16
)
# set the project name
# set the project name
project
(
cifpp VERSION
4.2.1
LANGUAGES CXX
)
project
(
cifpp VERSION
5.0.0
LANGUAGES CXX
)
list
(
PREPEND CMAKE_MODULE_PATH
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/cmake"
)
list
(
PREPEND CMAKE_MODULE_PATH
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/cmake"
)
...
...
cmake/FindAtomic.cmake
View file @
d9db2fe2
...
@@ -12,8 +12,6 @@ include(CheckCXXSourceRuns)
...
@@ -12,8 +12,6 @@ include(CheckCXXSourceRuns)
cmake_push_check_state
()
cmake_push_check_state
()
# set(CMAKE_CXX_STANDARD 17)
check_include_file_cxx
(
"atomic"
_CXX_ATOMIC_HAVE_HEADER
)
check_include_file_cxx
(
"atomic"
_CXX_ATOMIC_HAVE_HEADER
)
mark_as_advanced
(
_CXX_ATOMIC_HAVE_HEADER
)
mark_as_advanced
(
_CXX_ATOMIC_HAVE_HEADER
)
...
...
cmake/FindFilesystem.cmake
View file @
d9db2fe2
...
@@ -12,8 +12,6 @@ include(CheckCXXSourceCompiles)
...
@@ -12,8 +12,6 @@ include(CheckCXXSourceCompiles)
cmake_push_check_state
()
cmake_push_check_state
()
# set(CMAKE_CXX_STANDARD 17)
check_include_file_cxx
(
"filesystem"
_CXX_FILESYSTEM_HAVE_HEADER
)
check_include_file_cxx
(
"filesystem"
_CXX_FILESYSTEM_HAVE_HEADER
)
mark_as_advanced
(
_CXX_FILESYSTEM_HAVE_HEADER
)
mark_as_advanced
(
_CXX_FILESYSTEM_HAVE_HEADER
)
...
...
include/cif++/v2/category.hpp
View file @
d9db2fe2
...
@@ -410,6 +410,14 @@ class category
...
@@ -410,6 +410,14 @@ class category
return
result
;
return
result
;
}
}
std
::
string_view
get_column_name
(
uint16_t
ix
)
const
{
if
(
ix
>=
m_columns
.
size
())
throw
std
::
out_of_range
(
"column index is out of range"
);
return
m_columns
[
ix
].
m_name
;
}
uint16_t
add_column
(
std
::
string_view
column_name
)
uint16_t
add_column
(
std
::
string_view
column_name
)
{
{
using
namespace
std
::
literals
;
using
namespace
std
::
literals
;
...
...
include/cif++/v2/row.hpp
View file @
d9db2fe2
...
@@ -111,6 +111,7 @@ class row
...
@@ -111,6 +111,7 @@ class row
private
:
private
:
friend
class
item_handle
;
friend
class
item_handle
;
friend
class
category_index
;
friend
class
category_index
;
friend
class
row_initializer
;
template
<
typename
,
typename
...
>
template
<
typename
,
typename
...
>
friend
class
iterator_impl
;
friend
class
iterator_impl
;
...
@@ -138,6 +139,7 @@ class row_handle
...
@@ -138,6 +139,7 @@ class row_handle
friend
class
item_handle
;
friend
class
item_handle
;
friend
class
category
;
friend
class
category
;
friend
class
category_index
;
friend
class
category_index
;
friend
class
row_initializer
;
row_handle
()
=
default
;
row_handle
()
=
default
;
...
@@ -218,6 +220,7 @@ class row_handle
...
@@ -218,6 +220,7 @@ class row_handle
private
:
private
:
uint16_t
get_column_ix
(
std
::
string_view
name
)
const
;
uint16_t
get_column_ix
(
std
::
string_view
name
)
const
;
std
::
string_view
get_column_name
(
uint16_t
ix
)
const
;
uint16_t
add_column
(
std
::
string_view
name
);
uint16_t
add_column
(
std
::
string_view
name
);
...
@@ -257,6 +260,8 @@ class row_initializer
...
@@ -257,6 +260,8 @@ class row_initializer
{
{
}
}
row_initializer
(
row_handle
rh
);
private
:
private
:
std
::
vector
<
item
>
m_items
;
std
::
vector
<
item
>
m_items
;
};
};
...
...
src/v2/category.cpp
View file @
d9db2fe2
...
@@ -1310,82 +1310,86 @@ category::iterator category::insert_impl(const_iterator pos, row *n)
...
@@ -1310,82 +1310,86 @@ category::iterator category::insert_impl(const_iterator pos, row *n)
if
(
n
==
nullptr
)
if
(
n
==
nullptr
)
throw
std
::
runtime_error
(
"Invalid pointer passed to insert"
);
throw
std
::
runtime_error
(
"Invalid pointer passed to insert"
);
// First, make sure all mandatory fields are supplied
try
if
(
m_cat_validator
!=
nullptr
)
{
{
for
(
uint16_t
ix
=
0
;
ix
<
static_cast
<
uint16_t
>
(
m_columns
.
size
());
++
ix
)
// First, make sure all mandatory fields are supplied
if
(
m_cat_validator
!=
nullptr
)
{
{
const
auto
&
[
column
,
iv
]
=
m_columns
[
ix
];
for
(
uint16_t
ix
=
0
;
ix
<
static_cast
<
uint16_t
>
(
m_columns
.
size
());
++
ix
)
{
const
auto
&
[
column
,
iv
]
=
m_columns
[
ix
];
if
(
iv
==
nullptr
)
if
(
iv
==
nullptr
)
continue
;
continue
;
bool
seen
=
false
;
bool
seen
=
false
;
for
(
auto
i
=
n
->
m_head
;
i
!=
nullptr
;
i
=
i
->
m_next
)
for
(
auto
i
=
n
->
m_head
;
i
!=
nullptr
;
i
=
i
->
m_next
)
{
if
(
i
->
m_column_ix
==
ix
)
{
{
iv
->
operator
()(
i
->
text
());
if
(
i
->
m_column_ix
==
ix
)
{
iv
->
operator
()(
i
->
text
());
seen
=
true
;
seen
=
true
;
break
;
break
;
}
}
}
if
(
not
seen
and
iv
->
m_mandatory
)
throw
std
::
runtime_error
(
"missing mandatory field "
+
column
+
" for category "
+
m_name
);
}
}
if
(
not
seen
and
iv
->
m_mandatory
)
// if (m_index != nullptr)
throw
std
::
runtime_error
(
"missing mandatory field "
+
column
+
" for category "
+
m_name
);
// {
// std::unique_ptr<ItemRow> nr(new ItemRow{nullptr, this, nullptr});
// Row r(nr.get());
// auto keys = keyFields();
// for (auto v = b; v != e; ++v)
// {
// if (keys.count(v->name()))
// r.assign(v->name(), v->value(), true);
// }
// auto test = m_index->find(nr.get());
// if (test != nullptr)
// {
// if (VERBOSE > 1)
// std::cerr << "Not inserting new record in " << mName << " (duplicate Key)" << std::endl;
// result = test;
// isNew = false;
// }
// }
}
}
// if (m_index != nullptr)
if
(
m_index
!=
nullptr
)
// {
m_index
->
insert
(
n
);
// std::unique_ptr<ItemRow> nr(new ItemRow{nullptr, this, nullptr});
// Row r(nr.get());
// auto keys = keyFields();
// for (auto v = b; v != e; ++v)
// {
// if (keys.count(v->name()))
// r.assign(v->name(), v->value(), true);
// }
// auto test = m_index->find(nr.get());
// if (test != nullptr)
// {
// if (VERBOSE > 1)
// std::cerr << "Not inserting new record in " << mName << " (duplicate Key)" << std::endl;
// result = test;
// isNew = false;
// }
// }
}
if
(
m_index
!=
nullptr
)
m_index
->
insert
(
n
);
// insert at end, most often this is the case
// insert at end, most often this is the case
if
(
pos
.
m_current
==
nullptr
)
if
(
pos
.
m_current
==
nullptr
)
{
{
if
(
m_head
==
nullptr
)
if
(
m_head
==
nullptr
)
m_tail
=
m_head
=
n
;
m_tail
=
m_head
=
n
;
else
m_tail
=
m_tail
->
m_next
=
n
;
}
else
else
m_tail
=
m_tail
->
m_next
=
n
;
{
assert
(
m_head
!=
nullptr
);
if
(
pos
.
m_current
==
m_head
)
m_head
=
n
->
m_next
=
m_head
;
else
n
=
n
->
m_next
=
m_head
->
m_next
;
}
return
iterator
(
*
this
,
n
);
}
}
else
catch
(
const
std
::
exception
&
e
)
{
{
assert
(
m_head
!=
nullptr
);
delete_row
(
n
);
throw
;
if
(
pos
.
m_current
==
m_head
)
m_head
=
n
->
m_next
=
m_head
;
else
n
=
n
->
m_next
=
m_head
->
m_next
;
}
}
return
iterator
(
*
this
,
n
);
}
}
category
::
iterator
category
::
erase_impl
(
const_iterator
pos
)
category
::
iterator
category
::
erase_impl
(
const_iterator
pos
)
...
...
src/v2/row.cpp
View file @
d9db2fe2
...
@@ -39,9 +39,25 @@ uint16_t row_handle::get_column_ix(std::string_view name) const
...
@@ -39,9 +39,25 @@ uint16_t row_handle::get_column_ix(std::string_view name) const
return
m_category
->
get_column_ix
(
name
);
return
m_category
->
get_column_ix
(
name
);
}
}
std
::
string_view
row_handle
::
get_column_name
(
uint16_t
ix
)
const
{
return
m_category
->
get_column_name
(
ix
);
}
uint16_t
row_handle
::
add_column
(
std
::
string_view
name
)
uint16_t
row_handle
::
add_column
(
std
::
string_view
name
)
{
{
return
m_category
->
add_column
(
name
);
return
m_category
->
add_column
(
name
);
}
}
// --------------------------------------------------------------------
row_initializer
::
row_initializer
(
row_handle
rh
)
{
row
*
r
=
rh
;
auto
&
cat
=
*
rh
.
m_category
;
for
(
auto
i
=
r
->
m_head
;
i
!=
nullptr
;
i
=
i
->
m_next
)
m_items
.
emplace_back
(
cat
.
get_column_name
(
i
->
m_column_ix
),
i
->
text
());
}
}
//
namespace
cif
::
v2
}
//
namespace
cif
::
v2
\ No newline at end of file
test/unit-v2-test.cpp
View file @
d9db2fe2
...
@@ -130,6 +130,32 @@ BOOST_AUTO_TEST_CASE(cc_2)
...
@@ -130,6 +130,32 @@ BOOST_AUTO_TEST_CASE(cc_2)
}
}
}
}
BOOST_AUTO_TEST_CASE
(
item_1
)
{
using
namespace
cif
::
v2
;
item
i1
(
"1"
,
"1"
);
item
i2
(
"2"
,
2.0
);
item
i3
(
"3"
,
'3'
);
item
ci1
(
i1
);
item
ci2
(
i2
);
item
ci3
(
i3
);
BOOST_CHECK_EQUAL
(
i1
.
value
(),
ci1
.
value
());
BOOST_CHECK_EQUAL
(
i2
.
value
(),
ci2
.
value
());
BOOST_CHECK_EQUAL
(
i3
.
value
(),
ci3
.
value
());
item
mi1
(
std
::
move
(
i1
));
item
mi2
(
std
::
move
(
i2
));
item
mi3
(
std
::
move
(
i3
));
BOOST_CHECK_EQUAL
(
i1
.
value
(),
mi1
.
value
());
BOOST_CHECK_EQUAL
(
i2
.
value
(),
mi2
.
value
());
BOOST_CHECK_EQUAL
(
i3
.
value
(),
mi3
.
value
());
}
// --------------------------------------------------------------------
// --------------------------------------------------------------------
...
@@ -243,6 +269,27 @@ BOOST_AUTO_TEST_CASE(c_2)
...
@@ -243,6 +269,27 @@ BOOST_AUTO_TEST_CASE(c_2)
BOOST_CHECK_EQUAL
(
c
.
size
(),
3
);
BOOST_CHECK_EQUAL
(
c
.
size
(),
3
);
}
}
BOOST_AUTO_TEST_CASE
(
c_3
)
{
std
::
tuple
<
int
,
const
char
*>
D
[]
=
{
{
1
,
"aap"
},
{
2
,
"noot"
},
{
3
,
"mies"
}
};
cif
::
v2
::
category
c
(
"foo"
);
for
(
const
auto
&
[
id
,
s
]
:
D
)
c
.
emplace
({
{
"id"
,
id
},
{
"s"
,
s
}
});
cif
::
v2
::
category
c2
(
"bar"
);
for
(
auto
r
:
c
)
c2
.
emplace
(
r
);
// BOOST_CHECK(c == c2);
}
BOOST_AUTO_TEST_CASE
(
ci_1
)
BOOST_AUTO_TEST_CASE
(
ci_1
)
{
{
cif
::
v2
::
category
c
(
"foo"
);
cif
::
v2
::
category
c
(
"foo"
);
...
...
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