Skip to content
Snippets Groups Projects
Commit 09f305f4 authored by florian's avatar florian
Browse files

ENH: Add get_list_value_at getters

parent 4336c440
Branches
Tags
1 merge request!13ENH: Add datatypes and value classes to Extern C interface
...@@ -332,10 +332,14 @@ int caosdb_entity_entity_get_int_value(caosdb_entity_entity *entity, long *out); ...@@ -332,10 +332,14 @@ int caosdb_entity_entity_get_int_value(caosdb_entity_entity *entity, long *out);
int caosdb_entity_entity_get_double_value(caosdb_entity_entity *entity, double *out); int caosdb_entity_entity_get_double_value(caosdb_entity_entity *entity, double *out);
int caosdb_entity_entity_get_boolean_value(caosdb_entity_entity *entity, bool *out); int caosdb_entity_entity_get_boolean_value(caosdb_entity_entity *entity, bool *out);
int caosdb_entity_entity_get_string_value(caosdb_entity_entity *entity, char **out); int caosdb_entity_entity_get_string_value(caosdb_entity_entity *entity, char **out);
int caosdb_entity_entity_get_int_list_value(caosdb_entity_entity *entity, long *out); int caosdb_entity_entity_get_int_list_value_at(caosdb_entity_entity *entity, long *out,
int caosdb_entity_entity_get_double_list_value(caosdb_entity_entity *entity, double *out); const int index);
int caosdb_entity_entity_get_boolean_list_value(caosdb_entity_entity *entity, bool *out); int caosdb_entity_entity_get_double_list_value_at(caosdb_entity_entity *entity, double *out,
int caosdb_entity_entity_get_string_list_value(caosdb_entity_entity *entity, char **out); const int index);
int caosdb_entity_entity_get_boolean_list_value_at(caosdb_entity_entity *entity, bool *out,
const int index);
int caosdb_entity_entity_get_string_list_value_at(caosdb_entity_entity *entity, char **out,
const int index);
int caosdb_entity_entity_get_value_list_length(caosdb_entity_entity *entity, int *out); int caosdb_entity_entity_get_value_list_length(caosdb_entity_entity *entity, int *out);
int caosdb_entity_entity_get_version_id(caosdb_entity_entity *entity, char **out); int caosdb_entity_entity_get_version_id(caosdb_entity_entity *entity, char **out);
...@@ -366,10 +370,14 @@ int caosdb_entity_property_get_int_value(caosdb_entity_property *property, long ...@@ -366,10 +370,14 @@ int caosdb_entity_property_get_int_value(caosdb_entity_property *property, long
int caosdb_entity_property_get_double_value(caosdb_entity_property *property, double *out); int caosdb_entity_property_get_double_value(caosdb_entity_property *property, double *out);
int caosdb_entity_property_get_boolean_value(caosdb_entity_property *property, bool *out); int caosdb_entity_property_get_boolean_value(caosdb_entity_property *property, bool *out);
int caosdb_entity_property_get_string_value(caosdb_entity_property *property, char **out); int caosdb_entity_property_get_string_value(caosdb_entity_property *property, char **out);
int caosdb_entity_property_get_int_list_value(caosdb_entity_property *property, long **out); int caosdb_entity_property_get_int_list_value_at(caosdb_entity_property *property, long *out,
int caosdb_entity_property_get_double_list_value(caosdb_entity_property *property, double *out); const int index);
int caosdb_entity_property_get_boolean_list_value(caosdb_entity_property *property, bool *out); int caosdb_entity_property_get_double_list_value_at(caosdb_entity_property *property, double *out,
int caosdb_entity_property_get_string_list_value(caosdb_entity_property *property, char ***out); const int index);
int caosdb_entity_property_get_boolean_list_value_at(caosdb_entity_property *property, bool *out,
const int index);
int caosdb_entity_property_get_string_list_value_at(caosdb_entity_property *property, char **out,
const int index);
int caosdb_entity_property_get_value_list_length(caosdb_entity_property *property, int *out); int caosdb_entity_property_get_value_list_length(caosdb_entity_property *property, int *out);
int caosdb_entity_parent_get_id(caosdb_entity_parent *parent, char **out); int caosdb_entity_parent_get_id(caosdb_entity_parent *parent, char **out);
......
...@@ -566,16 +566,45 @@ ERROR_RETURN_CODE(GENERIC_ERROR, ...@@ -566,16 +566,45 @@ ERROR_RETURN_CODE(GENERIC_ERROR,
return 0; return 0;
}) })
CAOSDB_ENTITY_GET(string_value, GetValue().AsString) CAOSDB_ENTITY_GET(string_value, GetValue().AsString)
ERROR_RETURN_CODE(GENERIC_ERROR, ERROR_RETURN_CODE(GENERIC_ERROR,
int caosdb_entity_entity_get_int_list_value(caosdb_entity_entity *entity, int caosdb_entity_entity_get_int_list_value_at(caosdb_entity_entity *entity,
long *out), long *out, const int index),
{ {
auto *wrapped_entity = WRAPPED_ENTITY_CAST(entity); auto *wrapped_entity = WRAPPED_ENTITY_CAST(entity);
auto value_list = wrapped_entity->GetValue().AsList(); auto value_list = wrapped_entity->GetValue().AsList();
int i = 0; *out = value_list[index].AsInteger();
for (const auto elt : value_list) { return 0;
out[i++] = elt.AsInteger(); })
} ERROR_RETURN_CODE(GENERIC_ERROR,
int caosdb_entity_entity_get_double_list_value_at(caosdb_entity_entity *entity,
double *out, const int index),
{
auto *wrapped_entity = WRAPPED_ENTITY_CAST(entity);
auto value_list = wrapped_entity->GetValue().AsList();
*out = value_list[index].AsDouble();
return 0;
})
ERROR_RETURN_CODE(GENERIC_ERROR,
int caosdb_entity_entity_get_boolean_value_list_value_at(
caosdb_entity_entity *entity, bool *out, const int index),
{
auto *wrapped_entity = WRAPPED_ENTITY_CAST(entity);
auto value_list = wrapped_entity->GetValue().AsList();
*out = value_list[index].AsBool();
return 0;
})
ERROR_RETURN_CODE(GENERIC_ERROR,
int caosdb_entity_entity_get_string_list_value_at(caosdb_entity_entity *entity,
char **out, const int index),
{
auto *wrapped_entity = WRAPPED_ENTITY_CAST(entity);
auto value_list = wrapped_entity->GetValue().AsList();
char *tmp =
(char *)malloc(sizeof(char) * value_list[index].AsString().length() + 1);
strcpy(tmp, value_list[index].AsString().c_str());
delete[] * out;
*out = tmp;
return 0; return 0;
}) })
...@@ -754,6 +783,47 @@ ERROR_RETURN_CODE(GENERIC_ERROR, ...@@ -754,6 +783,47 @@ ERROR_RETURN_CODE(GENERIC_ERROR,
}) })
CAOSDB_PROPERTY_GET(string_value, GetValue().AsString) CAOSDB_PROPERTY_GET(string_value, GetValue().AsString)
ERROR_RETURN_CODE(GENERIC_ERROR,
int caosdb_entity_property_get_int_list_value_at(caosdb_entity_property *property,
long *out, const int index),
{
auto *wrapped_property = WRAPPED_PROPERTY_CAST(property);
auto value_list = wrapped_property->GetValue().AsList();
*out = value_list[index].AsInteger();
return 0;
})
ERROR_RETURN_CODE(GENERIC_ERROR,
int caosdb_entity_property_get_double_list_value_at(
caosdb_entity_property *property, double *out, const int index),
{
auto *wrapped_property = WRAPPED_PROPERTY_CAST(property);
auto value_list = wrapped_property->GetValue().AsList();
*out = value_list[index].AsDouble();
return 0;
})
ERROR_RETURN_CODE(GENERIC_ERROR,
int caosdb_entity_property_get_boolean_value_list_value_at(
caosdb_entity_property *property, bool *out, const int index),
{
auto *wrapped_property = WRAPPED_PROPERTY_CAST(property);
auto value_list = wrapped_property->GetValue().AsList();
*out = value_list[index].AsBool();
return 0;
})
ERROR_RETURN_CODE(GENERIC_ERROR,
int caosdb_entity_property_get_string_list_value_at(
caosdb_entity_property *property, char **out, const int index),
{
auto *wrapped_property = WRAPPED_PROPERTY_CAST(property);
auto value_list = wrapped_property->GetValue().AsList();
char *tmp =
(char *)malloc(sizeof(char) * value_list[index].AsString().length() + 1);
strcpy(tmp, value_list[index].AsString().c_str());
delete[] * out;
*out = tmp;
return 0;
})
// TODO(fspreck) Fix this somehow. It segfaults. Bleh. // TODO(fspreck) Fix this somehow. It segfaults. Bleh.
// ERROR_RETURN_CODE(GENERIC_ERROR, // ERROR_RETURN_CODE(GENERIC_ERROR,
// int caosdb_entity_property_get_string_list_value( // int caosdb_entity_property_get_string_list_value(
......
...@@ -277,14 +277,12 @@ TEST_F(test_ccaosdb, test_list_property) { ...@@ -277,14 +277,12 @@ TEST_F(test_ccaosdb, test_list_property) {
EXPECT_EQ(*length, 3); EXPECT_EQ(*length, 3);
// TODO(fspreck) get and compare values in list. Segfaults as it is right now. // TODO(fspreck) get and compare values in list. Segfaults as it is right now.
// char **out_list = nullptr; // NOLINT char *out = nullptr; // NOLINT
// std::cout << "Getting list values" << std::endl; for (int i = 0; i < *length; i++) {
// return_code = return_code = caosdb_entity_property_get_string_list_value_at(&property, &out, i);
// caosdb_entity_property_get_string_list_value(&property, &out_list); EXPECT_EQ(return_code, 0);
// EXPECT_EQ(return_code, 0); EXPECT_EQ(strcmp(value_list[i], out), 0); // NOLINT
// for (int i = 0; i < *length; i++) { }
// EXPECT_EQ(strcmp(value_list[i], out_list[i]), 0); // NOLINT
// }
return_code = caosdb_entity_delete_property(&property); return_code = caosdb_entity_delete_property(&property);
EXPECT_EQ(return_code, 0); EXPECT_EQ(return_code, 0);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment