Skip to content
Snippets Groups Projects

ENH: Add datatypes and value classes to Extern C interface

Merged Florian Spreckelsen requested to merge f-consolidate-c into dev
Files
2
+ 582
69
@@ -22,6 +22,7 @@
#include "ccaosdb.h"
#include "caosdb/connection.h"
#include "caosdb/constants.h"
#include "caosdb/data_type.h" // for DataType, AtomicDat...
#include "caosdb/utility.h"
#include "caosdb/status_code.h"
#include "caosdb/logging.h"
@@ -37,6 +38,20 @@ extern "C" {
#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)
#define ENUM_NAME_FROM_VALUE(arg, etype) \
caosdb::utility::getEnumNameFromValue<caosdb::entity::etype>(arg)
#define ENUM_VALUE_FROM_NAME(arg, etype) \
caosdb::utility::getEnumValueFromName<caosdb::entity::etype>(arg)
/*
* Macro for wrapping every function into a try-catch clause. If an exception
* occurs, the given StatusCode is being returned.
@@ -55,12 +70,16 @@ extern "C" {
/**
* Macro for entity getters
*/
#define CAOSDB_ENTITY_GET(element, body_part) \
#define CAOSDB_ENTITY_GET(element, GetFunction) \
ERROR_RETURN_CODE( \
GENERIC_ERROR, \
int caosdb_entity_entity_get_##element(caosdb_entity_entity *entity, char *out), { \
auto *wrapped_entity = static_cast<caosdb::entity::Entity *>(entity->wrapped_entity); \
body_part return 0; \
int caosdb_entity_entity_get_##element(caosdb_entity_entity *entity, char **out), { \
auto *wrapped_entity = WRAPPED_ENTITY_CAST(entity); \
char *tmp = (char *)malloc(sizeof(char) * wrapped_entity->GetFunction.length() + 1); \
strcpy(tmp, wrapped_entity->GetFunction.c_str()); \
delete[] * out; \
*out = tmp; \
return 0; \
})
/**
@@ -70,20 +89,23 @@ extern "C" {
ERROR_RETURN_CODE( \
GENERIC_ERROR, \
int caosdb_entity_entity_set_##element(caosdb_entity_entity *entity, const char *value), { \
auto *wrapped_entity = static_cast<caosdb::entity::Entity *>(entity->wrapped_entity); \
auto *wrapped_entity = WRAPPED_ENTITY_CAST(entity); \
body_part return 0; \
})
/**
* Macro for property getters
*/
#define CAOSDB_PROPERTY_GET(element, body_part) \
#define CAOSDB_PROPERTY_GET(element, GetFunction) \
ERROR_RETURN_CODE( \
GENERIC_ERROR, \
int caosdb_entity_property_get_##element(caosdb_entity_property *property, char *out), { \
auto *wrapped_property = \
static_cast<caosdb::entity::Property *>(property->wrapped_property); \
body_part return 0; \
int caosdb_entity_property_get_##element(caosdb_entity_property *property, char **out), { \
auto *wrapped_property = WRAPPED_PROPERTY_CAST(property); \
char *tmp = (char *)malloc(sizeof(char) * wrapped_property->GetFunction.length() + 1); \
strcpy(tmp, wrapped_property->GetFunction.c_str()); \
delete[] * out; \
*out = tmp; \
return 0; \
})
/**
@@ -94,20 +116,23 @@ extern "C" {
GENERIC_ERROR, \
int caosdb_entity_property_set_##element(caosdb_entity_property *property, const char *value), \
{ \
auto *wrapped_property = \
static_cast<caosdb::entity::Property *>(property->wrapped_property); \
auto *wrapped_property = WRAPPED_PROPERTY_CAST(property); \
body_part return 0; \
})
/**
* Macro for parent getters
*/
#define CAOSDB_PARENT_GET(element, body_part) \
#define CAOSDB_PARENT_GET(element, GetFunction) \
ERROR_RETURN_CODE( \
GENERIC_ERROR, \
int caosdb_entity_parent_get_##element(caosdb_entity_parent *parent, char *out), { \
auto *wrapped_parent = static_cast<caosdb::entity::Parent *>(parent->wrapped_parent); \
body_part return 0; \
int caosdb_entity_parent_get_##element(caosdb_entity_parent *parent, char **out), { \
auto *wrapped_parent = WRAPPED_PARENT_CAST(parent); \
char *tmp = (char *)malloc(sizeof(char) * wrapped_parent->GetFunction.length() + 1); \
strcpy(tmp, wrapped_parent->GetFunction.c_str()); \
delete[] * out; \
*out = tmp; \
return 0; \
})
/**
@@ -117,7 +142,7 @@ extern "C" {
ERROR_RETURN_CODE( \
GENERIC_ERROR, \
int caosdb_entity_parent_set_##element(caosdb_entity_parent *parent, const char *value), { \
auto *wrapped_parent = static_cast<caosdb::entity::Parent *>(parent->wrapped_parent); \
auto *wrapped_parent = WRAPPED_PARENT_CAST(parent); \
body_part return 0; \
})
@@ -514,18 +539,130 @@ ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_delete_parent(caosdb_entity_p
return 0;
})
CAOSDB_ENTITY_GET(id, strcpy(out, wrapped_entity->GetId().c_str());)
// TODO(fspreck)
// 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(description, strcpy(out, wrapped_entity->GetDescription().c_str());)
// TODO(fspreck)
// CAOSDB_ENTITY_GET(datatype, strcpy(out,
// wrapped_entity->GetDatatype().c_str());)
// TODO(fspreck)
// CAOSDB_ENTITY_GET(value, strcpy(out, wrapped_entity->GetValue().c_str());)
CAOSDB_ENTITY_GET(unit, strcpy(out, wrapped_entity->GetUnit().c_str());)
CAOSDB_ENTITY_GET(version_id, strcpy(out, wrapped_entity->GetVersionId().c_str());)
CAOSDB_ENTITY_GET(id, GetId())
ERROR_RETURN_CODE(GENERIC_ERROR,
int caosdb_entity_entity_get_role(caosdb_entity_entity *entity, char **out), {
auto *wrapped_entity = WRAPPED_ENTITY_CAST(entity);
std::string role_str = ENUM_NAME_FROM_VALUE(wrapped_entity->GetRole(), Role);
char *tmp = (char *)malloc(sizeof(char) * role_str.length() + 1);
strcpy(tmp, role_str.c_str());
delete[] * out;
*out = tmp;
return 0;
})
CAOSDB_ENTITY_GET(name, GetName())
CAOSDB_ENTITY_GET(description, GetDescription())
ERROR_RETURN_CODE(GENERIC_ERROR,
int caosdb_entity_entity_get_datatype(caosdb_entity_entity *entity, char **name,
bool *is_ref, bool *is_list),
{
auto *wrapped_entity = WRAPPED_ENTITY_CAST(entity);
const auto &datatype = wrapped_entity->GetDataType();
*is_list = datatype.IsList();
std::string datatype_name;
if (*is_list) {
const auto &list_datatype = datatype.AsList();
*is_ref = list_datatype.IsListOfReference();
if (*is_ref) {
datatype_name = list_datatype.GetReferenceDataType().GetName();
} else {
datatype_name =
ENUM_NAME_FROM_VALUE(list_datatype.GetAtomicDataType(), AtomicDataType);
}
} else {
*is_ref = datatype.IsReference();
if (*is_ref) {
datatype_name = datatype.AsReference().GetName();
} else {
datatype_name = ENUM_NAME_FROM_VALUE(datatype.AsAtomic(), AtomicDataType);
}
}
char *tmp = (char *)malloc(sizeof(char) * datatype_name.length() + 1);
strcpy(tmp, datatype_name.c_str());
delete[] * name;
*name = tmp;
return 0;
})
ERROR_RETURN_CODE(GENERIC_ERROR,
int caosdb_entity_entity_get_int_value(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_at(caosdb_entity_entity *entity,
long *out, const int index),
{
auto *wrapped_entity = WRAPPED_ENTITY_CAST(entity);
auto value_list = wrapped_entity->GetValue().AsList();
*out = value_list[index].AsInteger();
return 0;
})
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;
})
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(GENERIC_ERROR,
int caosdb_entity_entity_get_errors_size(caosdb_entity_entity *entity, int *out),
@@ -643,54 +780,300 @@ ERROR_RETURN_CODE(GENERIC_ERROR,
return 0;
})
CAOSDB_PARENT_GET(id, strcpy(out, wrapped_parent->GetId().c_str());)
CAOSDB_PARENT_GET(name, strcpy(out, wrapped_parent->GetName().c_str());)
CAOSDB_PARENT_GET(description, strcpy(out, wrapped_parent->GetDescription().c_str());)
CAOSDB_PARENT_GET(id, GetId())
CAOSDB_PARENT_GET(name, GetName())
CAOSDB_PARENT_GET(description, GetDescription())
CAOSDB_PROPERTY_GET(id, strcpy(out, wrapped_property->GetId().c_str());)
CAOSDB_PROPERTY_GET(name, strcpy(out, wrapped_property->GetName().c_str());)
CAOSDB_PROPERTY_GET(description, strcpy(out, wrapped_property->GetDescription().c_str());)
// TODO(fspreck)
// CAOSDB_PROPERTY_GET(importance,
// strcpy(out, wrapped_property->GetImportance().c_str());)
// TODO(fspreck)
// CAOSDB_PROPERTY_GET(datatype,
// strcpy(out, wrapped_property->GetDatatype().c_str());)
CAOSDB_PROPERTY_GET(unit, strcpy(out, wrapped_property->GetUnit().c_str());)
// TODO(fspreck)
// CAOSDB_PROPERTY_GET(value, strcpy(out,
// wrapped_property->GetValue().c_str());)
CAOSDB_PROPERTY_GET(id, GetId())
CAOSDB_PROPERTY_GET(name, GetName())
CAOSDB_PROPERTY_GET(description, GetDescription())
ERROR_RETURN_CODE(GENERIC_ERROR,
int caosdb_entity_message_get_code(caosdb_entity_message *message, int *out), {
auto *wrapped_message =
static_cast<caosdb::entity::Message *>(message->wrapped_message);
*out = wrapped_message->GetCode();
int caosdb_entity_property_get_importance(caosdb_entity_property *property,
char **out),
{
auto *wrapped_property = WRAPPED_PROPERTY_CAST(property);
std::string importance_str =
ENUM_NAME_FROM_VALUE(wrapped_property->GetImportance(), Importance);
char *tmp = (char *)malloc(sizeof(char) * importance_str.length() + 1);
strcpy(tmp, importance_str.c_str());
delete[] * out;
*out = tmp;
return 0;
})
ERROR_RETURN_CODE(GENERIC_ERROR,
int caosdb_entity_message_get_description(caosdb_entity_message *message,
char *out),
int caosdb_entity_property_get_datatype(caosdb_entity_property *property,
char **name, bool *is_ref, bool *is_list),
{
auto *wrapped_property = WRAPPED_PROPERTY_CAST(property);
const auto &datatype = wrapped_property->GetDataType();
*is_list = datatype.IsList();
std::string datatype_name;
if (*is_list) {
const auto &list_datatype = datatype.AsList();
*is_ref = list_datatype.IsListOfReference();
if (*is_ref) {
datatype_name = list_datatype.GetReferenceDataType().GetName();
} else {
datatype_name =
ENUM_NAME_FROM_VALUE(list_datatype.GetAtomicDataType(), AtomicDataType);
}
} else {
*is_ref = datatype.IsReference();
if (*is_ref) {
datatype_name = datatype.AsReference().GetName();
} else {
datatype_name = ENUM_NAME_FROM_VALUE(datatype.AsAtomic(), AtomicDataType);
}
}
char *tmp = (char *)malloc(sizeof(char) * datatype_name.length() + 1);
strcpy(tmp, datatype_name.c_str());
delete[] * name;
*name = tmp;
return 0;
})
CAOSDB_PROPERTY_GET(unit, GetUnit())
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_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;
})
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(GENERIC_ERROR,
int caosdb_entity_message_get_code(caosdb_entity_message *message, int *out), {
auto *wrapped_message =
static_cast<caosdb::entity::Message *>(message->wrapped_message);
strcpy(out, wrapped_message->GetDescription().c_str());
*out = wrapped_message->GetCode();
return 0;
})
// TODO(fspreck)
// CAOSDB_ENTITY_SET(role, role, wrapped_entity->SetRole(std::string(role));)
ERROR_RETURN_CODE(
GENERIC_ERROR,
int caosdb_entity_message_get_description(caosdb_entity_message *message, char **out), {
auto *wrapped_message = static_cast<caosdb::entity::Message *>(message->wrapped_message);
char *tmp = (char *)malloc(sizeof(char) * wrapped_message->GetDescription().length() + 1);
strcpy(tmp, wrapped_message->GetDescription().c_str());
delete[] * out;
*out = tmp;
return 0;
})
ERROR_RETURN_CODE(GENERIC_ERROR,
int caosdb_entity_entity_set_role(caosdb_entity_entity *entity, const char *role),
{
auto *wrapped_entity = WRAPPED_ENTITY_CAST(entity);
try {
auto enum_value = ENUM_VALUE_FROM_NAME(std::string(role), Role);
wrapped_entity->SetRole(enum_value);
return 0;
} catch (const std::out_of_range &exc) {
caosdb::logging::caosdb_log_fatal(CCAOSDB_LOGGER_NAME, exc.what());
return caosdb::StatusCode::ENUM_MAPPING_ERROR;
}
})
CAOSDB_ENTITY_SET(name, name, wrapped_entity->SetName(std::string(name));)
CAOSDB_ENTITY_SET(description, description,
wrapped_entity->SetDescription(std::string(description));)
// TODO(fspreck)
// CAOSDB_ENTITY_SET(datatype, datatype,
// wrapped_entity->SetDataType(std::string(datatype));)
ERROR_RETURN_CODE(GENERIC_ERROR,
int caosdb_entity_entity_set_datatype(caosdb_entity_entity *entity,
const char *datatype, const bool is_ref,
const bool is_list),
{
auto *wrapped_entity = WRAPPED_ENTITY_CAST(entity);
if (is_ref) {
// Refernce datatype with name of reference
wrapped_entity->SetDataType(std::string(datatype), is_list);
return 0;
} else {
// Atomic datatype so get from enum
try {
auto enum_value =
ENUM_VALUE_FROM_NAME(std::string(datatype), AtomicDataType);
wrapped_entity->SetDataType(enum_value, is_list);
return 0;
} catch (const std::out_of_range &exc) {
caosdb::logging::caosdb_log_fatal(CCAOSDB_LOGGER_NAME, exc.what());
return caosdb::StatusCode::ENUM_MAPPING_ERROR;
}
}
})
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]);
}
wrapped_entity->SetValue(value_list);
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]);
}
wrapped_entity->SetValue(value_list);
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]);
}
wrapped_entity->SetValue(value_list);
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]));
}
wrapped_entity->SetValue(value_list);
return 0;
})
ERROR_RETURN_CODE(GENERIC_ERROR,
int caosdb_entity_entity_append_parent(caosdb_entity_entity *entity,
@@ -737,14 +1120,144 @@ CAOSDB_PARENT_SET(name, name, wrapped_parent->SetName(std::string(name));)
CAOSDB_PROPERTY_SET(name, name, wrapped_property->SetName(std::string(name));)
CAOSDB_PROPERTY_SET(id, id, wrapped_property->SetId(std::string(id));)
// TODO(fspreck)
// CAOSDB_PROPERTY_SET(datatype, datatype,
// wrapped_property->SetDataType(std::string(datatype));)
// TODO(fspreck)
// CAOSDB_PROPERTY_SET(importance, importance,
// wrapped_property->SetImportance(std::string(importance));)
ERROR_RETURN_CODE(GENERIC_ERROR,
int caosdb_entity_property_set_datatype(caosdb_entity_property *property,
const char *datatype, const bool is_ref,
const bool is_list),
{
auto *wrapped_property = WRAPPED_PROPERTY_CAST(property);
if (is_ref) {
// Refernce datatype with name of reference
wrapped_property->SetDataType(std::string(datatype), is_list);
return 0;
} else {
// Atomic datatype so get from enum
try {
auto enum_value =
ENUM_VALUE_FROM_NAME(std::string(datatype), AtomicDataType);
wrapped_property->SetDataType(enum_value, is_list);
return 0;
} catch (const std::out_of_range &exc) {
caosdb::logging::caosdb_log_fatal(CCAOSDB_LOGGER_NAME, exc.what());
return caosdb::StatusCode::ENUM_MAPPING_ERROR;
}
}
})
ERROR_RETURN_CODE(GENERIC_ERROR,
int caosdb_entity_property_set_importance(caosdb_entity_property *property,
const char *importance),
{
auto *wrapped_property = WRAPPED_PROPERTY_CAST(property);
try {
auto enum_value = ENUM_VALUE_FROM_NAME(std::string(importance), Importance);
wrapped_property->SetImportance(enum_value);
return 0;
} catch (const std::out_of_range &exc) {
caosdb::logging::caosdb_log_fatal(CCAOSDB_LOGGER_NAME, exc.what());
return caosdb::StatusCode::ENUM_MAPPING_ERROR;
}
})
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]);
}
wrapped_property->SetValue(value_list);
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]);
}
wrapped_property->SetValue(value_list);
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]);
}
wrapped_property->SetValue(value_list);
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]));
}
wrapped_property->SetValue(value_list);
return 0;
})
}
Loading