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
5eb12825
Unverified
Commit
5eb12825
authored
Mar 27, 2023
by
Maarten L. Hekkelman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added category::find1<std::optional>
parent
cfa46ec9
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
50 additions
and
12 deletions
+50
-12
changelog
+1
-0
include/cif++/category.hpp
+21
-1
src/point.cpp
+0
-11
test/unit-v2-test.cpp
+28
-0
No files found.
changelog
View file @
5eb12825
...
@@ -3,6 +3,7 @@ Version 5.0.9
...
@@ -3,6 +3,7 @@ Version 5.0.9
-
Added
create_water
to
model
-
Added
create_water
to
model
-
Writing
twin
domain
info
in
PDB
files
and
more
PDB
fixes
-
Writing
twin
domain
info
in
PDB
files
and
more
PDB
fixes
-
remove_atom
improved
(
remove
struct_conn
records
)
-
remove_atom
improved
(
remove
struct_conn
records
)
-
Added
a
specialisation
for
category
::
find1
<
std
::
optional
>
Version
5.0.8
Version
5.0.8
-
implemented
find_first
,
find_min
,
find_max
and
count
in
category
-
implemented
find_first
,
find_min
,
find_max
and
count
in
category
...
...
include/cif++/category.hpp
View file @
5eb12825
...
@@ -64,6 +64,12 @@ class multiple_results_error : public std::runtime_error
...
@@ -64,6 +64,12 @@ class multiple_results_error : public std::runtime_error
};
};
// --------------------------------------------------------------------
// --------------------------------------------------------------------
// These should be moved elsewhere, one day.
template
<
typename
_Tp
>
inline
constexpr
bool
is_optional_v
=
false
;
template
<
typename
_Tp
>
inline
constexpr
bool
is_optional_v
<
std
::
optional
<
_Tp
>>
=
true
;
// --------------------------------------------------------------------
class
category
class
category
{
{
...
@@ -299,7 +305,7 @@ class category
...
@@ -299,7 +305,7 @@ class category
return
find1
<
T
>
(
cbegin
(),
std
::
move
(
cond
),
column
);
return
find1
<
T
>
(
cbegin
(),
std
::
move
(
cond
),
column
);
}
}
template
<
typename
T
>
template
<
typename
T
,
std
::
enable_if_t
<
not
is_optional_v
<
T
>
,
int
>
=
0
>
T
find1
(
const_iterator
pos
,
condition
&&
cond
,
const
char
*
column
)
const
T
find1
(
const_iterator
pos
,
condition
&&
cond
,
const
char
*
column
)
const
{
{
auto
h
=
find
<
T
>
(
pos
,
std
::
move
(
cond
),
column
);
auto
h
=
find
<
T
>
(
pos
,
std
::
move
(
cond
),
column
);
...
@@ -310,6 +316,20 @@ class category
...
@@ -310,6 +316,20 @@ class category
return
*
h
.
begin
();
return
*
h
.
begin
();
}
}
template
<
typename
T
,
std
::
enable_if_t
<
is_optional_v
<
T
>
,
int
>
=
0
>
T
find1
(
const_iterator
pos
,
condition
&&
cond
,
const
char
*
column
)
const
{
auto
h
=
find
<
typename
T
::
value_type
>
(
pos
,
std
::
move
(
cond
),
column
);
if
(
h
.
size
()
>
1
)
throw
multiple_results_error
();
if
(
h
.
empty
())
return
{};
return
*
h
.
begin
();
}
template
<
typename
...
Ts
,
typename
...
Cs
,
typename
U
=
std
::
enable_if_t
<
sizeof
...(
Ts
)
!=
1
>>
template
<
typename
...
Ts
,
typename
...
Cs
,
typename
U
=
std
::
enable_if_t
<
sizeof
...(
Ts
)
!=
1
>>
std
::
tuple
<
Ts
...
>
find1
(
condition
&&
cond
,
Cs
...
columns
)
const
std
::
tuple
<
Ts
...
>
find1
(
condition
&&
cond
,
Cs
...
columns
)
const
{
{
...
...
src/point.cpp
View file @
5eb12825
...
@@ -299,17 +299,6 @@ quaternion_type<T> normalize(quaternion_type<T> q)
...
@@ -299,17 +299,6 @@ quaternion_type<T> normalize(quaternion_type<T> q)
quaternion
construct_from_angle_axis
(
float
angle
,
point
axis
)
quaternion
construct_from_angle_axis
(
float
angle
,
point
axis
)
{
{
// auto q = std::cos((angle * kPI / 180) / 2);
// auto s = std::sqrt(1 - q * q);
// axis.normalize();
// return normalize(quaternion{
// static_cast<float>(q),
// static_cast<float>(s * axis.m_x),
// static_cast<float>(s * axis.m_y),
// static_cast<float>(s * axis.m_z) });
angle
=
(
angle
*
kPI
/
180
)
/
2
;
angle
=
(
angle
*
kPI
/
180
)
/
2
;
auto
s
=
std
::
sin
(
angle
);
auto
s
=
std
::
sin
(
angle
);
auto
c
=
std
::
cos
(
angle
);
auto
c
=
std
::
cos
(
angle
);
...
...
test/unit-v2-test.cpp
View file @
5eb12825
...
@@ -3104,3 +3104,30 @@ _date today
...
@@ -3104,3 +3104,30 @@ _date today
BOOST_TEST
(
db
==
db2
);
BOOST_TEST
(
db
==
db2
);
}
}
BOOST_AUTO_TEST_CASE
(
find1_opt_1
)
{
using
namespace
cif
::
literals
;
using
namespace
std
::
literals
;
auto
f
=
R"(data_TEST
#
loop_
_test.id
_test.name
_test.value
1 aap 1.0
2 noot 1.1
3 mies 1.2
)"
_cf
;
auto
&
db
=
f
.
front
();
auto
&
test
=
db
[
"test"
];
auto
v
=
test
.
find1
<
std
::
optional
<
float
>>
(
"id"
_key
==
1
,
"value"
);
BOOST_CHECK
(
v
.
has_value
());
BOOST_TEST
(
*
v
==
1.0
f
);
v
=
test
.
find1
<
std
::
optional
<
float
>>
(
"id"
_key
==
4
,
"value"
);
BOOST_CHECK
(
v
.
has_value
()
==
false
);
}
\ No newline at end of file
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