Skip to content
Snippets Groups Projects

ENH: Allow insertion and deletion of single entities

Merged Florian Spreckelsen requested to merge f-insert into dev
All threads resolved!
Compare and Show latest version
4 files
+ 192
9
Compare changes
  • Side-by-side
  • Inline
Files
4
+ 82
7
@@ -2,6 +2,7 @@
* This file is a part of the CaosDB Project.
*
* Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com>
* Copyright (C) 2021 Florian Spreckelsen <f.spreckelsen@indiscale.com>
* Copyright (C) 2021 IndiScale GmbH <info@indiscale.com>
*
* This program is free software: you can redistribute it and/or modify
@@ -36,6 +37,7 @@
namespace caosdb::entity {
using caosdb::entity::v1alpha1::IdResponse;
using ProtoParent = caosdb::entity::v1alpha1::Parent;
using ProtoProperty = caosdb::entity::v1alpha1::Property;
using ProtoEntity = caosdb::entity::v1alpha1::Entity;
/**
@@ -246,14 +248,35 @@ class Property {
public:
explicit inline Property(caosdb::entity::v1alpha1::Property *wrapped)
: wrapped(wrapped){};
Property();
// TODO(fspreck) All of these methods need implementations.
/**
* Return the id of this property
*/
[[nodiscard]] auto GetId() const -> const std::string &;
/**
* Return the name of this property
*/
[[nodiscard]] auto GetName() const -> const std::string &;
/**
* Return the description of this property
*/
[[nodiscard]] auto GetDescription() const -> const std::string &;
/**
* Return the importance of this property
*/
[[nodiscard]] auto GetImportance() const -> const std::string &;
/**
* Return the value of this property
*/
[[nodiscard]] auto GetValue() const -> const std::string &;
/**
* Return the unit of this property
*/
[[nodiscard]] auto GetUnit() const -> const std::string &;
/**
* Return the datatype of this property
*/
[[nodiscard]] auto GetDatatype() const -> const std::string &;
// TODO(fspreck) Implement these when we have decided how to attach
// messages to properties.
@@ -261,18 +284,52 @@ public:
// [[nodiscard]] auto GetWarnings() const -> const Messages &;
// [[nodiscard]] auto GetInfos() const -> const Messages &;
/**
* Set the id of this property.
*/
auto SetId(const std::string &id) -> void;
/**
* Set the name of this property.
*/
auto SetName(const std::string &name) -> void;
/**
* Set the importance of this property.
*/
auto SetImportance(const std::string &importance) -> void;
/**
* Set the value of this property.
*/
auto SetValue(const std::string &value) -> void;
/**
* Set the unit of this property.
*/
auto SetUnit(const std::string &unit) -> void;
/**
* Set the datatype of this property.
*/
auto SetDatatype(const std::string &datatype) -> void;
/**
* Return a json string representing this property.
*
* This is intended for debugging
*/
inline auto ToString() const -> const std::string {
google::protobuf::util::JsonOptions options;
std::string out;
google::protobuf::util::MessageToJsonString(*(this->wrapped), &out,
options);
return out;
}
friend class Entity;
friend class Properties;
private:
caosdb::entity::v1alpha1::Property *wrapped;
static auto CreateProtoProperty() -> ProtoProperty *;
mutable caosdb::entity::v1alpha1::Property *wrapped;
};
/**
@@ -282,10 +339,18 @@ private:
*/
class Properties {
public:
// TODO(fspreck) Implementations needed (basically everything). See Parents
// container for inspiration.
[[nodiscard]] auto At(int index) const -> const Property &;
auto Append(const Property &property) -> void;
/**
* Return the current size of the properties container.
*
* This is also the number of properties the owningn entity currently has.
*/
[[nodiscard]] inline auto Size() const -> int { return wrapped->size(); }
/**
* Return the property at the given index.
*/
[[nodiscard]] auto At(int index) const -> const Property {
return Property(&(wrapped->at(index)));
}
friend class Entity;
@@ -296,6 +361,13 @@ private:
*wrapped)
: wrapped(wrapped){};
/**
* Append a property
*
* This increases the Size() by one.
*/
auto Append(const Property &property) -> void;
::google::protobuf::RepeatedPtrField<caosdb::entity::v1alpha1::Property>
*wrapped;
};
@@ -375,11 +447,14 @@ public:
auto SetUnit(const std::string &unit) -> void;
// Currently no references or lists.
auto SetDatatype(const std::string &datatype) -> void;
// TODO(fspreck) this one is tricky. See AppendParent
auto AppendProperty(const Property &property) -> void;
auto AppendParent(const Parent &parent) -> void;
auto Switch(ProtoEntity *entity) -> void;
/**
* Copy all of this entity's features to the target ProtoEntity.
*/
auto CopyTo(ProtoEntity *target) -> void;
private:
static auto CreateProtoEntity() -> ProtoEntity *;
Loading