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
7 files
+ 270
26
Compare changes
  • Side-by-side
  • Inline
Files
7
+ 118
24
@@ -36,6 +36,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;
/**
@@ -54,6 +55,10 @@ public:
}
friend class Entity;
// TODO(fspreck) Re-enable once we have decided how messages are
// appended to parents and properties
// friend class Parent;
// friend class Property;
friend class Messages;
private:
@@ -74,6 +79,9 @@ public:
}
friend class Entity;
// TODO(fspreck) Same here.
// friend class Parent;
// friend class Property;
private:
inline Messages() : wrapped(nullptr){};
@@ -134,20 +142,32 @@ public:
return out;
}
// TODO(fspreck) These need implementations. See Entity::GetErrors for
// inspiration.
/**
* Return the error messages of this parent.
*/
[[nodiscard]] inline auto GetErrors() const -> const Messages &;
/**
* Return the warning messages of this parent.
*/
[[nodiscard]] inline auto GetWarnings() const -> const Messages &;
/**
* Return the info messages of this parent.
*/
[[nodiscard]] inline auto GetInfos() const -> const Messages &;
// TODO(fspreck) Finish the following implementations once we have
// decided how to attach messages to parents.
// /**
// * Return the error messages of this parent.
// */
// [[nodiscard]] inline auto GetErrors() const -> const Messages & {
// return errors;
// }
// [[nodiscard]] inline auto HasErrors() const -> bool {
// return this->errors.wrapped->size() > 0;
// }
// /**
// * Return the warning messages of this parent.
// */
// [[nodiscard]] inline auto GetWarnings() const -> const Messages & {
// return warnings;
// }
// [[nodiscard]] inline auto HasWarnings() const -> bool {
// return this->warnings.wrapped->size() > 0;
// }
// /**
// * Return the info messages of this parent.
// */
// [[nodiscard]] inline auto GetInfos() const -> const Messages & {
// return infos;
// }
friend class Entity;
friend class Parents;
@@ -169,6 +189,9 @@ private:
* Message which serves as storage backend.
*/
mutable caosdb::entity::v1alpha1::Parent *wrapped;
// Messages errors;
// Messages warnings;
// Messages infos;
};
/**
@@ -224,31 +247,88 @@ 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 &;
[[nodiscard]] auto GetErrors() const -> const Messages &;
[[nodiscard]] auto GetWarnings() const -> const Messages &;
[[nodiscard]] auto GetInfos() const -> const Messages &;
// TODO(fspreck) Implement these when we have decided how to attach
// messages to properties.
// [[nodiscard]] auto GetErrors() const -> const Messages &;
// [[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;
};
/**
@@ -258,10 +338,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;
@@ -272,6 +360,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;
};
@@ -351,7 +446,6 @@ 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;
Loading