Skip to content
Snippets Groups Projects
Commit 5edbfac4 authored by florian's avatar florian
Browse files

DRAFT: Add set_value to entity

parent de871349
No related branches found
No related tags found
1 merge request!13ENH: Add datatypes and value classes to Extern C interface
Pipeline #12223 failed
This commit is part of merge request !13. Comments created here will be created in the context of that merge request.
......@@ -132,6 +132,8 @@ public:
}
LIST_VALUE_CONSTRUCTOR(int64_t, set_integer_value)
LIST_VALUE_CONSTRUCTOR(double, set_double_value)
LIST_VALUE_CONSTRUCTOR(bool, set_boolean_value)
[[nodiscard]] inline auto IsNull() -> bool {
return this->wrapped->value_case() == ValueCase::VALUE_NOT_SET;
......
......@@ -439,21 +439,21 @@ int caosdb_entity_entity_set_unit(caosdb_entity_entity *entity,
const char *unit);
// TODO(fspreck) replace by more specific setters
int caosdb_entity_entity_set_int_value(caosdb_entity_entity *entity,
const long *value);
const long value);
int caosdb_entity_entity_set_double_value(caosdb_entity_entity *entity,
const double *value);
const double value);
int caosdb_entity_entity_set_boolean_value(caosdb_entity_entity *entity,
const bool *value);
const bool value);
int caosdb_entity_entity_set_string_value(caosdb_entity_entity *entity,
const char *value);
int caosdb_entity_entity_set_int_list_value(caosdb_entity_entity *entity,
const long **value,
const long *value,
const int length);
int caosdb_entity_entity_set_double_list_value(caosdb_entity_entity *entity,
const double **value,
const double *value,
const int length);
int caosdb_entity_entity_set_boolean_list_value(caosdb_entity_entity *entity,
const bool **value,
const bool *value,
const int length);
int caosdb_entity_entity_set_string_list_value(caosdb_entity_entity *entity,
const char **value,
......@@ -479,20 +479,20 @@ int caosdb_entity_property_set_unit(caosdb_entity_property *property,
const char *unit);
int caosdb_entity_property_set_int_value(caosdb_entity_property *property,
const long *value);
const long value);
int caosdb_entity_property_set_double_value(caosdb_entity_property *property,
const double *value);
const double value);
int caosdb_entity_property_set_boolean_value(caosdb_entity_property *property,
const bool *value);
const bool value);
int caosdb_entity_property_set_string_value(caosdb_entity_property *property,
const char *value);
int caosdb_entity_property_set_int_list_value(caosdb_entity_property *property,
const long **value,
const long *value,
const int length);
int caosdb_entity_property_set_double_list_value(
caosdb_entity_property *property, const double **value, const int length);
caosdb_entity_property *property, const double *value, const int length);
int caosdb_entity_property_set_boolean_list_value(
caosdb_entity_property *property, const bool **value, const int length);
caosdb_entity_property *property, const bool *value, const int length);
int caosdb_entity_property_set_string_list_value(
caosdb_entity_property *property, const char **value, const int length);
......
......@@ -783,9 +783,118 @@ CAOSDB_ENTITY_SET(description, description,
// CAOSDB_ENTITY_SET(datatype, datatype,
// wrapped_entity->SetDataType(std::string(datatype));)
CAOSDB_ENTITY_SET(unit, unit, wrapped_entity->SetUnit(std::string(unit));)
// TODO(fspreck)
// CAOSDB_ENTITY_SET(value, value,
// wrapped_entity->SetValue(std::string(value));)
ERROR_RETURN_CODE(
GENERIC_ERROR,
int caosdb_entity_entity_set_int_value(caosdb_entity_entity *entity,
const long value),
{
auto *wrapped_entity =
static_cast<caosdb::entity::Entity *>(entity->wrapped_entity);
wrapped_entity->SetValue(value);
return 0;
})
ERROR_RETURN_CODE(
GENERIC_ERROR,
int caosdb_entity_entity_set_double_value(caosdb_entity_entity *entity,
const double value),
{
auto *wrapped_entity =
static_cast<caosdb::entity::Entity *>(entity->wrapped_entity);
wrapped_entity->SetValue(value);
return 0;
})
ERROR_RETURN_CODE(
GENERIC_ERROR,
int caosdb_entity_entity_set_boolean_value(caosdb_entity_entity *entity,
const bool value),
{
auto *wrapped_entity =
static_cast<caosdb::entity::Entity *>(entity->wrapped_entity);
wrapped_entity->SetValue(value);
return 0;
})
ERROR_RETURN_CODE(
GENERIC_ERROR,
int caosdb_entity_entity_set_string_value(caosdb_entity_entity *entity,
const char *value),
{
auto *wrapped_entity =
static_cast<caosdb::entity::Entity *>(entity->wrapped_entity);
wrapped_entity->SetValue(std::string(value));
return 0;
})
ERROR_RETURN_CODE(GENERIC_ERROR,
int caosdb_entity_entity_set_int_list_value(
caosdb_entity_entity *entity, const long *value,
const int length),
{
auto *wrapped_entity =
static_cast<caosdb::entity::Entity *>(
entity->wrapped_entity);
std::vector<long> value_list;
for (int i = 0; i < length; i++) {
value_list.push_back(value[i]);
}
caosdb::entity::Value to_be_set(value_list);
wrapped_entity->SetValue(to_be_set);
return 0;
})
ERROR_RETURN_CODE(GENERIC_ERROR,
int caosdb_entity_entity_set_double_list_value(
caosdb_entity_entity *entity, const double *value,
const int length),
{
auto *wrapped_entity =
static_cast<caosdb::entity::Entity *>(
entity->wrapped_entity);
std::vector<double> value_list;
for (int i = 0; i < length; i++) {
value_list.push_back(value[i]);
}
caosdb::entity::Value to_be_set(value_list);
wrapped_entity->SetValue(to_be_set);
return 0;
})
ERROR_RETURN_CODE(GENERIC_ERROR,
int caosdb_entity_entity_set_boolean_list_value(
caosdb_entity_entity *entity, const bool *value,
const int length),
{
auto *wrapped_entity =
static_cast<caosdb::entity::Entity *>(
entity->wrapped_entity);
std::vector<bool> value_list;
for (int i = 0; i < length; i++) {
value_list.push_back(value[i]);
}
caosdb::entity::Value to_be_set(value_list);
wrapped_entity->SetValue(to_be_set);
return 0;
})
ERROR_RETURN_CODE(GENERIC_ERROR,
int caosdb_entity_entity_set_string_list_value(
caosdb_entity_entity *entity, const char **value,
const int length),
{
auto *wrapped_entity =
static_cast<caosdb::entity::Entity *>(
entity->wrapped_entity);
std::vector<std::string> value_list;
for (int i = 0; i < length; i++) {
value_list.push_back(std::string(value[i]));
}
caosdb::entity::Value to_be_set(value_list);
wrapped_entity->SetValue(to_be_set);
return 0;
})
ERROR_RETURN_CODE(
GENERIC_ERROR,
......@@ -846,7 +955,116 @@ CAOSDB_PROPERTY_SET(id, id, wrapped_property->SetId(std::string(id));)
// CAOSDB_PROPERTY_SET(importance, importance,
// wrapped_property->SetImportance(std::string(importance));)
CAOSDB_PROPERTY_SET(unit, unit, wrapped_property->SetUnit(std::string(unit));)
// TODO(fspreck)
// CAOSDB_PROPERTY_SET(value, value,
// wrapped_property->SetValue(std::string(value));)
ERROR_RETURN_CODE(
GENERIC_ERROR,
int caosdb_entity_property_set_int_value(caosdb_entity_property *property,
const long value),
{
auto *wrapped_property =
static_cast<caosdb::entity::Property *>(property->wrapped_property);
wrapped_property->SetValue(value);
return 0;
})
ERROR_RETURN_CODE(
GENERIC_ERROR,
int caosdb_entity_property_set_double_value(caosdb_entity_property *property,
const double value),
{
auto *wrapped_property =
static_cast<caosdb::entity::Property *>(property->wrapped_property);
wrapped_property->SetValue(value);
return 0;
})
ERROR_RETURN_CODE(
GENERIC_ERROR,
int caosdb_entity_property_set_boolean_value(caosdb_entity_property *property,
const bool value),
{
auto *wrapped_property =
static_cast<caosdb::entity::Property *>(property->wrapped_property);
wrapped_property->SetValue(value);
return 0;
})
ERROR_RETURN_CODE(
GENERIC_ERROR,
int caosdb_entity_property_set_string_value(caosdb_entity_property *property,
const char *value),
{
auto *wrapped_property =
static_cast<caosdb::entity::Property *>(property->wrapped_property);
wrapped_property->SetValue(std::string(value));
return 0;
})
ERROR_RETURN_CODE(GENERIC_ERROR,
int caosdb_entity_property_set_int_list_value(
caosdb_entity_property *property, const long *value,
const int length),
{
auto *wrapped_property =
static_cast<caosdb::entity::Property *>(
property->wrapped_property);
std::vector<long> value_list;
for (int i = 0; i < length; i++) {
value_list.push_back(value[i]);
}
caosdb::entity::Value to_be_set(value_list);
wrapped_property->SetValue(to_be_set);
return 0;
})
ERROR_RETURN_CODE(GENERIC_ERROR,
int caosdb_entity_property_set_double_list_value(
caosdb_entity_property *property, const double *value,
const int length),
{
auto *wrapped_property =
static_cast<caosdb::entity::Property *>(
property->wrapped_property);
std::vector<double> value_list;
for (int i = 0; i < length; i++) {
value_list.push_back(value[i]);
}
caosdb::entity::Value to_be_set(value_list);
wrapped_property->SetValue(to_be_set);
return 0;
})
ERROR_RETURN_CODE(GENERIC_ERROR,
int caosdb_entity_property_set_boolean_list_value(
caosdb_entity_property *property, const bool *value,
const int length),
{
auto *wrapped_property =
static_cast<caosdb::entity::Property *>(
property->wrapped_property);
std::vector<bool> value_list;
for (int i = 0; i < length; i++) {
value_list.push_back(value[i]);
}
caosdb::entity::Value to_be_set(value_list);
wrapped_property->SetValue(to_be_set);
return 0;
})
ERROR_RETURN_CODE(GENERIC_ERROR,
int caosdb_entity_property_set_string_list_value(
caosdb_entity_property *property, const char **value,
const int length),
{
auto *wrapped_property =
static_cast<caosdb::entity::Property *>(
property->wrapped_property);
std::vector<std::string> value_list;
for (int i = 0; i < length; i++) {
value_list.push_back(std::string(value[i]));
}
caosdb::entity::Value to_be_set(value_list);
wrapped_property->SetValue(to_be_set);
return 0;
})
}
......@@ -189,7 +189,7 @@ TEST_F(test_ccaosdb, test_entity) {
EXPECT_EQ(strcmp(out, "m"), 0);
// TODO(fspreck)
// caosdb_entity_entity_set_value(&entity, "5.0");
caosdb_entity_entity_set_double_value(&entity, 5.0);
// caosdb_entity_entity_get_value(&entity, out);
// EXPECT_EQ(strcmp(out, "5.0"), 0);
......@@ -226,12 +226,11 @@ TEST_F(test_ccaosdb, test_property) {
caosdb_entity_property_set_id(&property, "some_id");
caosdb_entity_property_set_name(&property, "some_name");
// TODO(fspreck)
// caosdb_entity_property_set_datatype(&property, "some_datatype");
// caosdb_entity_property_set_datatype(&property, "TEXT");
// TODO(fspreck)
// caosdb_entity_property_set_importance(&property, "some_importance");
// caosdb_entity_property_set_importance(&property, "FIX");
caosdb_entity_property_set_unit(&property, "some_unit");
// TODO(fspreck)
// caosdb_entity_property_set_value(&property, "some_value");
caosdb_entity_property_set_string_value(&property, "some_value");
char out[255] = {"a"}; // NOLINT
caosdb_entity_property_get_id(&property, out);
......@@ -242,23 +241,51 @@ TEST_F(test_ccaosdb, test_property) {
// TODO(fspreck)
// caosdb_entity_property_get_datatype(&property, out);
// EXPECT_EQ(strcmp(out, "some_datatype"), 0);
// EXPECT_EQ(strcmp(out, "TEXT"), 0);
// TODO(fspreck)
// caosdb_entity_property_get_importance(&property, out);
// EXPECT_EQ(strcmp(out, "some_importance"), 0);
// EXPECT_EQ(strcmp(out, "FIX"), 0);
caosdb_entity_property_get_unit(&property, out);
EXPECT_EQ(strcmp(out, "some_unit"), 0);
// TODO(fspreck)
// caosdb_entity_property_get_value(&property, out);
// caosdb_entity_property_get_string_value(&property, out);
// EXPECT_EQ(strcmp(out, "some_value"), 0);
return_code = caosdb_entity_delete_property(&property);
EXPECT_EQ(return_code, 0);
}
// TODO(fspreck) Test a property with datatype LIST<Something> and a
// list value.
TEST_F(test_ccaosdb, test_list_property) {
caosdb_entity_property property;
int return_code(caosdb_entity_create_property(&property));
EXPECT_EQ(return_code, 0);
// TODO(fspreck)
// return_code = caosdb_entity_property_set_datatype(&property, "LIST<TEXT>");
// EXPECT_EQ(return_code, 0);
const *char[] value_list = {"val0", "val1", "val2"}; // NOLINT
return_code = caosdb_entity_property_set_string_list_value(&property, value_list, 3);
EXPECT_EQ(return_code, 0);
// TODO(fspreck)
// char out_type[255] = {"abc"}; // NOLINT
// return_code = caosdb_entity_property_get_datatype(&property, out_type);
// EXPECT_EQ(return_code, 0);
// EXPECT_EQ(strcmp(out_type, "LIST<TEXT>"));
// TODO(fspreck) get and compare values in list
return_code = caosdb_entity_delete_property(&property);
EXPECT_EQ(return_code, 0);
}
TEST_F(test_ccaosdb, test_entity_with_parent_and_property) {
std::cout << "Creating objects ... " << std::endl;
caosdb_entity_parent input_parent;
......@@ -275,9 +302,8 @@ TEST_F(test_ccaosdb, test_entity_with_parent_and_property) {
caosdb_entity_property_set_id(&input_property, "property_id");
caosdb_entity_property_set_name(&input_property, "property_name");
// TODO(fspreck)
// caosdb_entity_property_set_datatype(&input_property, "property_datatype");
// TODO(fspreck)
// caosdb_entity_property_set_value(&input_property, "property_value");
// caosdb_entity_property_set_datatype(&input_property, "TEXT");
caosdb_entity_property_set_string_value(&input_property, "property_value");
caosdb_entity_entity entity;
return_code = caosdb_entity_create_entity(&entity);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment