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
184c4918
Unverified
Commit
184c4918
authored
Aug 18, 2022
by
Maarten L. Hekkelman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
changed find1 a bit more
reverted to returning empty results in case nothing is found
parent
f944b3ce
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
52 additions
and
24 deletions
+52
-24
CMakeLists.txt
+0
-4
include/cif++/category.hpp
+2
-14
include/cif++/item.hpp
+25
-0
include/cif++/row.hpp
+5
-5
src/item.cpp
+13
-1
src/row.cpp
+7
-0
No files found.
CMakeLists.txt
View file @
184c4918
...
...
@@ -35,7 +35,6 @@ include(CheckIncludeFiles)
include
(
CheckLibraryExists
)
include
(
CMakePackageConfigHelpers
)
include
(
Dart
)
include
(
GenerateExportHeader
)
set
(
CXX_EXTENSIONS OFF
)
set
(
CMAKE_CXX_STANDARD 20
)
...
...
@@ -275,9 +274,6 @@ if(UNIX)
target_compile_definitions
(
cifpp PUBLIC CACHE_DIR=
"
${
CIFPP_CACHE_DIR
}
"
)
endif
()
# generate_export_header(cifpp
# EXPORT_FILE_NAME cif++/Cif++Export.hpp)
set
(
INCLUDE_INSTALL_DIR
${
CMAKE_INSTALL_INCLUDEDIR
}
)
set
(
LIBRARY_INSTALL_DIR
${
CMAKE_INSTALL_LIBDIR
}
)
set
(
SHARE_INSTALL_DIR
${
CMAKE_INSTALL_DATADIR
}
/libcifpp
)
...
...
include/cif++/category.hpp
View file @
184c4918
...
...
@@ -262,13 +262,7 @@ class category
{
auto
h
=
find
<
T
>
(
pos
,
std
::
forward
<
condition
>
(
cond
),
column
);
if
(
h
.
empty
())
throw
std
::
runtime_error
(
"No hits found"
);
if
(
h
.
size
()
!=
1
)
throw
std
::
runtime_error
(
"Hit not unique"
);
return
std
::
get
<
0
>
(
*
h
.
begin
());
return
h
.
size
()
==
1
?
std
::
get
<
0
>
(
*
h
.
begin
())
:
T
{};
}
template
<
typename
...
Ts
,
typename
...
Cs
,
typename
U
=
std
::
enable_if_t
<
sizeof
...(
Ts
)
!=
1
>>
...
...
@@ -285,13 +279,7 @@ class category
static_assert
(
sizeof
...(
Ts
)
==
sizeof
...(
Cs
),
"The number of column titles should be equal to the number of types to return"
);
auto
h
=
find
<
Ts
...
>
(
pos
,
std
::
forward
<
condition
>
(
cond
),
std
::
forward
<
Cs
>
(
columns
)...);
if
(
h
.
empty
())
throw
std
::
runtime_error
(
"No hits found"
);
if
(
h
.
size
()
!=
1
)
throw
std
::
runtime_error
(
"Hit not unique"
);
return
*
h
.
begin
();
return
h
.
size
()
==
1
?
*
h
.
begin
()
:
std
::
tuple
<
Ts
...
>
{};
}
bool
exists
(
condition
&&
cond
)
const
...
...
include/cif++/item.hpp
View file @
184c4918
...
...
@@ -292,7 +292,11 @@ struct item_handle
{
}
static
const
item_handle
s_null_item
;
private
:
item_handle
();
uint16_t
m_column
;
row_handle
&
m_row_handle
;
...
...
@@ -421,6 +425,13 @@ struct item_handle::item_value_as<T, std::enable_if_t<std::is_same_v<T, bool>>>
template
<
size_t
N
>
struct
item_handle
::
item_value_as
<
char
[
N
]
>
{
static
std
::
string
convert
(
const
item_handle
&
ref
)
{
if
(
ref
.
empty
())
return
{};
return
{
ref
.
text
().
data
(),
ref
.
text
().
size
()
};
}
static
int
compare
(
const
item_handle
&
ref
,
const
char
(
&
value
)[
N
],
bool
icase
)
{
return
icase
?
cif
::
icompare
(
ref
.
text
(),
value
)
:
ref
.
text
().
compare
(
value
);
...
...
@@ -430,6 +441,13 @@ struct item_handle::item_value_as<char[N]>
template
<
typename
T
>
struct
item_handle
::
item_value_as
<
T
,
std
::
enable_if_t
<
std
::
is_same_v
<
T
,
const
char
*>>>
{
static
std
::
string
convert
(
const
item_handle
&
ref
)
{
if
(
ref
.
empty
())
return
{};
return
{
ref
.
text
().
data
(),
ref
.
text
().
size
()
};
}
static
int
compare
(
const
item_handle
&
ref
,
const
char
*
value
,
bool
icase
)
{
return
icase
?
cif
::
icompare
(
ref
.
text
(),
value
)
:
ref
.
text
().
compare
(
value
);
...
...
@@ -439,6 +457,13 @@ struct item_handle::item_value_as<T, std::enable_if_t<std::is_same_v<T, const ch
template
<
typename
T
>
struct
item_handle
::
item_value_as
<
T
,
std
::
enable_if_t
<
std
::
is_same_v
<
T
,
std
::
string_view
>>>
{
static
std
::
string
convert
(
const
item_handle
&
ref
)
{
if
(
ref
.
empty
())
return
{};
return
{
ref
.
text
().
data
(),
ref
.
text
().
size
()
};
}
static
int
compare
(
const
item_handle
&
ref
,
const
std
::
string_view
&
value
,
bool
icase
)
{
return
icase
?
cif
::
icompare
(
ref
.
text
(),
value
)
:
ref
.
text
().
compare
(
value
);
...
...
include/cif++/row.hpp
View file @
184c4918
...
...
@@ -172,22 +172,22 @@ class row_handle
item_handle
operator
[](
uint32_t
column_ix
)
{
return
item_handle
(
column_ix
,
*
this
);
return
empty
()
?
item_handle
::
s_null_item
:
item_handle
(
column_ix
,
*
this
);
}
const
item_handle
operator
[](
uint32_t
column_ix
)
const
{
return
item_handle
(
column_ix
,
const_cast
<
row_handle
&>
(
*
this
));
return
empty
()
?
item_handle
::
s_null_item
:
item_handle
(
column_ix
,
const_cast
<
row_handle
&>
(
*
this
));
}
item_handle
operator
[](
std
::
string_view
column_name
)
{
return
item_handle
(
add_column
(
column_name
),
*
this
);
return
empty
()
?
item_handle
::
s_null_item
:
item_handle
(
add_column
(
column_name
),
*
this
);
}
const
item_handle
operator
[](
std
::
string_view
column_name
)
const
{
return
item_handle
(
get_column_ix
(
column_name
),
const_cast
<
row_handle
&>
(
*
this
));
return
empty
()
?
item_handle
::
s_null_item
:
item_handle
(
get_column_ix
(
column_name
),
const_cast
<
row_handle
&>
(
*
this
));
}
template
<
typename
...
C
>
...
...
@@ -202,7 +202,7 @@ class row_handle
return
detail
::
get_row_result
<
Ts
...
>
(
*
this
,
{
get_column_ix
(
columns
)...
});
}
template
<
typename
T
>
template
<
typename
T
>
T
get
(
const
char
*
column
)
{
return
operator
[](
get_column_ix
(
column
)).
template
as
<
T
>
();
...
...
src/item.cpp
View file @
184c4918
...
...
@@ -24,14 +24,25 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <cassert>
#include <cif++/row.hpp>
namespace
cif
{
const
item_handle
item_handle
::
s_null_item
;
row_handle
s_null_row_handle
;
item_handle
::
item_handle
()
:
m_column
(
std
::
numeric_limits
<
uint16_t
>::
max
())
,
m_row_handle
(
s_null_row_handle
)
{
}
std
::
string_view
item_handle
::
text
()
const
{
if
(
m_row_handle
.
m_row
!=
nullptr
)
if
(
not
m_row_handle
.
empty
()
)
{
for
(
auto
iv
=
m_row_handle
.
m_row
->
m_head
;
iv
!=
nullptr
;
iv
=
iv
->
m_next
)
{
...
...
@@ -45,6 +56,7 @@ std::string_view item_handle::text() const
void
item_handle
::
assign_value
(
const
item
&
v
)
{
assert
(
not
m_row_handle
.
empty
());
m_row_handle
.
assign
(
m_column
,
v
.
value
(),
true
);
}
...
...
src/row.cpp
View file @
184c4918
...
...
@@ -31,21 +31,25 @@ namespace cif
void
row_handle
::
assign
(
size_t
column
,
std
::
string_view
value
,
bool
updateLinked
,
bool
validate
)
{
assert
(
m_category
);
m_category
->
update_value
(
m_row
,
column
,
value
,
updateLinked
,
validate
);
}
uint16_t
row_handle
::
get_column_ix
(
std
::
string_view
name
)
const
{
assert
(
m_category
);
return
m_category
->
get_column_ix
(
name
);
}
std
::
string_view
row_handle
::
get_column_name
(
uint16_t
ix
)
const
{
assert
(
m_category
);
return
m_category
->
get_column_name
(
ix
);
}
uint16_t
row_handle
::
add_column
(
std
::
string_view
name
)
{
assert
(
m_category
);
return
m_category
->
add_column
(
name
);
}
...
...
@@ -53,6 +57,9 @@ uint16_t row_handle::add_column(std::string_view name)
row_initializer
::
row_initializer
(
row_handle
rh
)
{
assert
(
rh
.
m_category
);
assert
(
rh
.
m_row
);
row
*
r
=
rh
;
auto
&
cat
=
*
rh
.
m_category
;
...
...
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