From b0d5af32db80fd38baaa8a9c5d6f81acd060e752 Mon Sep 17 00:00:00 2001 From: Timm Fitschen <t.fitschen@indiscale.com> Date: Wed, 15 Sep 2021 10:45:30 +0200 Subject: [PATCH] Change DataType::As<T> to GetAs<T> --- include/caosdb/data_type.h | 6 +++--- test/test_data_type.cpp | 14 +++++++------- test/test_entity.cpp | 14 +++++++------- test/test_list_properties.cpp | 4 ++-- test/test_protobuf.cpp | 4 ++-- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/include/caosdb/data_type.h b/include/caosdb/data_type.h index 22358fc..e6b92d5 100644 --- a/include/caosdb/data_type.h +++ b/include/caosdb/data_type.h @@ -179,14 +179,14 @@ public: [[nodiscard]] inline auto IsAtomic() const noexcept -> bool { return this->wrapped->data_type_case() == DataTypeCase::kAtomicDataType; } - [[nodiscard]] inline auto AsAtomic() const noexcept -> AtomicDataType { + [[nodiscard]] inline auto GetAsAtomic() const noexcept -> AtomicDataType { return static_cast<AtomicDataType>(this->wrapped->atomic_data_type()); } [[nodiscard]] inline auto IsReference() const noexcept -> bool { return this->wrapped->data_type_case() == DataTypeCase::kReferenceDataType; } - [[nodiscard]] inline auto AsReference() const noexcept -> const ReferenceDataType & { + [[nodiscard]] inline auto GetAsReference() const noexcept -> const ReferenceDataType & { if (!IsReference()) { return ReferenceDataType::GetEmptyInstance(); } else if (reference_data_type == nullptr) { @@ -200,7 +200,7 @@ public: return this->wrapped->data_type_case() == DataTypeCase::kListDataType; } - [[nodiscard]] inline auto AsList() const noexcept -> const ListDataType & { + [[nodiscard]] inline auto GetAsList() const noexcept -> const ListDataType & { if (!IsList()) { return ListDataType::GetEmptyInstance(); } else if (list_data_type == nullptr) { diff --git a/test/test_data_type.cpp b/test/test_data_type.cpp index bb2e97b..51624a7 100644 --- a/test/test_data_type.cpp +++ b/test/test_data_type.cpp @@ -53,17 +53,17 @@ TEST(test_data_type, test_atomic) { // the different AtomicDataType are associated with integers entity.SetDataType(map_el.first); EXPECT_TRUE(entity.GetDataType().IsAtomic()); - EXPECT_EQ(entity.GetDataType().AsAtomic(), map_el.first); + EXPECT_EQ(entity.GetDataType().GetAsAtomic(), map_el.first); proto_data_type.set_atomic_data_type(static_cast<ProtoAtomicDataType>(map_el.first)); DataType data_type(&proto_data_type); entity.SetDataType(data_type); EXPECT_FALSE(data_type.IsReference()); - EXPECT_EQ(data_type.AsReference().GetName(), std::basic_string<char>("")); + EXPECT_EQ(data_type.GetAsReference().GetName(), std::basic_string<char>("")); EXPECT_FALSE(data_type.IsList()); EXPECT_TRUE(data_type.IsAtomic()); - EXPECT_EQ(data_type.AsAtomic(), map_el.first); + EXPECT_EQ(data_type.GetAsAtomic(), map_el.first); } } @@ -74,7 +74,7 @@ TEST(test_data_type, test_reference) { entity.SetRole(Role::PROPERTY); entity.SetDataType("Person"); EXPECT_TRUE(entity.GetDataType().IsReference()); - EXPECT_EQ(entity.GetDataType().AsReference().GetName(), "Person"); + EXPECT_EQ(entity.GetDataType().GetAsReference().GetName(), "Person"); proto_data_type.mutable_reference_data_type()->set_name("Person"); DataType data_type(&proto_data_type); @@ -83,7 +83,7 @@ TEST(test_data_type, test_reference) { EXPECT_TRUE(data_type.IsReference()); EXPECT_FALSE(data_type.IsList()); EXPECT_FALSE(data_type.IsAtomic()); - EXPECT_EQ(data_type.AsReference().GetName(), "Person"); + EXPECT_EQ(data_type.GetAsReference().GetName(), "Person"); } TEST(test_data_type, test_list_of_atomic) { @@ -93,7 +93,7 @@ TEST(test_data_type, test_list_of_atomic) { EXPECT_FALSE(data_type.IsReference()); EXPECT_FALSE(data_type.IsAtomic()); EXPECT_TRUE(data_type.IsList()); - const auto &list_data_type = data_type.AsList(); + const auto &list_data_type = data_type.GetAsList(); EXPECT_EQ(list_data_type.GetReferenceDataType().GetName(), std::basic_string<char>("")); EXPECT_TRUE(list_data_type.IsListOfAtomic()); EXPECT_FALSE(list_data_type.IsListOfReference()); @@ -108,7 +108,7 @@ TEST(test_data_type, test_list_of_reference) { EXPECT_FALSE(data_type.IsAtomic()); EXPECT_TRUE(data_type.IsList()); - const auto &list_data_type = data_type.AsList(); + const auto &list_data_type = data_type.GetAsList(); EXPECT_TRUE(list_data_type.IsListOfReference()); EXPECT_FALSE(list_data_type.IsListOfAtomic()); const auto *wrapped = list_data_type.GetReferenceDataType().GetWrapped(); diff --git a/test/test_entity.cpp b/test/test_entity.cpp index 9e256d5..75adc7e 100644 --- a/test/test_entity.cpp +++ b/test/test_entity.cpp @@ -83,12 +83,12 @@ TEST(test_entity, test_property_setters) { EXPECT_EQ(prop.GetValue().GetAsString(), "prop_value"); EXPECT_EQ(prop.GetUnit(), "prop_unit"); EXPECT_TRUE(prop.GetDataType().IsReference()); - EXPECT_EQ(prop.GetDataType().AsReference().GetName(), "prop_dtype"); + EXPECT_EQ(prop.GetDataType().GetAsReference().GetName(), "prop_dtype"); EXPECT_FALSE(prop.GetDataType().IsList()); prop.SetDataType(AtomicDataType::DATETIME); EXPECT_TRUE(prop.GetDataType().IsAtomic()); - EXPECT_EQ(prop.GetDataType().AsAtomic(), AtomicDataType::DATETIME); + EXPECT_EQ(prop.GetDataType().GetAsAtomic(), AtomicDataType::DATETIME); EXPECT_FALSE(prop.GetDataType().IsList()); } @@ -97,16 +97,16 @@ TEST(test_entity, test_list_property_setters) { prop.SetDataType(AtomicDataType::DATETIME); // Set as atomic first. EXPECT_TRUE(prop.GetDataType().IsAtomic()); - EXPECT_EQ(prop.GetDataType().AsAtomic(), AtomicDataType::DATETIME); + EXPECT_EQ(prop.GetDataType().GetAsAtomic(), AtomicDataType::DATETIME); prop.SetDataType(AtomicDataType::DOUBLE, true); auto const &dtype = prop.GetDataType(); EXPECT_FALSE(dtype.IsAtomic()); // Should not be true anymore. EXPECT_FALSE(dtype.IsReference()); EXPECT_TRUE(dtype.IsList()); - EXPECT_NE(dtype.AsAtomic(), AtomicDataType::DATETIME); // Should be overwritten. - EXPECT_TRUE(dtype.AsList().IsListOfAtomic()); - EXPECT_EQ(dtype.AsList().GetAtomicDataType(), AtomicDataType::DOUBLE); + EXPECT_NE(dtype.GetAsAtomic(), AtomicDataType::DATETIME); // Should be overwritten. + EXPECT_TRUE(dtype.GetAsList().IsListOfAtomic()); + EXPECT_EQ(dtype.GetAsList().GetAtomicDataType(), AtomicDataType::DOUBLE); } TEST(test_entity, test_append_property) { @@ -200,7 +200,7 @@ TEST(test_entity, test_insert_with_role) { EXPECT_EQ(entity.GetRole(), Role::PROPERTY); EXPECT_TRUE(entity.GetDataType().IsAtomic()); - EXPECT_EQ(entity.GetDataType().AsAtomic(), AtomicDataType::DOUBLE); + EXPECT_EQ(entity.GetDataType().GetAsAtomic(), AtomicDataType::DOUBLE); EXPECT_EQ(entity.GetName(), "Length"); EXPECT_EQ(entity.GetUnit(), "m"); EXPECT_TRUE(entity.GetValue().IsDouble()); diff --git a/test/test_list_properties.cpp b/test/test_list_properties.cpp index 75ae98d..27d0aad 100644 --- a/test/test_list_properties.cpp +++ b/test/test_list_properties.cpp @@ -52,8 +52,8 @@ TEST(test_list_property, test_list_of_text) { const auto &value = entity.GetProperties().at(0).GetValue(); EXPECT_TRUE(data_type.IsList()); - EXPECT_TRUE(data_type.AsList().IsListOfAtomic()); - EXPECT_EQ(data_type.AsList().GetAtomicDataType(), AtomicDataType::TEXT); + EXPECT_TRUE(data_type.GetAsList().IsListOfAtomic()); + EXPECT_EQ(data_type.GetAsList().GetAtomicDataType(), AtomicDataType::TEXT); EXPECT_TRUE(value.IsVector()); EXPECT_EQ(value.GetAsVector().size(), 3); diff --git a/test/test_protobuf.cpp b/test/test_protobuf.cpp index 43ab688..6f9bda0 100644 --- a/test/test_protobuf.cpp +++ b/test/test_protobuf.cpp @@ -102,10 +102,10 @@ TEST(test_protobuf, test_copy_nested) { EXPECT_EQ(entity_destination.data_type().reference_data_type().name(), "src_per"); Entity entity(&entity_destination); - EXPECT_EQ(entity.GetDataType().AsReference().GetName(), "src_per"); + EXPECT_EQ(entity.GetDataType().GetAsReference().GetName(), "src_per"); const Entity ©_entity(entity); - EXPECT_EQ(copy_entity.GetDataType().AsReference().GetName(), "src_per"); + EXPECT_EQ(copy_entity.GetDataType().GetAsReference().GetName(), "src_per"); } } // namespace caosdb -- GitLab