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

STY: Mostly formatting.

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