Skip to content
Snippets Groups Projects
Commit 49ea1cf7 authored by Daniel Hornung's avatar Daniel Hornung
Browse files

STY: Mostly formatting.

parent b2d07890
Branches
Tags
1 merge request!16Workaround to return non-string values, according to the specified DataType.
Pipeline #12505 failed
...@@ -553,7 +553,6 @@ public: ...@@ -553,7 +553,6 @@ public:
friend class RepeatedPtrFieldWrapper<Property, ProtoProperty>; friend class RepeatedPtrFieldWrapper<Property, ProtoProperty>;
private: private:
/** /**
* Workaround until non-string values are supported by the server. * Workaround until non-string values are supported by the server.
* *
......
...@@ -46,8 +46,7 @@ Messages::~Messages() = default; ...@@ -46,8 +46,7 @@ Messages::~Messages() = default;
// Forward declarations /////////////////////////////////////////////////////// // Forward declarations ///////////////////////////////////////////////////////
template<typename E> template <typename E> auto FixValueImpl(E *ent) -> void;
auto FixValueImpl(E* ent) -> void;
// Parent ///////////////////////////////////////////////////////////////////// // Parent /////////////////////////////////////////////////////////////////////
...@@ -75,9 +74,7 @@ auto Parent::SetId(const std::string &id) -> void { this->wrapped->set_id(id); } ...@@ -75,9 +74,7 @@ auto Parent::SetId(const std::string &id) -> void { this->wrapped->set_id(id); }
return this->wrapped->description(); return this->wrapped->description();
} }
Property::Property() : Property(Property::CreateProtoProperty()) { Property::Property() : Property(Property::CreateProtoProperty()) { FixValue(); }
FixValue();
}
auto Property::CreateProtoProperty() -> ProtoProperty * { auto Property::CreateProtoProperty() -> ProtoProperty * {
return Arena::CreateMessage<ProtoProperty>(get_arena()); return Arena::CreateMessage<ProtoProperty>(get_arena());
...@@ -163,9 +160,7 @@ auto Property::SetDataType(const std::string &new_data_type, bool list_type) -> ...@@ -163,9 +160,7 @@ auto Property::SetDataType(const std::string &new_data_type, bool list_type) ->
return SetDataType(DataType(new_data_type, list_type)); return SetDataType(DataType(new_data_type, list_type));
} }
auto Property::FixValue() -> void { auto Property::FixValue() -> void { FixValueImpl(this); }
FixValueImpl(this);
}
// Entity ///////////////////////////////////////////////////////////////////// // Entity /////////////////////////////////////////////////////////////////////
[[nodiscard]] auto Entity::GetParents() const -> const Parents & { return parents; } [[nodiscard]] auto Entity::GetParents() const -> const Parents & { return parents; }
...@@ -193,9 +188,7 @@ Entity::Entity(IdResponse *id_response) : Entity() { ...@@ -193,9 +188,7 @@ Entity::Entity(IdResponse *id_response) : Entity() {
FixValue(); FixValue();
} }
Entity::Entity() : Entity(Entity::CreateProtoEntity()) { Entity::Entity() : Entity(Entity::CreateProtoEntity()) { FixValue(); }
FixValue();
}
auto Entity::CreateMessagesField() -> RepeatedPtrField<ProtoMessage> * { auto Entity::CreateMessagesField() -> RepeatedPtrField<ProtoMessage> * {
return Arena::CreateMessage<RepeatedPtrField<ProtoMessage>>(get_arena()); return Arena::CreateMessage<RepeatedPtrField<ProtoMessage>>(get_arena());
...@@ -275,14 +268,11 @@ auto Entity::SetFilePath(const std::string &path) -> void { ...@@ -275,14 +268,11 @@ auto Entity::SetFilePath(const std::string &path) -> void {
this->wrapped->mutable_file_descriptor()->set_path(path); this->wrapped->mutable_file_descriptor()->set_path(path);
} }
auto Entity::FixValue() -> void { auto Entity::FixValue() -> void { FixValueImpl(this); }
FixValueImpl(this);
}
// Utility functions ////////////////////////////////////////////////////////// // Utility functions //////////////////////////////////////////////////////////
template<typename E> template <typename E> auto FixValueImpl(E *ent) -> void {
auto FixValueImpl(E* ent) -> void {
const auto &dtype = ent->GetDataType(); const auto &dtype = ent->GetDataType();
const auto &value = ent->GetValue(); const auto &value = ent->GetValue();
auto new_value = Value(); auto new_value = Value();
...@@ -304,9 +294,8 @@ auto FixValueImpl(E* ent) -> void { ...@@ -304,9 +294,8 @@ auto FixValueImpl(E* ent) -> void {
auto &list_type = dtype.AsList(); auto &list_type = dtype.AsList();
atype = list_type.GetAtomicDataType(); atype = list_type.GetAtomicDataType();
if (!list_type.IsListOfAtomic() // References, strings etc. need no treatment. if (!list_type.IsListOfAtomic() // References, strings etc. need no treatment.
|| atype == AtomicDataType::UNSPECIFIED || atype == AtomicDataType::UNSPECIFIED || atype == AtomicDataType::TEXT ||
|| atype == AtomicDataType::TEXT atype == AtomicDataType::DATETIME) {
|| atype == AtomicDataType::DATETIME) {
return; return;
} }
if (atype == AtomicDataType::DOUBLE) { if (atype == AtomicDataType::DOUBLE) {
...@@ -316,7 +305,7 @@ auto FixValueImpl(E* ent) -> void { ...@@ -316,7 +305,7 @@ auto FixValueImpl(E* ent) -> void {
} }
new_value = Value(data); new_value = Value(data);
} else if (atype == AtomicDataType::INTEGER) { } else if (atype == AtomicDataType::INTEGER) {
std::vector<long> data; std::vector<int64_t> data;
for (auto &d : value.AsList()) { for (auto &d : value.AsList()) {
data.push_back(std::stol(d.AsString())); data.push_back(std::stol(d.AsString()));
} }
...@@ -324,7 +313,7 @@ auto FixValueImpl(E* ent) -> void { ...@@ -324,7 +313,7 @@ auto FixValueImpl(E* ent) -> void {
} else if (atype == AtomicDataType::BOOLEAN) { } else if (atype == AtomicDataType::BOOLEAN) {
std::vector<bool> data; std::vector<bool> data;
for (auto &d : value.AsList()) { for (auto &d : value.AsList()) {
auto bool_value = d.AsString(); const auto &bool_value = d.AsString();
if (boost::to_upper_copy(bool_value) == "TRUE") { if (boost::to_upper_copy(bool_value) == "TRUE") {
data.push_back(true); data.push_back(true);
} else if (boost::to_upper_copy(bool_value) == "FALSE") { } else if (boost::to_upper_copy(bool_value) == "FALSE") {
...@@ -346,9 +335,8 @@ auto FixValueImpl(E* ent) -> void { ...@@ -346,9 +335,8 @@ auto FixValueImpl(E* ent) -> void {
} }
atype = dtype.AsAtomic(); atype = dtype.AsAtomic();
if (!dtype.IsAtomic() // References, strings etc. need no treatment. if (!dtype.IsAtomic() // References, strings etc. need no treatment.
|| atype == AtomicDataType::UNSPECIFIED || atype == AtomicDataType::UNSPECIFIED || atype == AtomicDataType::TEXT ||
|| atype == AtomicDataType::TEXT atype == AtomicDataType::DATETIME) {
|| atype == AtomicDataType::DATETIME) {
return; return;
} }
if (atype == AtomicDataType::DOUBLE) { if (atype == AtomicDataType::DOUBLE) {
...@@ -356,7 +344,7 @@ auto FixValueImpl(E* ent) -> void { ...@@ -356,7 +344,7 @@ auto FixValueImpl(E* ent) -> void {
} else if (atype == AtomicDataType::INTEGER) { } else if (atype == AtomicDataType::INTEGER) {
new_value = Value(std::stol(value.AsString())); new_value = Value(std::stol(value.AsString()));
} else if (atype == AtomicDataType::BOOLEAN) { } else if (atype == AtomicDataType::BOOLEAN) {
auto bool_value = value.AsString(); const auto &bool_value = value.AsString();
if (boost::to_upper_copy(bool_value) == "TRUE") { if (boost::to_upper_copy(bool_value) == "TRUE") {
new_value = Value(true); new_value = Value(true);
} else if (boost::to_upper_copy(bool_value) == "FALSE") { } else if (boost::to_upper_copy(bool_value) == "FALSE") {
...@@ -374,5 +362,4 @@ auto FixValueImpl(E* ent) -> void { ...@@ -374,5 +362,4 @@ auto FixValueImpl(E* ent) -> void {
ent->SetValue(new_value); ent->SetValue(new_value);
} }
} // namespace caosdb::entity } // namespace caosdb::entity
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment