Skip to content
Snippets Groups Projects

ENH: Allow insert/update/delete and files in Extern C

Merged Florian Spreckelsen requested to merge f-full-c into dev
All threads resolved!
1 file
+ 38
0
Compare changes
  • Side-by-side
  • Inline
+ 67
8
@@ -75,7 +75,7 @@ extern "C" {
GENERIC_ERROR, \
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); \
auto *tmp = (char *)malloc(sizeof(char) * wrapped_entity->GetFunction.length() + 1); \
strcpy(tmp, wrapped_entity->GetFunction.c_str()); \
delete[] * out; \
*out = tmp; \
@@ -101,7 +101,7 @@ extern "C" {
GENERIC_ERROR, \
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); \
auto *tmp = (char *)malloc(sizeof(char) * wrapped_property->GetFunction.length() + 1); \
strcpy(tmp, wrapped_property->GetFunction.c_str()); \
delete[] * out; \
*out = tmp; \
@@ -128,7 +128,7 @@ extern "C" {
GENERIC_ERROR, \
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); \
auto *tmp = (char *)malloc(sizeof(char) * wrapped_parent->GetFunction.length() + 1); \
strcpy(tmp, wrapped_parent->GetFunction.c_str()); \
delete[] * out; \
*out = tmp; \
@@ -338,12 +338,12 @@ ERROR_RETURN_CODE(
out->patch = (int)version_info->GetPatch();
// copy pre_release, needs local variable because out->pre_release is const
char *pre_release = (char *)malloc(sizeof(char) * (version_info->GetPreRelease().length() + 1));
auto *pre_release = (char *)malloc(sizeof(char) * (version_info->GetPreRelease().length() + 1));
strcpy(pre_release, version_info->GetPreRelease().c_str());
out->pre_release = pre_release;
// copy build, needs local variable because out->build is const
char *build = (char *)malloc(sizeof(char) * (version_info->GetBuild().length() + 1));
auto *build = (char *)malloc(sizeof(char) * (version_info->GetBuild().length() + 1));
strcpy(build, version_info->GetBuild().c_str());
out->build = build;
@@ -413,6 +413,16 @@ ERROR_RETURN_CODE(GENERIC_ERROR,
return wrapped_transaction->RetrieveById(std::string(id));
})
ERROR_RETURN_CODE(GENERIC_ERROR,
int caosdb_transaction_transaction_retrieve_and_download_file_by_id(
caosdb_transaction_transaction *transaction, const char *id, const char *path),
{
auto *wrapped_transaction = static_cast<caosdb::transaction::Transaction *>(
transaction->wrapped_transaction);
return wrapped_transaction->RetrieveAndDownloadFileById(std::string(id),
std::string(path));
})
ERROR_RETURN_CODE(GENERIC_ERROR,
int caosdb_transaction_transaction_retrieve_by_ids(
caosdb_transaction_transaction *transaction, const char *ids[], int length),
@@ -431,6 +441,40 @@ ERROR_RETURN_CODE(GENERIC_ERROR,
return wrapped_transaction->Query(std::string(query));
})
ERROR_RETURN_CODE(
GENERIC_ERROR,
int caosdb_transaction_transaction_insert_entity(caosdb_transaction_transaction *transaction,
caosdb_entity_entity *entity),
{
auto *wrapped_transaction =
static_cast<caosdb::transaction::Transaction *>(transaction->wrapped_transaction);
auto *wrapped_entity = static_cast<caosdb::entity::Entity *>(entity->wrapped_entity);
return wrapped_transaction->InsertEntity(wrapped_entity);
})
ERROR_RETURN_CODE(
GENERIC_ERROR,
int caosdb_transaction_transaction_update_entity(caosdb_transaction_transaction *transaction,
caosdb_entity_entity *entity),
{
auto *wrapped_transaction =
static_cast<caosdb::transaction::Transaction *>(transaction->wrapped_transaction);
auto *wrapped_entity = static_cast<caosdb::entity::Entity *>(entity->wrapped_entity);
return wrapped_transaction->UpdateEntity(wrapped_entity);
})
ERROR_RETURN_CODE(GENERIC_ERROR,
int caosdb_transaction_transaction_delete_by_id(
caosdb_transaction_transaction *transaction, const char *id),
{
auto *wrapped_transaction = static_cast<caosdb::transaction::Transaction *>(
transaction->wrapped_transaction);
return wrapped_transaction->DeleteById(std::string(id));
})
ERROR_RETURN_CODE(
GENERIC_ERROR,
int caosdb_transaction_transaction_execute(caosdb_transaction_transaction *transaction), {
@@ -544,13 +588,25 @@ 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);
auto *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())
ERROR_RETURN_CODE(GENERIC_ERROR,
int caosdb_entity_entity_get_local_path(caosdb_entity_entity *entity, char **out),
{
auto *wrapped_entity = WRAPPED_ENTITY_CAST(entity);
auto path = wrapped_entity->GetLocalPath().string();
auto *tmp = (char *)(malloc(sizeof(char) * path.length() + 1));
strcpy(tmp, path.c_str());
delete[] * out;
*out = tmp;
return 0;
})
// CAOSDB_ENTITY_GET(file_path, GetFilePath()) TODO(henrik)
CAOSDB_ENTITY_GET(description, GetDescription())
ERROR_RETURN_CODE(GENERIC_ERROR,
int caosdb_entity_entity_get_datatype(caosdb_entity_entity *entity, char **name,
@@ -895,7 +951,7 @@ ERROR_RETURN_CODE(GENERIC_ERROR,
{
auto *wrapped_property = WRAPPED_PROPERTY_CAST(property);
auto value_list = wrapped_property->GetValue().AsList();
char *tmp =
auto *tmp =
(char *)malloc(sizeof(char) * value_list[index].AsString().length() + 1);
strcpy(tmp, value_list[index].AsString().c_str());
delete[] * out;
@@ -928,7 +984,7 @@ 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);
auto *tmp = (char *)malloc(sizeof(char) * wrapped_message->GetDescription().length() + 1);
strcpy(tmp, wrapped_message->GetDescription().c_str());
delete[] * out;
*out = tmp;
@@ -949,6 +1005,9 @@ ERROR_RETURN_CODE(GENERIC_ERROR,
}
})
CAOSDB_ENTITY_SET(name, name, wrapped_entity->SetName(std::string(name));)
CAOSDB_ENTITY_SET(local_path, local_path,
return wrapped_entity->SetLocalPath(boost::filesystem::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));)
ERROR_RETURN_CODE(GENERIC_ERROR,
Loading