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
19a89aeb
Unverified
Commit
19a89aeb
authored
Aug 07, 2022
by
Maarten L. Hekkelman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- start row_initializer
parent
677c61c3
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
52 additions
and
57 deletions
+52
-57
include/cif++/v2/category.hpp
+4
-6
include/cif++/v2/condition.hpp
+2
-2
include/cif++/v2/row.hpp
+29
-49
test/unit-v2-test.cpp
+17
-0
No files found.
include/cif++/v2/category.hpp
View file @
19a89aeb
...
@@ -36,7 +36,6 @@
...
@@ -36,7 +36,6 @@
// TODO: implement all of:
// TODO: implement all of:
// https://en.cppreference.com/w/cpp/named_req/Container
// https://en.cppreference.com/w/cpp/named_req/Container
// https://en.cppreference.com/w/cpp/named_req/SequenceContainer
// https://en.cppreference.com/w/cpp/named_req/SequenceContainer
// https://en.cppreference.com/w/cpp/named_req/AssociativeContainer ?
// and more?
// and more?
...
@@ -333,12 +332,12 @@ class category
...
@@ -333,12 +332,12 @@ class category
// --------------------------------------------------------------------
// --------------------------------------------------------------------
// void insert(const_iterator pos, const row &row)
// void insert(const_iterator pos, const row
_initializer
&row)
// {
// {
// insert_impl(pos, row);
// insert_impl(pos, row);
// }
// }
// void insert(const_iterator pos, row &&row)
// void insert(const_iterator pos, row
_initializer
&&row)
// {
// {
// insert_impl(pos, std::move(row));
// insert_impl(pos, std::move(row));
// }
// }
...
@@ -347,9 +346,9 @@ class category
...
@@ -347,9 +346,9 @@ class category
size_t
erase
(
condition
&&
cond
);
size_t
erase
(
condition
&&
cond
);
size_t
erase
(
condition
&&
cond
,
std
::
function
<
void
(
row_handle
)
>
&&
visit
);
size_t
erase
(
condition
&&
cond
,
std
::
function
<
void
(
row_handle
)
>
&&
visit
);
iterator
emplace
(
std
::
initializer_list
<
item
>
items
)
iterator
emplace
(
row_initializer
&&
ri
)
{
{
return
this
->
emplace
(
items
.
begin
(),
items
.
end
());
return
this
->
emplace
(
ri
.
m_items
.
begin
(),
ri
.
m_
items
.
end
());
}
}
template
<
typename
ItemIter
>
template
<
typename
ItemIter
>
...
@@ -586,7 +585,6 @@ class category
...
@@ -586,7 +585,6 @@ class category
// proxy methods for every insertion
// proxy methods for every insertion
iterator
insert_impl
(
const_iterator
pos
,
row
*
n
);
iterator
insert_impl
(
const_iterator
pos
,
row
*
n
);
iterator
erase_impl
(
const_iterator
pos
);
iterator
erase_impl
(
const_iterator
pos
);
std
::
string
m_name
;
std
::
string
m_name
;
...
...
include/cif++/v2/condition.hpp
View file @
19a89aeb
...
@@ -248,7 +248,7 @@ namespace detail
...
@@ -248,7 +248,7 @@ namespace detail
bool
test
(
row_handle
r
)
const
override
bool
test
(
row_handle
r
)
const
override
{
{
auto
&
c
=
r
.
cat
();
auto
&
c
=
r
.
get_category
();
bool
result
=
false
;
bool
result
=
false
;
for
(
auto
&
f
:
get_category_fields
(
c
))
for
(
auto
&
f
:
get_category_fields
(
c
))
...
@@ -286,7 +286,7 @@ namespace detail
...
@@ -286,7 +286,7 @@ namespace detail
bool
test
(
row_handle
r
)
const
override
bool
test
(
row_handle
r
)
const
override
{
{
auto
&
c
=
r
.
cat
();
auto
&
c
=
r
.
get_category
();
bool
result
=
false
;
bool
result
=
false
;
for
(
auto
&
f
:
get_category_fields
(
c
))
for
(
auto
&
f
:
get_category_fields
(
c
))
...
...
include/cif++/v2/row.hpp
View file @
19a89aeb
...
@@ -130,7 +130,7 @@ class row
...
@@ -130,7 +130,7 @@ class row
};
};
// --------------------------------------------------------------------
// --------------------------------------------------------------------
/// \brief row_handle is the way to access data in rows
/// \brief row_handle is the way to access data
stored
in rows
class
row_handle
class
row_handle
{
{
...
@@ -153,7 +153,7 @@ class row_handle
...
@@ -153,7 +153,7 @@ class row_handle
{
{
}
}
const
category
&
cat
()
const
const
category
&
get_category
()
const
{
{
return
*
m_category
;
return
*
m_category
;
}
}
...
@@ -202,55 +202,8 @@ class row_handle
...
@@ -202,55 +202,8 @@ class row_handle
void
assign
(
const
std
::
vector
<
item
>
&
values
)
void
assign
(
const
std
::
vector
<
item
>
&
values
)
{
{
// std::map<std::string, std::tuple<size_t, std::string, std::string>> changed;
for
(
auto
&
value
:
values
)
for
(
auto
&
value
:
values
)
{
assign
(
value
,
true
);
assign
(
value
,
true
);
// auto columnIx = cat->add_column(value.name());
// auto &col = cat->m_columns[columnIx];
// std::string tag = col.mValidator ? col.mValidator->mTag : std::to_string(columnIx);
// changed[tag] = std::make_tuple(columnIx, operator[](columnIx).c_str(), value.value());
// assign(columnIx, value.value(), true);
}
// // see if we need to update any child categories that depend on these values
// // auto iv = col.mValidator;
// if (mCascade)
// {
// for (auto &&[childCat, linked] : cat->mChildLinks)
// {
// Condition cond;
// std::string childTag;
// std::vector<Item> newValues;
// for (size_t ix = 0; ix < linked->mParentKeys.size(); ++ix)
// {
// std::string pk = linked->mParentKeys[ix];
// std::string ck = linked->mChildKeys[ix];
// if (changed.count(pk) > 0)
// {
// childTag = ck;
// cond = std::move(cond) && (Key(ck) == std::get<1>(changed[pk]));
// newValues.emplace_back(ck, std::get<2>(changed[pk]));
// }
// else
// {
// const char *value = (*this)[pk].c_str();
// cond = std::move(cond) && (Key(ck) == value);
// }
// }
// auto rows = childCat->find(std::move(cond));
// for (auto &cr : rows)
// cr.assign(newValues);
// }
// }
}
}
void
assign
(
std
::
string_view
name
,
std
::
string_view
value
,
bool
updateLinked
,
bool
validate
=
true
)
void
assign
(
std
::
string_view
name
,
std
::
string_view
value
,
bool
updateLinked
,
bool
validate
=
true
)
...
@@ -282,4 +235,30 @@ class row_handle
...
@@ -282,4 +235,30 @@ class row_handle
row
*
m_row
=
nullptr
;
row
*
m_row
=
nullptr
;
};
};
// --------------------------------------------------------------------
class
row_initializer
{
public
:
friend
class
category
;
row_initializer
()
=
default
;
row_initializer
(
const
row_initializer
&
)
=
default
;
row_initializer
(
row_initializer
&&
)
=
default
;
row_initializer
&
operator
=
(
const
row_initializer
&
)
=
default
;
row_initializer
&
operator
=
(
row_initializer
&&
)
=
default
;
row_initializer
(
std
::
initializer_list
<
item
>
items
)
:
m_items
(
items
)
{}
template
<
typename
ItemIter
,
std
::
enable_if_t
<
std
::
is_same_v
<
typename
ItemIter
::
value_type
,
item
>
,
int
>
=
0
>
row_initializer
(
ItemIter
b
,
ItemIter
e
)
:
m_items
(
b
,
e
)
{
}
private
:
std
::
vector
<
item
>
m_items
;
};
}
//
namespace
cif
::
v2
}
//
namespace
cif
::
v2
\ No newline at end of file
test/unit-v2-test.cpp
View file @
19a89aeb
...
@@ -662,6 +662,23 @@ mies Mies
...
@@ -662,6 +662,23 @@ mies Mies
cat1
.
erase
(
cif
::
v2
::
key
(
"id"
)
==
"noot"
);
cat1
.
erase
(
cif
::
v2
::
key
(
"id"
)
==
"noot"
);
BOOST_CHECK
(
cat1
.
size
()
==
2
);
BOOST_CHECK
(
cat1
.
size
()
==
2
);
// should fail with duplicate key:
BOOST_CHECK_THROW
(
cat1
.
emplace
({
{
"id"
,
"aap"
},
{
"c"
,
"2e-aap"
}
}),
std
::
exception
);
cat1
.
erase
(
cif
::
v2
::
key
(
"id"
)
==
"aap"
);
BOOST_CHECK
(
cat1
.
size
()
==
1
);
cat1
.
emplace
({
{
"id"
,
"aap"
},
{
"c"
,
"2e-aap"
}
});
BOOST_CHECK
(
cat1
.
size
()
==
2
);
}
}
// --------------------------------------------------------------------
// --------------------------------------------------------------------
...
...
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