Skip to content
Snippets Groups Projects
Commit 567276d2 authored by florian's avatar florian
Browse files

DRAFT: Continue setters and getters

parent 1da6c37a
Branches
Tags
1 merge request!13ENH: Add datatypes and value classes to Extern C interface
Pipeline #12256 failed
...@@ -334,13 +334,13 @@ typedef struct { ...@@ -334,13 +334,13 @@ typedef struct {
} caosdb_entity_message; } caosdb_entity_message;
// GETTERS FOR EVERYTHING // GETTERS FOR EVERYTHING
int caosdb_entity_entity_get_id(caosdb_entity_entity *entity, char *out); int caosdb_entity_entity_get_id(caosdb_entity_entity *entity, char **out);
int caosdb_entity_entity_get_role(caosdb_entity_entity *entity, char *out); int caosdb_entity_entity_get_role(caosdb_entity_entity *entity, char **out);
int caosdb_entity_entity_get_name(caosdb_entity_entity *entity, char *out); int caosdb_entity_entity_get_name(caosdb_entity_entity *entity, char **out);
int caosdb_entity_entity_get_description(caosdb_entity_entity *entity, int caosdb_entity_entity_get_description(caosdb_entity_entity *entity,
char *out); char **out);
int caosdb_entity_entity_get_datatype(caosdb_entity_entity *entity, char *out); int caosdb_entity_entity_get_datatype(caosdb_entity_entity *entity, char **out);
int caosdb_entity_entity_get_unit(caosdb_entity_entity *entity, char *out); int caosdb_entity_entity_get_unit(caosdb_entity_entity *entity, char **out);
int caosdb_entity_entity_get_int_value(caosdb_entity_entity *entity, long *out); int caosdb_entity_entity_get_int_value(caosdb_entity_entity *entity, long *out);
int caosdb_entity_entity_get_double_value(caosdb_entity_entity *entity, int caosdb_entity_entity_get_double_value(caosdb_entity_entity *entity,
...@@ -348,18 +348,20 @@ int caosdb_entity_entity_get_double_value(caosdb_entity_entity *entity, ...@@ -348,18 +348,20 @@ int caosdb_entity_entity_get_double_value(caosdb_entity_entity *entity,
int caosdb_entity_entity_get_boolean_value(caosdb_entity_entity *entity, int caosdb_entity_entity_get_boolean_value(caosdb_entity_entity *entity,
bool *out); bool *out);
int caosdb_entity_entity_get_string_value(caosdb_entity_entity *entity, int caosdb_entity_entity_get_string_value(caosdb_entity_entity *entity,
char *out); char **out);
int caosdb_entity_entity_get_int_list_value(caosdb_entity_entity *entity, int caosdb_entity_entity_get_int_list_value(caosdb_entity_entity *entity,
long **out); long *out);
int caosdb_entity_entity_get_double_list_value(caosdb_entity_entity *entity, int caosdb_entity_entity_get_double_list_value(caosdb_entity_entity *entity,
double **out); double *out);
int caosdb_entity_entity_get_boolean_list_value(caosdb_entity_entity *entity, int caosdb_entity_entity_get_boolean_list_value(caosdb_entity_entity *entity,
bool **out); bool *out);
int caosdb_entity_entity_get_string_list_value(caosdb_entity_entity *entity, int caosdb_entity_entity_get_string_list_value(caosdb_entity_entity *entity,
char **out); char **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, int caosdb_entity_entity_get_version_id(caosdb_entity_entity *entity,
char *out); char **out);
int caosdb_entity_entity_get_errors_size(caosdb_entity_entity *entity, int caosdb_entity_entity_get_errors_size(caosdb_entity_entity *entity,
int *out); int *out);
int caosdb_entity_entity_get_error(caosdb_entity_entity *entity, int caosdb_entity_entity_get_error(caosdb_entity_entity *entity,
...@@ -380,17 +382,17 @@ int caosdb_entity_entity_get_parents_size(caosdb_entity_entity *entity, ...@@ -380,17 +382,17 @@ int caosdb_entity_entity_get_parents_size(caosdb_entity_entity *entity,
int caosdb_entity_entity_get_parent(caosdb_entity_entity *entity, int caosdb_entity_entity_get_parent(caosdb_entity_entity *entity,
caosdb_entity_parent *out, int index); caosdb_entity_parent *out, int index);
int caosdb_entity_property_get_id(caosdb_entity_property *property, char *out); int caosdb_entity_property_get_id(caosdb_entity_property *property, char **out);
int caosdb_entity_property_get_name(caosdb_entity_property *property, int caosdb_entity_property_get_name(caosdb_entity_property *property,
char *out); char **out);
int caosdb_entity_property_get_description(caosdb_entity_property *property, int caosdb_entity_property_get_description(caosdb_entity_property *property,
char *out); char **out);
int caosdb_entity_property_get_importance(caosdb_entity_property *property, int caosdb_entity_property_get_importance(caosdb_entity_property *property,
char *out); char **out);
int caosdb_entity_property_get_datatype(caosdb_entity_property *property, int caosdb_entity_property_get_datatype(caosdb_entity_property *property,
char *out); char **out);
int caosdb_entity_property_get_unit(caosdb_entity_property *property, int caosdb_entity_property_get_unit(caosdb_entity_property *property,
char *out); char **out);
int caosdb_entity_property_get_int_value(caosdb_entity_property *property, int caosdb_entity_property_get_int_value(caosdb_entity_property *property,
long *out); long *out);
...@@ -399,24 +401,26 @@ int caosdb_entity_property_get_double_value(caosdb_entity_property *property, ...@@ -399,24 +401,26 @@ int caosdb_entity_property_get_double_value(caosdb_entity_property *property,
int caosdb_entity_property_get_boolean_value(caosdb_entity_property *property, int caosdb_entity_property_get_boolean_value(caosdb_entity_property *property,
bool *out); bool *out);
int caosdb_entity_property_get_string_value(caosdb_entity_property *property, int caosdb_entity_property_get_string_value(caosdb_entity_property *property,
char *out); char **out);
int caosdb_entity_property_get_int_list_value(caosdb_entity_property *property, int caosdb_entity_property_get_int_list_value(caosdb_entity_property *property,
long **out); long **out);
int caosdb_entity_property_get_double_list_value( int caosdb_entity_property_get_double_list_value(
caosdb_entity_property *property, double **out); caosdb_entity_property *property, double *out);
int caosdb_entity_property_get_boolean_list_value( int caosdb_entity_property_get_boolean_list_value(
caosdb_entity_property *property, bool **out); caosdb_entity_property *property, bool *out);
int caosdb_entity_property_get_string_list_value( int caosdb_entity_property_get_string_list_value(
caosdb_entity_property *property, char **out); caosdb_entity_property *property, char *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);
int caosdb_entity_parent_get_name(caosdb_entity_parent *parent, char *out); int caosdb_entity_parent_get_name(caosdb_entity_parent *parent, char **out);
int caosdb_entity_parent_get_description(caosdb_entity_parent *parent, int caosdb_entity_parent_get_description(caosdb_entity_parent *parent,
char *out); char **out);
int caosdb_entity_message_get_code(caosdb_entity_message *message, int *out); int caosdb_entity_message_get_code(caosdb_entity_message *message, int *out);
int caosdb_entity_message_get_description(caosdb_entity_message *message, int caosdb_entity_message_get_description(caosdb_entity_message *message,
char *out); char **out);
// CONSTRUCTORS AND DESTRUCTORS // CONSTRUCTORS AND DESTRUCTORS
int caosdb_entity_create_entity(caosdb_entity_entity *out); int caosdb_entity_create_entity(caosdb_entity_entity *out);
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "ccaosdb.h" #include "ccaosdb.h"
#include "caosdb/connection.h" #include "caosdb/connection.h"
#include "caosdb/constants.h" #include "caosdb/constants.h"
#include "caosdb/data_type.h" // for DataType, AtomicDat...
#include "caosdb/utility.h" #include "caosdb/utility.h"
#include "caosdb/status_code.h" #include "caosdb/status_code.h"
#include "caosdb/logging.h" #include "caosdb/logging.h"
...@@ -37,6 +38,18 @@ extern "C" { ...@@ -37,6 +38,18 @@ extern "C" {
#define CCAOSDB_LOGGER_NAME "ccaosdb" #define CCAOSDB_LOGGER_NAME "ccaosdb"
#define WRAPPED_ENTITY_CAST(name) \
static_cast<caosdb::entity::Entity *>(name->wrapped_entity)
#define WRAPPED_PROPERTY_CAST(name) \
static_cast<caosdb::entity::Property *>(name->wrapped_property)
#define WRAPPED_PARENT_CAST(name) \
static_cast<caosdb::entity::Parent *>(name->wrapped_parent)
#define WRAPPED_MESSAGE_CAST(name) \
static_cast<caosdb::entity::Message *>(name->wrapped_message)
/* /*
* Macro for wrapping every function into a try-catch clause. If an exception * Macro for wrapping every function into a try-catch clause. If an exception
* occurs, the given StatusCode is being returned. * occurs, the given StatusCode is being returned.
...@@ -55,86 +68,93 @@ extern "C" { ...@@ -55,86 +68,93 @@ extern "C" {
/** /**
* Macro for entity getters * Macro for entity getters
*/ */
#define CAOSDB_ENTITY_GET(element, body_part) \ #define CAOSDB_ENTITY_GET(element, GetFunction) \
ERROR_RETURN_CODE( \ ERROR_RETURN_CODE( \
GENERIC_ERROR, \ GENERIC_ERROR, \
int caosdb_entity_entity_get_##element(caosdb_entity_entity *entity, \ int caosdb_entity_entity_get_##element(caosdb_entity_entity *entity, \
char *out), \ char **out), \
{ \ { \
auto *wrapped_entity = \ auto *wrapped_entity = WRAPPED_ENTITY_CAST(entity); \
static_cast<caosdb::entity::Entity *>(entity->wrapped_entity); \ char *tmp = (char *)malloc( \
body_part return 0; \ sizeof(char) * wrapped_entity->GetFunction().length() + 1); \
strcpy(tmp, wrapped_entity->GetFunction().c_str()); \
delete[] * out; \
*out = tmp; \
return 0; \
}) })
/** /**
* Macro for entity setters * Macro for entity setters
*/ */
#define CAOSDB_ENTITY_SET(element, value, body_part) \ #define CAOSDB_ENTITY_SET(element, value, body_part) \
ERROR_RETURN_CODE( \ ERROR_RETURN_CODE(GENERIC_ERROR, \
GENERIC_ERROR, \ int caosdb_entity_entity_set_##element( \
int caosdb_entity_entity_set_##element(caosdb_entity_entity *entity, \ caosdb_entity_entity *entity, const char *value), \
const char *value), \ { \
{ \ auto *wrapped_entity = WRAPPED_ENTITY_CAST(entity); \
auto *wrapped_entity = \ body_part return 0; \
static_cast<caosdb::entity::Entity *>(entity->wrapped_entity); \ })
body_part return 0; \
})
/** /**
* Macro for property getters * Macro for property getters
*/ */
#define CAOSDB_PROPERTY_GET(element, body_part) \ #define CAOSDB_PROPERTY_GET(element, GetFunction) \
ERROR_RETURN_CODE( \ ERROR_RETURN_CODE( \
GENERIC_ERROR, \ GENERIC_ERROR, \
int caosdb_entity_property_get_##element(caosdb_entity_property *property, \ int caosdb_entity_property_get_##element(caosdb_entity_property *property, \
char *out), \ char **out), \
{ \ { \
auto *wrapped_property = \ auto *wrapped_property = WRAPPED_PROPERTY_CAST(property); \
static_cast<caosdb::entity::Property *>(property->wrapped_property); \ char *tmp = (char *)malloc( \
body_part return 0; \ sizeof(char) * wrapped_property->GetFunction().length() + 1); \
strcpy(tmp, wrapped_property->GetFunction().c_str()); \
delete[] * out; \
*out = tmp; \
return 0; \
}) })
/** /**
* Macro for property setters * Macro for property setters
*/ */
#define CAOSDB_PROPERTY_SET(element, value, body_part) \ #define CAOSDB_PROPERTY_SET(element, value, body_part) \
ERROR_RETURN_CODE( \ ERROR_RETURN_CODE(GENERIC_ERROR, \
GENERIC_ERROR, \ int caosdb_entity_property_set_##element( \
int caosdb_entity_property_set_##element(caosdb_entity_property *property, \ caosdb_entity_property *property, const char *value), \
const char *value), \ { \
{ \ auto *wrapped_property = \
auto *wrapped_property = \ WRAPPED_PROPERTY_CAST(property); \
static_cast<caosdb::entity::Property *>(property->wrapped_property); \ body_part return 0; \
body_part return 0; \ })
})
/** /**
* Macro for parent getters * Macro for parent getters
*/ */
#define CAOSDB_PARENT_GET(element, body_part) \ #define CAOSDB_PARENT_GET(element, GetFunction) \
ERROR_RETURN_CODE( \ ERROR_RETURN_CODE( \
GENERIC_ERROR, \ GENERIC_ERROR, \
int caosdb_entity_parent_get_##element(caosdb_entity_parent *parent, \ int caosdb_entity_parent_get_##element(caosdb_entity_parent *parent, \
char *out), \ char **out), \
{ \ { \
auto *wrapped_parent = \ auto *wrapped_parent = WRAPPED_PARENT_CAST(parent); \
static_cast<caosdb::entity::Parent *>(parent->wrapped_parent); \ char *tmp = (char *)malloc( \
body_part return 0; \ sizeof(char) * wrapped_parent->GetFunction().length() + 1); \
strcpy(tmp, wrapped_parent->GetFunction().c_str()); \
delete[] * out; \
*out = tmp; \
return 0; \
}) })
/** /**
* Macro for parent setters * Macro for parent setters
*/ */
#define CAOSDB_PARENT_SET(element, value, body_part) \ #define CAOSDB_PARENT_SET(element, value, body_part) \
ERROR_RETURN_CODE( \ ERROR_RETURN_CODE(GENERIC_ERROR, \
GENERIC_ERROR, \ int caosdb_entity_parent_set_##element( \
int caosdb_entity_parent_set_##element(caosdb_entity_parent *parent, \ caosdb_entity_parent *parent, const char *value), \
const char *value), \ { \
{ \ auto *wrapped_parent = WRAPPED_PARENT_CAST(parent); \
auto *wrapped_parent = \ body_part return 0; \
static_cast<caosdb::entity::Parent *>(parent->wrapped_parent); \ })
body_part return 0; \
})
int caosdb_constants_LIBCAOSDB_VERSION_MAJOR() { int caosdb_constants_LIBCAOSDB_VERSION_MAJOR() {
return caosdb::LIBCAOSDB_VERSION_MAJOR; return caosdb::LIBCAOSDB_VERSION_MAJOR;
...@@ -588,20 +608,69 @@ ERROR_RETURN_CODE(GENERIC_ERROR, ...@@ -588,20 +608,69 @@ ERROR_RETURN_CODE(GENERIC_ERROR,
return 0; return 0;
}) })
CAOSDB_ENTITY_GET(id, strcpy(out, wrapped_entity->GetId().c_str());) CAOSDB_ENTITY_GET(id, GetId)
// TODO(fspreck) // TODO(fspreck)
// CAOSDB_ENTITY_GET(role, strcpy(out, wrapped_entity->GetRole().c_str());) // CAOSDB_ENTITY_GET(role, strcpy(out, wrapped_entity->GetRole().c_str());)
CAOSDB_ENTITY_GET(name, strcpy(out, wrapped_entity->GetName().c_str());) CAOSDB_ENTITY_GET(name, GetName)
CAOSDB_ENTITY_GET(description, CAOSDB_ENTITY_GET(description, GetDescription)
strcpy(out, wrapped_entity->GetDescription().c_str());)
// TODO(fspreck) // TODO(fspreck)
// CAOSDB_ENTITY_GET(datatype, strcpy(out, // CAOSDB_ENTITY_GET(datatype, strcpy(out,
// wrapped_entity->GetDatatype().c_str());) // wrapped_entity->GetDatatype().c_str());)
// TODO(fspreck) // TODO(fspreck)
// CAOSDB_ENTITY_GET(value, strcpy(out, wrapped_entity->GetValue().c_str());) // CAOSDB_ENTITY_GET(value, strcpy(out, wrapped_entity->GetValue().c_str());)
CAOSDB_ENTITY_GET(unit, strcpy(out, wrapped_entity->GetUnit().c_str());) ERROR_RETURN_CODE(GENERIC_ERROR,
CAOSDB_ENTITY_GET(version_id, int caosdb_entity_entity_get_int_value(
strcpy(out, wrapped_entity->GetVersionId().c_str());) caosdb_entity_entity *entity, long *out),
{
auto *wrapped_entity = WRAPPED_ENTITY_CAST(entity);
*out = wrapped_entity->GetValue().AsInteger();
return 0;
})
ERROR_RETURN_CODE(GENERIC_ERROR,
int caosdb_entity_entity_get_double_value(
caosdb_entity_entity *entity, double *out),
{
auto *wrapped_entity = WRAPPED_ENTITY_CAST(entity);
*out = wrapped_entity->GetValue().AsDouble();
return 0;
})
ERROR_RETURN_CODE(GENERIC_ERROR,
int caosdb_entity_entity_get_boolean_value(
caosdb_entity_entity *entity, bool *out),
{
auto *wrapped_entity = WRAPPED_ENTITY_CAST(entity);
*out = wrapped_entity->GetValue().AsBool();
return 0;
})
CAOSDB_ENTITY_GET(string_value, GetValue().AsString)
ERROR_RETURN_CODE(GENERIC_ERROR,
int caosdb_entity_entity_get_int_list_value(
caosdb_entity_entity *entity, long *out),
{
auto *wrapped_entity = WRAPPED_ENTITY_CAST(entity);
auto value_list = wrapped_entity->GetValue().AsList();
int i = 0;
for (const auto elt : value_list) {
out[i++] = elt.AsInteger();
}
return 0;
})
ERROR_RETURN_CODE(GENERIC_ERROR,
int caosdb_entity_entity_get_value_list_length(
caosdb_entity_entity *entity, int *out),
{
auto *wrapped_entity = WRAPPED_ENTITY_CAST(entity);
if (wrapped_entity->GetValue().IsList()) {
*out = wrapped_entity->GetValue().AsList().size();
} else {
*out = 0;
}
return 0;
})
CAOSDB_ENTITY_GET(unit, GetUnit)
CAOSDB_ENTITY_GET(version_id, GetVersionId)
ERROR_RETURN_CODE( ERROR_RETURN_CODE(
GENERIC_ERROR, GENERIC_ERROR,
...@@ -733,25 +802,77 @@ ERROR_RETURN_CODE( ...@@ -733,25 +802,77 @@ ERROR_RETURN_CODE(
return 0; return 0;
}) })
CAOSDB_PARENT_GET(id, strcpy(out, wrapped_parent->GetId().c_str());) CAOSDB_PARENT_GET(id, GetId)
CAOSDB_PARENT_GET(name, strcpy(out, wrapped_parent->GetName().c_str());) CAOSDB_PARENT_GET(name, GetName)
CAOSDB_PARENT_GET(description, CAOSDB_PARENT_GET(description, GetDescription)
strcpy(out, wrapped_parent->GetDescription().c_str());)
CAOSDB_PROPERTY_GET(id, strcpy(out, wrapped_property->GetId().c_str());) CAOSDB_PROPERTY_GET(id, GetId)
CAOSDB_PROPERTY_GET(name, strcpy(out, wrapped_property->GetName().c_str());) CAOSDB_PROPERTY_GET(name, GetName)
CAOSDB_PROPERTY_GET(description, CAOSDB_PROPERTY_GET(description, GetDescription)
strcpy(out, wrapped_property->GetDescription().c_str());)
// TODO(fspreck) // TODO(fspreck)
// CAOSDB_PROPERTY_GET(importance, // CAOSDB_PROPERTY_GET(importance,
// strcpy(out, wrapped_property->GetImportance().c_str());) // strcpy(out, wrapped_property->GetImportance().c_str());)
// TODO(fspreck) // TODO(fspreck)
// CAOSDB_PROPERTY_GET(datatype, // CAOSDB_PROPERTY_GET(datatype,
// strcpy(out, wrapped_property->GetDatatype().c_str());) // strcpy(out, wrapped_property->GetDatatype().c_str());)
CAOSDB_PROPERTY_GET(unit, strcpy(out, wrapped_property->GetUnit().c_str());) CAOSDB_PROPERTY_GET(unit, GetUnit)
// TODO(fspreck) // TODO(fspreck)
// CAOSDB_PROPERTY_GET(value, strcpy(out, // CAOSDB_PROPERTY_GET(value, strcpy(out,
// wrapped_property->GetValue().c_str());) // wrapped_property->GetValue().c_str());)
ERROR_RETURN_CODE(GENERIC_ERROR,
int caosdb_entity_property_get_int_value(
caosdb_entity_property *property, long *out),
{
auto *wrapped_property = WRAPPED_PROPERTY_CAST(property);
*out = wrapped_property->GetValue().AsInteger();
return 0;
})
ERROR_RETURN_CODE(GENERIC_ERROR,
int caosdb_entity_property_get_double_value(
caosdb_entity_property *property, double *out),
{
auto *wrapped_property = WRAPPED_PROPERTY_CAST(property);
*out = wrapped_property->GetValue().AsDouble();
return 0;
})
ERROR_RETURN_CODE(GENERIC_ERROR,
int caosdb_entity_property_get_boolean_value(
caosdb_entity_property *property, bool *out),
{
auto *wrapped_property = WRAPPED_PROPERTY_CAST(property);
*out = wrapped_property->GetValue().AsBool();
return 0;
})
CAOSDB_PROPERTY_GET(string_value, GetValue().AsString)
ERROR_RETURN_CODE(GENERIC_ERROR,
int caosdb_entity_property_get_string_list_value(
caosdb_entity_property *property, char *out[]),
{
auto *wrapped_property = WRAPPED_PROPERTY_CAST(property);
auto value_list = wrapped_property->GetValue().AsList();
char *tmp;
int i = 0;
for (const auto elt : value_list) {
tmp = (char *)(sizeof(char) * elt.AsString().length());
strcpy(tmp, elt.AsString().c_str());
out[i++] = tmp;
}
return 0;
})
ERROR_RETURN_CODE(GENERIC_ERROR,
int caosdb_entity_property_get_value_list_length(
caosdb_entity_property *property, int *out),
{
auto *wrapped_property = WRAPPED_PROPERTY_CAST(property);
if (wrapped_property->GetValue().IsList()) {
*out = wrapped_property->GetValue().AsList().size();
} else {
*out = 0;
}
return 0;
})
ERROR_RETURN_CODE( ERROR_RETURN_CODE(
GENERIC_ERROR, GENERIC_ERROR,
...@@ -766,11 +887,15 @@ ERROR_RETURN_CODE( ...@@ -766,11 +887,15 @@ ERROR_RETURN_CODE(
ERROR_RETURN_CODE( ERROR_RETURN_CODE(
GENERIC_ERROR, GENERIC_ERROR,
int caosdb_entity_message_get_description(caosdb_entity_message *message, int caosdb_entity_message_get_description(caosdb_entity_message *message,
char *out), char **out),
{ {
auto *wrapped_message = auto *wrapped_message =
static_cast<caosdb::entity::Message *>(message->wrapped_message); static_cast<caosdb::entity::Message *>(message->wrapped_message);
strcpy(out, wrapped_message->GetDescription().c_str()); char *tmp = (char *)malloc(
sizeof(char) * wrapped_message->GetDescription().length() + 1);
strcpy(tmp, wrapped_message->GetDescription().c_str());
delete[] * out;
*out = tmp;
return 0; return 0;
}) })
...@@ -787,7 +912,7 @@ CAOSDB_ENTITY_SET(unit, unit, wrapped_entity->SetUnit(std::string(unit));) ...@@ -787,7 +912,7 @@ CAOSDB_ENTITY_SET(unit, unit, wrapped_entity->SetUnit(std::string(unit));)
ERROR_RETURN_CODE( ERROR_RETURN_CODE(
GENERIC_ERROR, GENERIC_ERROR,
int caosdb_entity_entity_set_int_value(caosdb_entity_entity *entity, int caosdb_entity_entity_set_int_value(caosdb_entity_entity *entity,
const long value), const long value),
{ {
auto *wrapped_entity = auto *wrapped_entity =
static_cast<caosdb::entity::Entity *>(entity->wrapped_entity); static_cast<caosdb::entity::Entity *>(entity->wrapped_entity);
...@@ -798,7 +923,7 @@ ERROR_RETURN_CODE( ...@@ -798,7 +923,7 @@ ERROR_RETURN_CODE(
ERROR_RETURN_CODE( ERROR_RETURN_CODE(
GENERIC_ERROR, GENERIC_ERROR,
int caosdb_entity_entity_set_double_value(caosdb_entity_entity *entity, int caosdb_entity_entity_set_double_value(caosdb_entity_entity *entity,
const double value), const double value),
{ {
auto *wrapped_entity = auto *wrapped_entity =
static_cast<caosdb::entity::Entity *>(entity->wrapped_entity); static_cast<caosdb::entity::Entity *>(entity->wrapped_entity);
...@@ -809,7 +934,7 @@ ERROR_RETURN_CODE( ...@@ -809,7 +934,7 @@ ERROR_RETURN_CODE(
ERROR_RETURN_CODE( ERROR_RETURN_CODE(
GENERIC_ERROR, GENERIC_ERROR,
int caosdb_entity_entity_set_boolean_value(caosdb_entity_entity *entity, int caosdb_entity_entity_set_boolean_value(caosdb_entity_entity *entity,
const bool value), const bool value),
{ {
auto *wrapped_entity = auto *wrapped_entity =
static_cast<caosdb::entity::Entity *>(entity->wrapped_entity); static_cast<caosdb::entity::Entity *>(entity->wrapped_entity);
...@@ -820,7 +945,7 @@ ERROR_RETURN_CODE( ...@@ -820,7 +945,7 @@ ERROR_RETURN_CODE(
ERROR_RETURN_CODE( ERROR_RETURN_CODE(
GENERIC_ERROR, GENERIC_ERROR,
int caosdb_entity_entity_set_string_value(caosdb_entity_entity *entity, int caosdb_entity_entity_set_string_value(caosdb_entity_entity *entity,
const char *value), const char *value),
{ {
auto *wrapped_entity = auto *wrapped_entity =
static_cast<caosdb::entity::Entity *>(entity->wrapped_entity); static_cast<caosdb::entity::Entity *>(entity->wrapped_entity);
...@@ -828,73 +953,69 @@ ERROR_RETURN_CODE( ...@@ -828,73 +953,69 @@ ERROR_RETURN_CODE(
return 0; return 0;
}) })
ERROR_RETURN_CODE(GENERIC_ERROR, ERROR_RETURN_CODE(
int caosdb_entity_entity_set_int_list_value( GENERIC_ERROR,
caosdb_entity_entity *entity, const long *value, int caosdb_entity_entity_set_int_list_value(caosdb_entity_entity *entity,
const int length), const long *value,
{ const int length),
auto *wrapped_entity = {
static_cast<caosdb::entity::Entity *>( auto *wrapped_entity =
entity->wrapped_entity); static_cast<caosdb::entity::Entity *>(entity->wrapped_entity);
std::vector<long> value_list; std::vector<long> value_list;
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
value_list.push_back(value[i]); value_list.push_back(value[i]);
} }
caosdb::entity::Value to_be_set(value_list); wrapped_entity->SetValue(value_list);
wrapped_entity->SetValue(to_be_set); return 0;
return 0; })
})
ERROR_RETURN_CODE(GENERIC_ERROR, ERROR_RETURN_CODE(
int caosdb_entity_entity_set_double_list_value( GENERIC_ERROR,
caosdb_entity_entity *entity, const double *value, int caosdb_entity_entity_set_double_list_value(caosdb_entity_entity *entity,
const int length), const double *value,
{ const int length),
auto *wrapped_entity = {
static_cast<caosdb::entity::Entity *>( auto *wrapped_entity =
entity->wrapped_entity); static_cast<caosdb::entity::Entity *>(entity->wrapped_entity);
std::vector<double> value_list; std::vector<double> value_list;
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
value_list.push_back(value[i]); value_list.push_back(value[i]);
} }
caosdb::entity::Value to_be_set(value_list); wrapped_entity->SetValue(value_list);
wrapped_entity->SetValue(to_be_set); return 0;
return 0; })
})
ERROR_RETURN_CODE(GENERIC_ERROR, ERROR_RETURN_CODE(
int caosdb_entity_entity_set_boolean_list_value( GENERIC_ERROR,
caosdb_entity_entity *entity, const bool *value, int caosdb_entity_entity_set_boolean_list_value(caosdb_entity_entity *entity,
const int length), const bool *value,
{ const int length),
auto *wrapped_entity = {
static_cast<caosdb::entity::Entity *>( auto *wrapped_entity =
entity->wrapped_entity); static_cast<caosdb::entity::Entity *>(entity->wrapped_entity);
std::vector<bool> value_list; std::vector<bool> value_list;
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
value_list.push_back(value[i]); value_list.push_back(value[i]);
} }
caosdb::entity::Value to_be_set(value_list); wrapped_entity->SetValue(value_list);
wrapped_entity->SetValue(to_be_set); return 0;
return 0; })
})
ERROR_RETURN_CODE(GENERIC_ERROR, ERROR_RETURN_CODE(
int caosdb_entity_entity_set_string_list_value( GENERIC_ERROR,
caosdb_entity_entity *entity, const char **value, int caosdb_entity_entity_set_string_list_value(caosdb_entity_entity *entity,
const int length), const char **value,
{ const int length),
auto *wrapped_entity = {
static_cast<caosdb::entity::Entity *>( auto *wrapped_entity =
entity->wrapped_entity); static_cast<caosdb::entity::Entity *>(entity->wrapped_entity);
std::vector<std::string> value_list; std::vector<std::string> value_list;
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
value_list.push_back(std::string(value[i])); value_list.push_back(std::string(value[i]));
} }
caosdb::entity::Value to_be_set(value_list); wrapped_entity->SetValue(value_list);
wrapped_entity->SetValue(to_be_set); return 0;
return 0; })
})
ERROR_RETURN_CODE( ERROR_RETURN_CODE(
GENERIC_ERROR, GENERIC_ERROR,
...@@ -1012,8 +1133,7 @@ ERROR_RETURN_CODE(GENERIC_ERROR, ...@@ -1012,8 +1133,7 @@ ERROR_RETURN_CODE(GENERIC_ERROR,
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
value_list.push_back(value[i]); value_list.push_back(value[i]);
} }
caosdb::entity::Value to_be_set(value_list); wrapped_property->SetValue(value_list);
wrapped_property->SetValue(to_be_set);
return 0; return 0;
}) })
...@@ -1029,8 +1149,7 @@ ERROR_RETURN_CODE(GENERIC_ERROR, ...@@ -1029,8 +1149,7 @@ ERROR_RETURN_CODE(GENERIC_ERROR,
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
value_list.push_back(value[i]); value_list.push_back(value[i]);
} }
caosdb::entity::Value to_be_set(value_list); wrapped_property->SetValue(value_list);
wrapped_property->SetValue(to_be_set);
return 0; return 0;
}) })
...@@ -1046,8 +1165,7 @@ ERROR_RETURN_CODE(GENERIC_ERROR, ...@@ -1046,8 +1165,7 @@ ERROR_RETURN_CODE(GENERIC_ERROR,
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
value_list.push_back(value[i]); value_list.push_back(value[i]);
} }
caosdb::entity::Value to_be_set(value_list); wrapped_property->SetValue(value_list);
wrapped_property->SetValue(to_be_set);
return 0; return 0;
}) })
...@@ -1063,8 +1181,7 @@ ERROR_RETURN_CODE(GENERIC_ERROR, ...@@ -1063,8 +1181,7 @@ ERROR_RETURN_CODE(GENERIC_ERROR,
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
value_list.push_back(std::string(value[i])); value_list.push_back(std::string(value[i]));
} }
caosdb::entity::Value to_be_set(value_list); wrapped_property->SetValue(value_list);
wrapped_property->SetValue(to_be_set);
return 0; return 0;
}) })
} }
...@@ -165,8 +165,8 @@ TEST_F(test_ccaosdb, test_entity) { ...@@ -165,8 +165,8 @@ TEST_F(test_ccaosdb, test_entity) {
// the strings for the rest // the strings for the rest
return_code = caosdb_entity_entity_set_name(&entity, "length"); return_code = caosdb_entity_entity_set_name(&entity, "length");
EXPECT_EQ(return_code, 0); EXPECT_EQ(return_code, 0);
char out[255] = {"a"}; // NOLINT char *out = nullptr; // NOLINT
return_code = caosdb_entity_entity_get_name(&entity, out); return_code = caosdb_entity_entity_get_name(&entity, &out);
EXPECT_EQ(return_code, 0); EXPECT_EQ(return_code, 0);
EXPECT_EQ(strcmp(out, "length"), 0); EXPECT_EQ(strcmp(out, "length"), 0);
...@@ -176,7 +176,7 @@ TEST_F(test_ccaosdb, test_entity) { ...@@ -176,7 +176,7 @@ TEST_F(test_ccaosdb, test_entity) {
// EXPECT_EQ(strcmp(out, "Property"), 0); // EXPECT_EQ(strcmp(out, "Property"), 0);
caosdb_entity_entity_set_description(&entity, "The length of an object"); caosdb_entity_entity_set_description(&entity, "The length of an object");
caosdb_entity_entity_get_description(&entity, out); caosdb_entity_entity_get_description(&entity, &out);
EXPECT_EQ(strcmp(out, "The length of an object"), 0); EXPECT_EQ(strcmp(out, "The length of an object"), 0);
// TODO(fspreck) // TODO(fspreck)
...@@ -185,13 +185,18 @@ TEST_F(test_ccaosdb, test_entity) { ...@@ -185,13 +185,18 @@ TEST_F(test_ccaosdb, test_entity) {
// EXPECT_EQ(strcmp(out, "DOUBLE"), 0); // EXPECT_EQ(strcmp(out, "DOUBLE"), 0);
caosdb_entity_entity_set_unit(&entity, "m"); caosdb_entity_entity_set_unit(&entity, "m");
caosdb_entity_entity_get_unit(&entity, out); caosdb_entity_entity_get_unit(&entity, &out);
EXPECT_EQ(strcmp(out, "m"), 0); EXPECT_EQ(strcmp(out, "m"), 0);
// TODO(fspreck) return_code = caosdb_entity_entity_set_double_value(&entity, 5.0);
caosdb_entity_entity_set_double_value(&entity, 5.0); EXPECT_EQ(return_code, 0);
// caosdb_entity_entity_get_value(&entity, out); double value[] = {0.0}; // NOLINT
// EXPECT_EQ(strcmp(out, "5.0"), 0); std::cout << *value << std::endl;
return_code = caosdb_entity_entity_get_double_value(&entity, value);
std::cout << *value << std::endl;
EXPECT_EQ(return_code, 0);
// TODO(fspreck) Re-enable once role and datatype are set
// EXPECT_EQ(*value, 5.0);
return_code = caosdb_entity_delete_entity(&entity); return_code = caosdb_entity_delete_entity(&entity);
EXPECT_EQ(return_code, 0); EXPECT_EQ(return_code, 0);
...@@ -206,11 +211,11 @@ TEST_F(test_ccaosdb, test_parent) { ...@@ -206,11 +211,11 @@ TEST_F(test_ccaosdb, test_parent) {
caosdb_entity_parent_set_id(&parent, "some_id"); caosdb_entity_parent_set_id(&parent, "some_id");
caosdb_entity_parent_set_name(&parent, "some_name"); caosdb_entity_parent_set_name(&parent, "some_name");
char out[255] = {"a"}; // NOLINT char *out = nullptr; // NOLINT
caosdb_entity_parent_get_id(&parent, out); caosdb_entity_parent_get_id(&parent, &out);
EXPECT_EQ(strcmp(out, "some_id"), 0); EXPECT_EQ(strcmp(out, "some_id"), 0);
caosdb_entity_parent_get_name(&parent, out); caosdb_entity_parent_get_name(&parent, &out);
EXPECT_EQ(strcmp(out, "some_name"), 0); EXPECT_EQ(strcmp(out, "some_name"), 0);
return_code = caosdb_entity_delete_parent(&parent); return_code = caosdb_entity_delete_parent(&parent);
...@@ -232,11 +237,11 @@ TEST_F(test_ccaosdb, test_property) { ...@@ -232,11 +237,11 @@ TEST_F(test_ccaosdb, test_property) {
caosdb_entity_property_set_unit(&property, "some_unit"); caosdb_entity_property_set_unit(&property, "some_unit");
caosdb_entity_property_set_string_value(&property, "some_value"); caosdb_entity_property_set_string_value(&property, "some_value");
char out[255] = {"a"}; // NOLINT char *out = nullptr; // NOLINT
caosdb_entity_property_get_id(&property, out); caosdb_entity_property_get_id(&property, &out);
EXPECT_EQ(strcmp(out, "some_id"), 0); EXPECT_EQ(strcmp(out, "some_id"), 0);
caosdb_entity_property_get_name(&property, out); caosdb_entity_property_get_name(&property, &out);
EXPECT_EQ(strcmp(out, "some_name"), 0); EXPECT_EQ(strcmp(out, "some_name"), 0);
// TODO(fspreck) // TODO(fspreck)
...@@ -247,7 +252,7 @@ TEST_F(test_ccaosdb, test_property) { ...@@ -247,7 +252,7 @@ TEST_F(test_ccaosdb, test_property) {
// caosdb_entity_property_get_importance(&property, out); // caosdb_entity_property_get_importance(&property, out);
// EXPECT_EQ(strcmp(out, "FIX"), 0); // EXPECT_EQ(strcmp(out, "FIX"), 0);
caosdb_entity_property_get_unit(&property, out); caosdb_entity_property_get_unit(&property, &out);
EXPECT_EQ(strcmp(out, "some_unit"), 0); EXPECT_EQ(strcmp(out, "some_unit"), 0);
// TODO(fspreck) // TODO(fspreck)
...@@ -270,8 +275,9 @@ TEST_F(test_ccaosdb, test_list_property) { ...@@ -270,8 +275,9 @@ TEST_F(test_ccaosdb, test_list_property) {
// return_code = caosdb_entity_property_set_datatype(&property, "LIST<TEXT>"); // return_code = caosdb_entity_property_set_datatype(&property, "LIST<TEXT>");
// EXPECT_EQ(return_code, 0); // EXPECT_EQ(return_code, 0);
const *char[] value_list = {"val0", "val1", "val2"}; // NOLINT const char *value_list[] = {"val0", "val1", "val2"}; // NOLINT
return_code = caosdb_entity_property_set_string_list_value(&property, value_list, 3); return_code =
caosdb_entity_property_set_string_list_value(&property, value_list, 3);
EXPECT_EQ(return_code, 0); EXPECT_EQ(return_code, 0);
// TODO(fspreck) // TODO(fspreck)
...@@ -280,7 +286,19 @@ TEST_F(test_ccaosdb, test_list_property) { ...@@ -280,7 +286,19 @@ TEST_F(test_ccaosdb, test_list_property) {
// EXPECT_EQ(return_code, 0); // EXPECT_EQ(return_code, 0);
// EXPECT_EQ(strcmp(out_type, "LIST<TEXT>")); // EXPECT_EQ(strcmp(out_type, "LIST<TEXT>"));
int length[] = {0}; // NOLINT
return_code = caosdb_entity_property_get_value_list_length(&property, length);
EXPECT_EQ(return_code, 0);
EXPECT_EQ(*length, 3);
// TODO(fspreck) get and compare values in list // TODO(fspreck) get and compare values in list
char *out_list[*length]; // NOLINT
return_code =
caosdb_entity_property_get_string_list_value(&property, out_list); // NOLINT
EXPECT_EQ(return_code, 0);
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);
...@@ -309,14 +327,12 @@ TEST_F(test_ccaosdb, test_entity_with_parent_and_property) { ...@@ -309,14 +327,12 @@ TEST_F(test_ccaosdb, test_entity_with_parent_and_property) {
return_code = caosdb_entity_create_entity(&entity); return_code = caosdb_entity_create_entity(&entity);
EXPECT_EQ(return_code, 0); EXPECT_EQ(return_code, 0);
std::cout << "Appending parent and property ..." << std::endl;
return_code = caosdb_entity_entity_append_parent(&entity, &input_parent); return_code = caosdb_entity_entity_append_parent(&entity, &input_parent);
EXPECT_EQ(return_code, 0); EXPECT_EQ(return_code, 0);
return_code = caosdb_entity_entity_append_property(&entity, &input_property); return_code = caosdb_entity_entity_append_property(&entity, &input_property);
EXPECT_EQ(return_code, 0); EXPECT_EQ(return_code, 0);
std::cout << "Counting parents and properties ..." << std::endl;
int count[] = {0}; // NOLINT int count[] = {0}; // NOLINT
return_code = caosdb_entity_entity_get_parents_size(&entity, count); return_code = caosdb_entity_entity_get_parents_size(&entity, count);
EXPECT_EQ(return_code, 0); EXPECT_EQ(return_code, 0);
...@@ -326,26 +342,22 @@ TEST_F(test_ccaosdb, test_entity_with_parent_and_property) { ...@@ -326,26 +342,22 @@ TEST_F(test_ccaosdb, test_entity_with_parent_and_property) {
EXPECT_EQ(return_code, 0); EXPECT_EQ(return_code, 0);
EXPECT_EQ(*count, 1); EXPECT_EQ(*count, 1);
char in[255] = {"a"}; // NOLINT char *in = nullptr; // NOLINT
char out[255] = {"b"}; // NOLINT char *out = nullptr; // NOLINT
std::cout << "Comparing ..." << std::endl;
// cannot assign an already assigned property // cannot assign an already assigned property
return_code = caosdb_entity_entity_get_property(&entity, &input_property, 0); return_code = caosdb_entity_entity_get_property(&entity, &input_property, 0);
EXPECT_EQ(return_code, caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR); EXPECT_EQ(return_code, caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR);
caosdb_entity_property output_property; caosdb_entity_property output_property;
return_code = caosdb_entity_entity_get_property(&entity, &output_property, 0); return_code = caosdb_entity_entity_get_property(&entity, &output_property, 0);
std::cout << "Got output property." << std::endl;
EXPECT_EQ(return_code, 0); EXPECT_EQ(return_code, 0);
caosdb_entity_property_get_id(&input_property, in); caosdb_entity_property_get_id(&input_property, &in);
std::cout << "Got input id." << std::endl; caosdb_entity_property_get_id(&output_property, &out);
caosdb_entity_property_get_id(&output_property, out);
std::cout << "Got output id." << std::endl;
EXPECT_EQ(strcmp(in, out), 0); EXPECT_EQ(strcmp(in, out), 0);
caosdb_entity_property_get_name(&input_property, in); caosdb_entity_property_get_name(&input_property, &in);
caosdb_entity_property_get_name(&output_property, out); caosdb_entity_property_get_name(&output_property, &out);
EXPECT_EQ(strcmp(in, out), 0); EXPECT_EQ(strcmp(in, out), 0);
// TODO(fspreck) // TODO(fspreck)
...@@ -353,27 +365,23 @@ TEST_F(test_ccaosdb, test_entity_with_parent_and_property) { ...@@ -353,27 +365,23 @@ TEST_F(test_ccaosdb, test_entity_with_parent_and_property) {
// caosdb_entity_property_get_datatype(&output_property, out); // caosdb_entity_property_get_datatype(&output_property, out);
// EXPECT_EQ(strcmp(in, out), 0); // EXPECT_EQ(strcmp(in, out), 0);
// TODO(fspreck) caosdb_entity_property_get_string_value(&input_property, &in);
// caosdb_entity_property_get_value(&input_property, in); caosdb_entity_property_get_string_value(&output_property, &out);
// caosdb_entity_property_get_value(&output_property, out); EXPECT_EQ(strcmp(in, out), 0);
// EXPECT_EQ(strcmp(in, out), 0);
std::cout << "Comparing parent..." << std::endl;
caosdb_entity_parent output_parent; caosdb_entity_parent output_parent;
return_code = caosdb_entity_entity_get_parent(&entity, &output_parent, 0); return_code = caosdb_entity_entity_get_parent(&entity, &output_parent, 0);
std::cout << "Got output parent." << std::endl;
EXPECT_EQ(return_code, 0); EXPECT_EQ(return_code, 0);
caosdb_entity_parent_get_id(&input_parent, in); caosdb_entity_parent_get_id(&input_parent, &in);
caosdb_entity_parent_get_id(&output_parent, out); caosdb_entity_parent_get_id(&output_parent, &out);
EXPECT_EQ(strcmp(in, out), 0); EXPECT_EQ(strcmp(in, out), 0);
caosdb_entity_parent_get_name(&input_parent, in); caosdb_entity_parent_get_name(&input_parent, &in);
caosdb_entity_parent_get_name(&output_parent, out); caosdb_entity_parent_get_name(&output_parent, &out);
EXPECT_EQ(strcmp(in, out), 0); EXPECT_EQ(strcmp(in, out), 0);
// Delete everything // Delete everything
std::cout << "Deleting ..." << std::endl;
return_code = caosdb_entity_delete_parent(&input_parent); return_code = caosdb_entity_delete_parent(&input_parent);
EXPECT_EQ(return_code, 0); EXPECT_EQ(return_code, 0);
return_code = caosdb_entity_delete_property(&input_property); return_code = caosdb_entity_delete_property(&input_property);
...@@ -433,13 +441,13 @@ TEST_F(test_ccaosdb, test_remove_property) { ...@@ -433,13 +441,13 @@ TEST_F(test_ccaosdb, test_remove_property) {
return_code = caosdb_entity_entity_get_property(&entity, &out_prop, 0); return_code = caosdb_entity_entity_get_property(&entity, &out_prop, 0);
EXPECT_EQ(return_code, 0); EXPECT_EQ(return_code, 0);
char in[255] = {"a"}; // NOLINT char *in = nullptr; // NOLINT
char out[255] = {"b"}; // NOLINT char *out = nullptr; // NOLINT
// Deleted the first property, so the second one should remain. // Deleted the first property, so the second one should remain.
return_code = caosdb_entity_property_get_name(&in_prop_2, in); return_code = caosdb_entity_property_get_name(&in_prop_2, &in);
EXPECT_EQ(return_code, 0); EXPECT_EQ(return_code, 0);
return_code = caosdb_entity_property_get_name(&out_prop, out); return_code = caosdb_entity_property_get_name(&out_prop, &out);
EXPECT_EQ(return_code, 0); EXPECT_EQ(return_code, 0);
EXPECT_EQ(strcmp(in, out), 0); EXPECT_EQ(strcmp(in, out), 0);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment