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
55d304ad
Commit
55d304ad
authored
3 years ago
by
florian
Browse files
Options
Downloads
Patches
Plain Diff
ENH: Add creators and deleter for values
parent
cd50b367
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!24
API: Introduce value and datatype structs to Extern C
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
include/ccaosdb.h
+0
-1
0 additions, 1 deletion
include/ccaosdb.h
src/ccaosdb.cpp
+52
-0
52 additions, 0 deletions
src/ccaosdb.cpp
test/test_ccaosdb.cpp
+30
-0
30 additions, 0 deletions
test/test_ccaosdb.cpp
with
82 additions
and
1 deletion
include/ccaosdb.h
+
0
−
1
View file @
55d304ad
...
...
@@ -431,7 +431,6 @@ int caosdb_entity_delete_parent(caosdb_entity_parent *out);
int
caosdb_entity_create_datatype
(
caosdb_entity_datatype
*
out
);
int
caosdb_entity_delete_datatype
(
caosdb_entity_datatype
*
out
);
// VALUE CONSTRUCTORS (resolve overloaded constructors)
int
caosdb_entity_create_value
(
caosdb_entity_value
*
out
,
caosdb_entity_value
*
in
);
int
caosdb_entity_create_int_value
(
caosdb_entity_value
*
out
,
const
int64_t
value
);
int
caosdb_entity_create_string_value
(
caosdb_entity_value
*
out
,
const
char
*
value
);
int
caosdb_entity_create_double_value
(
caosdb_entity_value
*
out
,
const
double
value
);
...
...
This diff is collapsed.
Click to expand it.
src/ccaosdb.cpp
+
52
−
0
View file @
55d304ad
...
...
@@ -23,6 +23,7 @@
#include
"caosdb/connection.h"
#include
"caosdb/constants.h"
#include
"caosdb/data_type.h"
// for DataType, AtomicDat...
#include
"caosdb/value.h"
#include
"caosdb/utility.h"
#include
"caosdb/status_code.h"
#include
"caosdb/logging.h"
...
...
@@ -46,6 +47,8 @@ extern "C" {
#define WRAPPED_MESSAGE_CAST(name) static_cast<caosdb::entity::Message *>(name->wrapped_message)
#define WRAPPED_VALUE_CAST(name) static_cast<caosdb::entity::Value *>(name->wrapped_value)
#define ENUM_NAME_FROM_VALUE(arg, etype) \
caosdb::utility::getEnumNameFromValue<caosdb::entity::etype>(arg)
...
...
@@ -146,6 +149,38 @@ extern "C" {
body_part return 0; \
})
/**
* Macro for scalar value creators
*/
#define CREATE_VALUE(fname, arg) \
ERROR_RETURN_CODE(GENERIC_ERROR, \
int caosdb_entity_create_##fname(caosdb_entity_value *out, arg), { \
if (out->_deletable) { \
return caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR; \
} \
out->wrapped_value = new caosdb::entity::Value(value); \
out->_deletable = true; \
return 0; \
})
/**
* Macro for list-value creators
*/
#define CREATE_LIST_VALUE(fname, type, arg, assign) \
ERROR_RETURN_CODE( \
GENERIC_ERROR, \
int caosdb_entity_create_##fname(caosdb_entity_value *out, arg, const int length), { \
if (out->_deletable) { \
return caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR; \
} \
std::vector<type> value_vec; \
for (int i = 0; i < length; i++) { \
value_vec.push_back(assign); \
} \
out->wrapped_value = new caosdb::entity::Value(value_vec); \
out->_deletable = true; \
return 0; \
})
int
caosdb_constants_LIBCAOSDB_VERSION_MAJOR
()
{
return
caosdb
::
LIBCAOSDB_VERSION_MAJOR
;
}
int
caosdb_constants_LIBCAOSDB_VERSION_MINOR
()
{
return
caosdb
::
LIBCAOSDB_VERSION_MINOR
;
}
...
...
@@ -625,6 +660,23 @@ ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_delete_parent(caosdb_entity_p
return
0
;
})
CREATE_VALUE
(
int_value
,
const
int64_t
value
)
CREATE_VALUE
(
string_value
,
const
char
*
value
)
CREATE_VALUE
(
double_value
,
const
double
value
)
CREATE_VALUE
(
bool_value
,
const
bool
value
)
CREATE_LIST_VALUE
(
int_list_value
,
int64_t
,
const
int64_t
*
value
,
value
[
i
])
CREATE_LIST_VALUE
(
string_list_value
,
std
::
string
,
const
char
**
value
,
std
::
string
(
value
[
i
]))
CREATE_LIST_VALUE
(
double_list_value
,
double
,
const
double
*
value
,
value
[
i
])
CREATE_LIST_VALUE
(
bool_list_value
,
bool
,
const
bool
*
value
,
value
[
i
])
ERROR_RETURN_CODE
(
GENERIC_ERROR
,
int
caosdb_entity_delete_value
(
caosdb_entity_value
*
out
),
{
if
(
out
->
_deletable
)
{
delete
WRAPPED_VALUE_CAST
(
out
);
}
out
->
_deletable
=
false
;
return
0
;
})
CAOSDB_ENTITY_GET
(
id
,
GetId
())
ERROR_RETURN_CODE
(
GENERIC_ERROR
,
int
caosdb_entity_entity_get_role
(
caosdb_entity_entity
*
entity
,
char
**
out
),
{
...
...
This diff is collapsed.
Click to expand it.
test/test_ccaosdb.cpp
+
30
−
0
View file @
55d304ad
...
...
@@ -127,6 +127,36 @@ TEST_F(test_ccaosdb, test_query) {
EXPECT_EQ
(
return_code
,
0
);
}
TEST_F
(
test_ccaosdb
,
test_value
)
{
caosdb_entity_value
string_value
;
int
return_code
(
caosdb_entity_create_string_value
(
&
string_value
,
"value"
));
EXPECT_EQ
(
return_code
,
0
);
caosdb_entity_value
int_value
;
return_code
=
caosdb_entity_create_int_value
(
&
int_value
,
27
);
EXPECT_EQ
(
return_code
,
0
);
caosdb_entity_value
bool_value
;
return_code
=
caosdb_entity_create_bool_value
(
&
bool_value
,
true
);
EXPECT_EQ
(
return_code
,
0
);
caosdb_entity_value
double_value
;
return_code
=
caosdb_entity_create_double_value
(
&
double_value
,
2.7
);
EXPECT_EQ
(
return_code
,
0
);
// TODO(fspreck) Test is... and as... functions
return_code
=
caosdb_entity_delete_value
(
&
string_value
);
EXPECT_EQ
(
return_code
,
0
);
return_code
=
caosdb_entity_delete_value
(
&
int_value
);
EXPECT_EQ
(
return_code
,
0
);
return_code
=
caosdb_entity_delete_value
(
&
bool_value
);
EXPECT_EQ
(
return_code
,
0
);
return_code
=
caosdb_entity_delete_value
(
&
double_value
);
EXPECT_EQ
(
return_code
,
0
);
}
TEST_F
(
test_ccaosdb
,
test_entity
)
{
caosdb_entity_entity
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