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
640bb8c3
Verified
Commit
640bb8c3
authored
3 years ago
by
Timm Fitschen
Browse files
Options
Downloads
Patches
Plain Diff
FIX: Value(AbstractValue) constructor
parent
63423526
No related branches found
No related tags found
1 merge request
!24
API: Introduce value and datatype structs to Extern C
Pipeline
#13685
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/value.h
+9
-1
9 additions, 1 deletion
include/caosdb/value.h
test/test_value.cpp
+33
-0
33 additions, 0 deletions
test/test_value.cpp
with
42 additions
and
1 deletion
include/caosdb/value.h
+
9
−
1
View file @
640bb8c3
...
@@ -162,6 +162,7 @@ public:
...
@@ -162,6 +162,7 @@ public:
* The return value is undefined if IsVector is false.
* The return value is undefined if IsVector is false.
*/
*/
[[
nodiscard
]]
virtual
auto
GetAsVector
()
const
noexcept
->
const
std
::
vector
<
ScalarValue
>
&
=
0
;
[[
nodiscard
]]
virtual
auto
GetAsVector
()
const
noexcept
->
const
std
::
vector
<
ScalarValue
>
&
=
0
;
[[
nodiscard
]]
virtual
auto
ToString
()
const
noexcept
->
const
std
::
string
=
0
;
friend
class
Value
;
friend
class
Value
;
protected:
protected:
...
@@ -250,6 +251,11 @@ public:
...
@@ -250,6 +251,11 @@ public:
static
const
std
::
vector
<
ScalarValue
>
empty_collection
;
static
const
std
::
vector
<
ScalarValue
>
empty_collection
;
return
empty_collection
;
return
empty_collection
;
}
}
inline
auto
ToString
()
const
noexcept
->
const
std
::
string
{
CAOSDB_DEBUG_MESSAGE_STRING
(
*
wrapped
,
out
)
return
out
;
}
friend
class
Value
;
friend
class
Value
;
protected
:
protected
:
...
@@ -286,7 +292,9 @@ public:
...
@@ -286,7 +292,9 @@ public:
explicit
inline
Value
(
const
ScalarValue
&
value
)
:
Value
()
{
explicit
inline
Value
(
const
ScalarValue
&
value
)
:
Value
()
{
this
->
wrapped
->
mutable_scalar_value
()
->
CopyFrom
(
*
value
.
wrapped
);
this
->
wrapped
->
mutable_scalar_value
()
->
CopyFrom
(
*
value
.
wrapped
);
}
}
explicit
inline
Value
(
const
AbstractValue
&
value
)
:
Value
(
value
.
GetProtoValue
())
{}
explicit
inline
Value
(
const
AbstractValue
&
value
)
:
Value
()
{
this
->
wrapped
->
CopyFrom
(
*
value
.
GetProtoValue
());
}
explicit
inline
Value
(
ProtoValue
*
wrapped
)
:
ProtoMessageWrapper
<
ProtoValue
>
(
wrapped
)
{}
explicit
inline
Value
(
ProtoValue
*
wrapped
)
:
ProtoMessageWrapper
<
ProtoValue
>
(
wrapped
)
{}
explicit
inline
Value
(
const
std
::
string
&
value
)
:
ProtoMessageWrapper
<
ProtoValue
>
()
{
explicit
inline
Value
(
const
std
::
string
&
value
)
:
ProtoMessageWrapper
<
ProtoValue
>
()
{
this
->
wrapped
->
mutable_scalar_value
()
->
set_string_value
(
value
);
this
->
wrapped
->
mutable_scalar_value
()
->
set_string_value
(
value
);
...
...
This diff is collapsed.
Click to expand it.
test/test_value.cpp
+
33
−
0
View file @
640bb8c3
...
@@ -147,4 +147,37 @@ TEST(test_value, test_scalar_value_to_value) {
...
@@ -147,4 +147,37 @@ TEST(test_value, test_scalar_value_to_value) {
EXPECT_EQ
(
scalar_value
.
GetAsInt64
(),
value
.
GetAsInt64
());
EXPECT_EQ
(
scalar_value
.
GetAsInt64
(),
value
.
GetAsInt64
());
}
}
TEST
(
test_value
,
test_abstract_value
)
{
std
::
vector
<
double
>
vals
;
for
(
double
num
:
{
0.0
,
5.6
,
27.5
})
{
vals
.
push_back
(
num
);
}
Value
value
(
vals
);
EXPECT_EQ
(
""
,
value
.
ToString
());
EXPECT_TRUE
(
value
.
IsVector
());
AbstractValue
*
abstract_value
=
&
value
;
EXPECT_EQ
(
""
,
abstract_value
->
ToString
());
EXPECT_TRUE
(
abstract_value
->
IsVector
());
Value
value2
(
*
abstract_value
);
EXPECT_EQ
(
""
,
value2
.
ToString
());
EXPECT_TRUE
(
value2
.
IsVector
());
ScalarValue
scalar_value
=
value
.
GetAsVector
().
at
(
2
);
EXPECT_TRUE
(
scalar_value
.
IsDouble
());
EXPECT_EQ
(
""
,
scalar_value
.
ToString
());
EXPECT_EQ
(
scalar_value
.
GetAsDouble
(),
27.5
);
AbstractValue
*
abstract_scalar_value
=
&
scalar_value
;
EXPECT_EQ
(
""
,
abstract_scalar_value
->
ToString
());
EXPECT_TRUE
(
abstract_scalar_value
->
IsDouble
());
EXPECT_EQ
(
abstract_scalar_value
->
GetAsDouble
(),
27.5
);
Value
scalar_value2
(
*
abstract_scalar_value
);
EXPECT_TRUE
(
scalar_value2
.
IsDouble
());
EXPECT_EQ
(
""
,
scalar_value2
.
ToString
());
EXPECT_EQ
(
scalar_value2
.
GetAsDouble
(),
27.5
);
}
}
// namespace caosdb::entity
}
// namespace caosdb::entity
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