diff --git a/include/caosdb/entity.h b/include/caosdb/entity.h index 6b96c907f1e24eae4894bc652173ffc8e52ee387..de6d4928771af83edca68d748d73b58f690a35f7 100644 --- a/include/caosdb/entity.h +++ b/include/caosdb/entity.h @@ -515,7 +515,7 @@ public: * Set the value of this property. */ auto SetValue(const Value &value) -> StatusCode; - // auto SetValue(const AbstractValue &value) -> StatusCode; + auto SetValue(const AbstractValue &value) -> StatusCode; auto SetValue(const std::string &value) -> StatusCode; auto SetValue(const char *value) -> StatusCode; auto SetValue(const double value) -> StatusCode; @@ -688,7 +688,7 @@ public: */ auto SetDescription(const std::string &description) -> void; - // auto SetValue(const AbstractValue &value) -> StatusCode; + auto SetValue(const AbstractValue &value) -> StatusCode; auto SetValue(const Value &value) -> StatusCode; auto SetValue(const std::string &value) -> StatusCode; auto SetValue(const char *value) -> StatusCode; diff --git a/include/ccaosdb.h b/include/ccaosdb.h index 4c0f81b0178a4f9b08943617dd03d77118b28945..2c37417a6706717c98173d3cc145d5b8d3337210 100644 --- a/include/ccaosdb.h +++ b/include/ccaosdb.h @@ -474,11 +474,9 @@ int caosdb_entity_entity_set_name(caosdb_entity_entity *entity, const char *name int caosdb_entity_entity_set_description(caosdb_entity_entity *entity, const char *description); int caosdb_entity_entity_set_local_path(caosdb_entity_entity *entity, const char *name); int caosdb_entity_entity_set_file_path(caosdb_entity_entity *entity, const char *name); -// TODO(fspreck) implementation int caosdb_entity_entity_set_datatype(caosdb_entity_entity *entity, caosdb_entity_datatype *datatype); int caosdb_entity_entity_set_unit(caosdb_entity_entity *entity, const char *unit); -// TODO(fspreck) implementation int caosdb_entity_entity_set_value(caosdb_entity_entity *entity, caosdb_entity_value *value); int caosdb_entity_entity_append_parent(caosdb_entity_entity *entity, caosdb_entity_parent *parent); @@ -489,20 +487,15 @@ int caosdb_entity_entity_remove_property(caosdb_entity_entity *entity, int index int caosdb_entity_property_set_id(caosdb_entity_property *property, const char *id); int caosdb_entity_property_set_name(caosdb_entity_property *property, const char *name); -// TODO(fspreck) implementation int caosdb_entity_property_set_datatype(caosdb_entity_property *property, caosdb_entity_datatype *datatype); int caosdb_entity_property_set_importance(caosdb_entity_property *property, const char *importance); int caosdb_entity_property_set_unit(caosdb_entity_property *property, const char *unit); - -// TODO(fspreck) implementation int caosdb_entity_property_set_value(caosdb_entity_property *property, caosdb_entity_value *value); int caosdb_entity_parent_set_id(caosdb_entity_parent *parent, const char *id); int caosdb_entity_parent_set_name(caosdb_entity_parent *parent, const char *name); -// TODO(fspreck) setters for datatype - #ifdef __cplusplus } #endif diff --git a/src/caosdb/entity.cpp b/src/caosdb/entity.cpp index 977fb69e63a9741705506b08a9366a41dafcf7ad..7f241520ac9e29b7c628eb363698a4d365945ea9 100644 --- a/src/caosdb/entity.cpp +++ b/src/caosdb/entity.cpp @@ -109,8 +109,7 @@ auto Property::SetImportance(Importance importance) -> void { auto Property::SetValue(const Value &value) -> StatusCode { return this->value.CopyFrom(value); } -// auto Property::SetValue(const AbstractValue &value) -> StatusCode { return -// SetValue(Value(value)); } +auto Property::SetValue(const AbstractValue &value) -> StatusCode { return SetValue(Value(value)); } auto Property::SetValue(const std::string &value) -> StatusCode { return SetValue(Value(value)); } @@ -206,8 +205,7 @@ auto Entity::SetValue(const Value &value) -> StatusCode { return this->value.CopyFrom(value); } -// auto Entity::SetValue(const AbstractValue &value) -> StatusCode { return SetValue(Value(value)); -// } +auto Entity::SetValue(const AbstractValue &value) -> StatusCode { return SetValue(Value(value)); } auto Entity::SetValue(const std::string &value) -> StatusCode { return SetValue(Value(value)); } diff --git a/src/ccaosdb.cpp b/src/ccaosdb.cpp index c89e0a3922d868bf0c793adaeb2e646f4bc97dc1..476505e4bd94d7f872e8bd99ed1204833354168e 100644 --- a/src/ccaosdb.cpp +++ b/src/ccaosdb.cpp @@ -1085,7 +1085,7 @@ ERROR_RETURN_CODE( } char *tmp = (char *)malloc(sizeof(char) * datatype_name.length() + 1); strcpy(tmp, datatype_name.c_str()); - delete[] *out; + delete[] * out; *out = tmp; return 0; }) @@ -1143,31 +1143,25 @@ CAOSDB_ENTITY_SET(local_path, local_path, CAOSDB_ENTITY_SET(file_path, file_path, wrapped_entity->SetFilePath(std::string(file_path));) CAOSDB_ENTITY_SET(description, description, wrapped_entity->SetDescription(std::string(description));) -// TODO(fspreck) -// 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));) +ERROR_RETURN_CODE(GENERIC_ERROR, + int caosdb_entity_entity_set_datatype(caosdb_entity_entity *entity, + caosdb_entity_datatype *datatype), + { + auto *wrapped_entity = WRAPPED_ENTITY_CAST(entity); + auto *wrapped_datatype = WRAPPED_DATATYPE_CAST(datatype); + + return wrapped_entity->SetDataType(*wrapped_datatype); + }) +ERROR_RETURN_CODE(GENERIC_ERROR, + int caosdb_entity_entity_set_value(caosdb_entity_entity *entity, + caosdb_entity_value *value), + { + auto *wrapped_entity = WRAPPED_ENTITY_CAST(entity); + auto *wrapped_value = WRAPPED_VALUE_CAST(value); + + return wrapped_entity->SetValue(*wrapped_value); + }) ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_entity_append_parent(caosdb_entity_entity *entity, @@ -1214,31 +1208,24 @@ 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));) +ERROR_RETURN_CODE(GENERIC_ERROR, + int caosdb_entity_property_set_datatype(caosdb_entity_property *property, + caosdb_entity_datatype *datatype), + { + auto *wrapped_property = WRAPPED_PROPERTY_CAST(property); + auto *wrapped_datatype = WRAPPED_DATATYPE_CAST(datatype); -// TODO(fspreck) -// 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; -// } -// } -// }) + return wrapped_property->SetDataType(*wrapped_datatype); + }) +ERROR_RETURN_CODE(GENERIC_ERROR, + int caosdb_entity_property_set_value(caosdb_entity_property *property, + caosdb_entity_value *value), + { + auto *wrapped_property = WRAPPED_PROPERTY_CAST(property); + auto *wrapped_value = WRAPPED_VALUE_CAST(value); + + return wrapped_property->SetValue(*wrapped_value); + }) ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_property_set_importance(caosdb_entity_property *property,