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
+ 302
9
Compare changes
  • Side-by-side
  • Inline

Files

+ 82
7
@@ -2,6 +2,7 @@
@@ -2,6 +2,7 @@
* This file is a part of the CaosDB Project.
* This file is a part of the CaosDB Project.
*
*
* Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com>
* 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>
* Copyright (C) 2021 IndiScale GmbH <info@indiscale.com>
*
*
* This program is free software: you can redistribute it and/or modify
* This program is free software: you can redistribute it and/or modify
@@ -36,6 +37,7 @@
@@ -36,6 +37,7 @@
namespace caosdb::entity {
namespace caosdb::entity {
using caosdb::entity::v1alpha1::IdResponse;
using caosdb::entity::v1alpha1::IdResponse;
using ProtoParent = caosdb::entity::v1alpha1::Parent;
using ProtoParent = caosdb::entity::v1alpha1::Parent;
 
using ProtoProperty = caosdb::entity::v1alpha1::Property;
using ProtoEntity = caosdb::entity::v1alpha1::Entity;
using ProtoEntity = caosdb::entity::v1alpha1::Entity;
/**
/**
@@ -246,14 +248,35 @@ class Property {
@@ -246,14 +248,35 @@ class Property {
public:
public:
explicit inline Property(caosdb::entity::v1alpha1::Property *wrapped)
explicit inline Property(caosdb::entity::v1alpha1::Property *wrapped)
: wrapped(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 &;
[[nodiscard]] auto GetId() const -> const std::string &;
 
/**
 
* Return the name of this property
 
*/
[[nodiscard]] auto GetName() const -> const std::string &;
[[nodiscard]] auto GetName() const -> const std::string &;
 
/**
 
* Return the description of this property
 
*/
[[nodiscard]] auto GetDescription() const -> const std::string &;
[[nodiscard]] auto GetDescription() const -> const std::string &;
 
/**
 
* Return the importance of this property
 
*/
[[nodiscard]] auto GetImportance() const -> const std::string &;
[[nodiscard]] auto GetImportance() const -> const std::string &;
 
/**
 
* Return the value of this property
 
*/
[[nodiscard]] auto GetValue() const -> const std::string &;
[[nodiscard]] auto GetValue() const -> const std::string &;
 
/**
 
* Return the unit of this property
 
*/
[[nodiscard]] auto GetUnit() const -> const std::string &;
[[nodiscard]] auto GetUnit() const -> const std::string &;
 
/**
 
* Return the datatype of this property
 
*/
[[nodiscard]] auto GetDatatype() const -> const std::string &;
[[nodiscard]] auto GetDatatype() const -> const std::string &;
// TODO(fspreck) Implement these when we have decided how to attach
// TODO(fspreck) Implement these when we have decided how to attach
// messages to properties.
// messages to properties.
@@ -261,18 +284,52 @@ public:
@@ -261,18 +284,52 @@ public:
// [[nodiscard]] auto GetWarnings() const -> const Messages &;
// [[nodiscard]] auto GetWarnings() const -> const Messages &;
// [[nodiscard]] auto GetInfos() const -> const Messages &;
// [[nodiscard]] auto GetInfos() const -> const Messages &;
 
/**
 
* Set the id of this property.
 
*/
auto SetId(const std::string &id) -> void;
auto SetId(const std::string &id) -> void;
 
/**
 
* Set the name of this property.
 
*/
auto SetName(const std::string &name) -> void;
auto SetName(const std::string &name) -> void;
 
/**
 
* Set the importance of this property.
 
*/
auto SetImportance(const std::string &importance) -> void;
auto SetImportance(const std::string &importance) -> void;
 
/**
 
* Set the value of this property.
 
*/
auto SetValue(const std::string &value) -> void;
auto SetValue(const std::string &value) -> void;
 
/**
 
* Set the unit of this property.
 
*/
auto SetUnit(const std::string &unit) -> void;
auto SetUnit(const std::string &unit) -> void;
 
/**
 
* Set the datatype of this property.
 
*/
auto SetDatatype(const std::string &datatype) -> void;
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 Entity;
friend class Properties;
friend class Properties;
private:
private:
caosdb::entity::v1alpha1::Property *wrapped;
static auto CreateProtoProperty() -> ProtoProperty *;
 
 
mutable caosdb::entity::v1alpha1::Property *wrapped;
};
};
/**
/**
@@ -282,10 +339,18 @@ private:
@@ -282,10 +339,18 @@ private:
*/
*/
class Properties {
class Properties {
public:
public:
// TODO(fspreck) Implementations needed (basically everything). See Parents
/**
// container for inspiration.
* Return the current size of the properties container.
[[nodiscard]] auto At(int index) const -> const Property &;
*
auto Append(const Property &property) -> void;
* 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;
friend class Entity;
@@ -296,6 +361,13 @@ private:
@@ -296,6 +361,13 @@ private:
*wrapped)
*wrapped)
: wrapped(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>
::google::protobuf::RepeatedPtrField<caosdb::entity::v1alpha1::Property>
*wrapped;
*wrapped;
};
};
@@ -375,11 +447,14 @@ public:
@@ -375,11 +447,14 @@ public:
auto SetUnit(const std::string &unit) -> void;
auto SetUnit(const std::string &unit) -> void;
// Currently no references or lists.
// Currently no references or lists.
auto SetDatatype(const std::string &datatype) -> void;
auto SetDatatype(const std::string &datatype) -> void;
// TODO(fspreck) this one is tricky. See AppendParent
auto AppendProperty(const Property &property) -> void;
auto AppendProperty(const Property &property) -> void;
auto AppendParent(const Parent &parent) -> void;
auto AppendParent(const Parent &parent) -> void;
auto Switch(ProtoEntity *entity) -> void;
auto Switch(ProtoEntity *entity) -> void;
 
/**
 
* Copy all of this entity's features to the target ProtoEntity.
 
*/
 
auto CopyTo(ProtoEntity *target) -> void;
private:
private:
static auto CreateProtoEntity() -> ProtoEntity *;
static auto CreateProtoEntity() -> ProtoEntity *;
Loading