Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-cpplib
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
caosdb-cpplib
Commits
67522b83
Commit
67522b83
authored
3 years ago
by
Daniel Hornung
Browse files
Options
Downloads
Patches
Plain Diff
ENH: Convenient list constructor for DataType.
parent
3ce3fae9
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!14
ENH: New functions getEnumNameFromValue() and getEnumValueFromName()
,
!12
F consolidation
Pipeline
#12259
failed
3 years ago
Stage: info
Stage: setup
Stage: test
Stage: deploy
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
include/caosdb/data_type.h
+19
-5
19 additions, 5 deletions
include/caosdb/data_type.h
test/test_data_type.cpp
+9
-21
9 additions, 21 deletions
test/test_data_type.cpp
with
28 additions
and
26 deletions
include/caosdb/data_type.h
+
19
−
5
View file @
67522b83
...
...
@@ -155,12 +155,26 @@ public:
DataType
(
ProtoDataType
*
wrapped
)
:
ProtoMessageWrapper
<
ProtoDataType
>
(
wrapped
)
{}
DataType
()
:
ProtoMessageWrapper
<
ProtoDataType
>
()
{}
DataType
(
AtomicDataType
data_type
)
:
DataType
()
{
this
->
wrapped
->
set_atomic_data_type
(
static_cast
<
ProtoAtomicDataType
>
(
data_type
));
/**
* Create an AtomicDataType typed DataType. For references, use the std::string constructor.
*/
DataType
(
AtomicDataType
data_type
,
bool
list_type
=
false
)
:
DataType
()
{
if
(
list_type
)
{
this
->
wrapped
->
mutable_list_data_type
()
->
set_atomic_data_type
(
static_cast
<
ProtoAtomicDataType
>
(
data_type
));
}
else
{
this
->
wrapped
->
set_atomic_data_type
(
static_cast
<
ProtoAtomicDataType
>
(
data_type
));
}
}
DataType
(
const
std
::
string
&
data_type
)
:
DataType
()
{
this
->
wrapped
->
mutable_reference_data_type
()
->
set_name
(
data_type
);
/**
* Create a reference typed DataType.
*/
DataType
(
const
std
::
string
&
data_type
,
bool
list_type
=
false
)
:
DataType
()
{
if
(
list_type
)
{
this
->
wrapped
->
mutable_list_data_type
()
->
mutable_reference_data_type
()
->
set_name
(
data_type
);
}
else
{
this
->
wrapped
->
mutable_reference_data_type
()
->
set_name
(
data_type
);
}
}
[[
nodiscard
]]
inline
auto
IsAtomic
()
const
noexcept
->
bool
{
return
this
->
wrapped
->
data_type_case
()
==
DataTypeCase
::
kAtomicDataType
;
...
...
This diff is collapsed.
Click to expand it.
test/test_data_type.cpp
+
9
−
21
View file @
67522b83
...
...
@@ -22,9 +22,7 @@
#include
"caosdb/data_type.h"
// for DataType, AtomicDataType
#include
"caosdb/entity.h"
// for Entity
#include
"caosdb/entity/v1alpha1/main.pb.h"
// for AtomicDataType, DataType
#include
"caosdb/logging.h"
// for CAOSDB_LOG_DEBUG
#include
"caosdb/protobuf_helper.h"
// for CAOSDB_DEBUG_...
#include
<boost/log/core/record.hpp>
// for record
#include
<boost/log/detail/attachable_sstream_buf.hpp>
// for basic_ostring...
#include
<boost/log/sources/record_ostream.hpp>
// for operator<<
...
...
@@ -45,15 +43,15 @@ using ProtoAtomicDataType = caosdb::entity::v1alpha1::AtomicDataType;
TEST
(
test_data_type
,
test_atomic
)
{
ProtoDataType
proto_data_type
;
for
(
int
i
=
1
;
i
<
6
;
i
++
)
{
for
(
auto
map_el
:
atomicdatatype_names
)
{
Entity
entity
;
entity
.
SetRole
(
Role
::
PROPERTY
);
// the different AtomicDataType are associated with integers
entity
.
SetDataType
(
static_cast
<
AtomicDataType
>
(
i
)
);
entity
.
SetDataType
(
map_el
.
first
);
EXPECT_TRUE
(
entity
.
GetDataType
().
IsAtomic
());
EXPECT_EQ
(
entity
.
GetDataType
().
AsAtomic
(),
static_cast
<
AtomicDataType
>
(
i
)
);
EXPECT_EQ
(
entity
.
GetDataType
().
AsAtomic
(),
map_el
.
first
);
proto_data_type
.
set_atomic_data_type
(
static_cast
<
ProtoAtomicDataType
>
(
i
));
proto_data_type
.
set_atomic_data_type
(
static_cast
<
ProtoAtomicDataType
>
(
map_el
.
first
));
DataType
data_type
(
&
proto_data_type
);
entity
.
SetDataType
(
data_type
);
...
...
@@ -61,7 +59,7 @@ TEST(test_data_type, test_atomic) {
EXPECT_EQ
(
data_type
.
AsReference
().
GetName
(),
std
::
basic_string
<
char
>
(
""
));
EXPECT_FALSE
(
data_type
.
IsList
());
EXPECT_TRUE
(
data_type
.
IsAtomic
());
EXPECT_EQ
(
data_type
.
AsAtomic
(),
static_cast
<
AtomicDataType
>
(
i
)
);
EXPECT_EQ
(
data_type
.
AsAtomic
(),
map_el
.
first
);
}
}
...
...
@@ -85,13 +83,8 @@ TEST(test_data_type, test_reference) {
}
TEST
(
test_data_type
,
test_list_of_atomic
)
{
ProtoDataType
proto_data_type
;
auto
*
proto_list_data_type
=
proto_data_type
.
mutable_list_data_type
();
for
(
int
i
=
1
;
i
<
6
;
i
++
)
{
proto_list_data_type
->
set_atomic_data_type
(
static_cast
<
ProtoAtomicDataType
>
(
i
));
DataType
data_type
(
&
proto_data_type
);
for
(
auto
map_el
:
atomicdatatype_names
)
{
DataType
data_type
(
map_el
.
first
,
true
);
EXPECT_FALSE
(
data_type
.
IsReference
());
EXPECT_FALSE
(
data_type
.
IsAtomic
());
...
...
@@ -101,17 +94,12 @@ TEST(test_data_type, test_list_of_atomic) {
std
::
basic_string
<
char
>
(
""
));
EXPECT_TRUE
(
list_data_type
.
IsListOfAtomic
());
EXPECT_FALSE
(
list_data_type
.
IsListOfReference
());
EXPECT_EQ
(
list_data_type
.
GetAtomicDataType
(),
static_cast
<
AtomicDataType
>
(
i
));
EXPECT_EQ
(
list_data_type
.
GetAtomicDataType
(),
map_el
.
first
);
}
}
TEST
(
test_data_type
,
test_list_of_reference
)
{
ProtoDataType
proto_data_type
;
auto
*
proto_list_data_type
=
proto_data_type
.
mutable_list_data_type
();
proto_list_data_type
->
mutable_reference_data_type
()
->
set_name
(
"person"
);
DataType
data_type
(
&
proto_data_type
);
auto
data_type
=
DataType
(
"person"
,
true
);
EXPECT_FALSE
(
data_type
.
IsReference
());
EXPECT_FALSE
(
data_type
.
IsAtomic
());
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment