diff --git a/include/ccaosdb.h b/include/ccaosdb.h index 61b86817532b77ccfd24ccb791b18cc31afc6faa..dc979d71253f15f55077ef554f87331e0fa4dd8e 100644 --- a/include/ccaosdb.h +++ b/include/ccaosdb.h @@ -441,7 +441,11 @@ int caosdb_entity_delete_property(caosdb_entity_property *out); int caosdb_entity_create_parent(caosdb_entity_parent *out); int caosdb_entity_delete_parent(caosdb_entity_parent *out); // TODO(fspreck) implementations, also list_datatypes, list_values... -int caosdb_entity_create_datatype(caosdb_entity_datatype *out); +// DATATYPE CONSTRUCTORS for atomic and reference datatypes and lists thereof +int caosdb_entity_create_atomic_datatype(caosdb_entity_datatype *out, const char *name); +int caosdb_entity_create_reference_datatype(caosdb_entity_datatype *out, const char *name); +int caosdb_entity_create_atomic_list_datatype(caosdb_entity_datatype *out, const char *name); +int caosdb_entity_create_reference_list_datatype(caosdb_entity_datatype *out, const char *name); int caosdb_entity_delete_datatype(caosdb_entity_datatype *out); // VALUE CONSTRUCTORS (resolve overloaded constructors) int caosdb_entity_create_int_value(caosdb_entity_value *out, const int64_t value); diff --git a/src/ccaosdb.cpp b/src/ccaosdb.cpp index 8a7ae4131f513d257e3c0c1b69f975fde595f9dc..cf1d75b5b9f8b2bd6a52cc4d7b747bd2381b746c 100644 --- a/src/ccaosdb.cpp +++ b/src/ccaosdb.cpp @@ -48,6 +48,8 @@ extern "C" { #define WRAPPED_MESSAGE_CAST(name) static_cast<caosdb::entity::Message *>(name->wrapped_message) +#define WRAPPED_DATATYPE_CAST(name) static_cast<caosdb::entity::Datatype *>(name->wrapped_datatype) + #define WRAPPED_VALUE_CAST(name) static_cast<caosdb::entity::AbstractValue *>(name->wrapped_value) #define ENUM_NAME_FROM_VALUE(arg, etype) \ @@ -56,6 +58,11 @@ extern "C" { #define ENUM_VALUE_FROM_NAME(arg, etype) \ caosdb::utility::getEnumValueFromName<caosdb::entity::etype>(arg) +#define RETURN_ASSIGNEMENT_ERROR_IF_DELETABLE(name) \ + if (name->_deletable) { \ + return caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR; \ + } + /* * Macro for wrapping every function into a try-catch clause. If an exception * occurs, the given StatusCode is being returned. @@ -683,6 +690,31 @@ ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_delete_parent(caosdb_entity_p return 0; }) +ERROR_RETURN_CODE(GENERIC_ERROR, + int caosdb_entity_create_atomic_datatype(caosdb_entity_datatype *out, + const char *name), + {}) +ERROR_RETURN_CODE(GENERIC_ERROR, + int caosdb_entity_create_reference_datatype(caosdb_entity_datatype *out, + const char *name), + {}) +ERROR_RETURN_CODE(GENERIC_ERROR, + int caosdb_entity_create_atomic_list_datatype(caosdb_entity_datatype *out, + const char *name), + {}) +ERROR_RETURN_CODE(GENERIC_ERROR, + int caosdb_entity_create_reference_list_datatype(caosdb_entity_datatype *out, + const char *name), + {}) + +ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_delete_datatype(caosdb_entity_datatype *out), { + if (out->_deletable) { + delete WRAPPED_DATATYPE_CAST(out); + } + out->_deletable = false; + return 0; +}) + CREATE_VALUE(int_value, const int64_t value) CREATE_VALUE(string_value, const char *value) CREATE_VALUE(double_value, const double value)