diff --git a/include/caosdb/transaction.h b/include/caosdb/transaction.h index ee848469cf6fd23abde4542c8a1db7f12ac94c76..48762db4396e8996442ef5be287e3965836ecd4e 100644 --- a/include/caosdb/transaction.h +++ b/include/caosdb/transaction.h @@ -31,7 +31,6 @@ #include "caosdb/transaction_status.h" // for TransactionStatus #include "caosdb/status_code.h" // for StatusCode #include "google/protobuf/util/json_util.h" // for MessageToJsonString, Jso... -#include <cstddef> // for size_t #include <iterator> // IWYU pragma: no_include <ext/alloc_traits.h> #include <memory> // for shared_ptr, unique_ptr @@ -180,7 +179,7 @@ class ResultSet { public: virtual ~ResultSet() = default; - [[nodiscard]] virtual auto Size() const noexcept -> size_t = 0; + [[nodiscard]] virtual auto Size() const noexcept -> int = 0; [[nodiscard]] virtual auto At(const int index) const -> const Entity & = 0; auto begin() const -> iterator; auto end() const -> iterator; @@ -188,14 +187,14 @@ public: private: class iterator : public std::iterator<std::output_iterator_tag, Entity> { public: - explicit iterator(const ResultSet *result_set, size_t index = 0); + explicit iterator(const ResultSet *result_set, int index = 0); auto operator*() const -> const Entity &; auto operator++() -> iterator &; auto operator++(int) -> iterator; auto operator!=(const iterator &rhs) const -> bool; private: - size_t current_index = 0; + int current_index = 0; const ResultSet *result_set; }; }; @@ -210,7 +209,7 @@ class MultiResultSet : public ResultSet { public: ~MultiResultSet() = default; explicit MultiResultSet(MultiTransactionResponse *response); - [[nodiscard]] inline auto Size() const noexcept -> size_t override { + [[nodiscard]] inline auto Size() const noexcept -> int override { return this->entities.size(); } [[nodiscard]] inline auto At(const int index) const @@ -234,9 +233,7 @@ public: explicit inline UniqueResult(IdResponse *idResponse) : entity(new Entity(idResponse)){}; [[nodiscard]] auto GetEntity() const -> const Entity &; - [[nodiscard]] inline auto Size() const noexcept -> size_t override { - return 1; - } + [[nodiscard]] inline auto Size() const noexcept -> int override { return 1; } [[nodiscard]] inline auto At(const int index) const -> const Entity & override { if (index != 0) { diff --git a/src/caosdb/transaction.cpp b/src/caosdb/transaction.cpp index 9709a884aa8e2e2a9b9481f08d0ccba9b8feef74..f946175f3b33397e9398188500cf0ef51cc16d26 100644 --- a/src/caosdb/transaction.cpp +++ b/src/caosdb/transaction.cpp @@ -75,7 +75,8 @@ auto get_status_description(int code) -> const std::string & { "The Transaction has a transaction type which does not allow the " "attempted action."}, {StatusCode::ORIGINAL_ENTITY_MISSING_ID, - "The attempt to update this entity failed because this entity does have " + "The attempt to update this entity failed because this entity does not " + "have " "an id. This is the case when you did not retrieve it before applying any " "changes and instantiated the Entity class explicitely."}, {StatusCode::UNSUPPORTED_FEATURE, @@ -100,14 +101,11 @@ using grpc::ClientAsyncResponseReader; using ProtoEntity = caosdb::entity::v1alpha1::Entity; using grpc::CompletionQueue; -ResultSet::iterator::iterator(const ResultSet *result_set_param, size_t index) +ResultSet::iterator::iterator(const ResultSet *result_set_param, int index) : current_index(index), result_set(result_set_param) {} auto ResultSet::iterator::operator*() const -> const Entity & { - // TODO(tf) clang warns about a bugprone conversion from unsigned - // size_t to signed int, i.e., the `index` of ResultSet::At. Should - // we make this unsigned as well? - return this->result_set->At(current_index); // NOLINT + return this->result_set->At(current_index); } auto ResultSet::iterator::operator++() -> ResultSet::iterator & { diff --git a/test/test_entity.cpp b/test/test_entity.cpp index 7b08e6d392fe89d519fbe0fc2c62a59a1ec07b00..3639f8c574ae90e70f0ef9abeb77a4403fadc06b 100644 --- a/test/test_entity.cpp +++ b/test/test_entity.cpp @@ -30,9 +30,7 @@ #include "gtest/gtest-message.h" // for Message #include "gtest/gtest-test-part.h" // for TestPartResult, Sui... #include "gtest/gtest_pred_impl.h" // for Test, EXPECT_EQ -#include <iostream> // for endl, basic_ostream #include <memory> // for allocator, shared_ptr -#include <string> // for operator<< namespace caosdb::entity { using caosdb::entity::v1alpha1::IdResponse; @@ -187,7 +185,6 @@ TEST(test_entity, test_insert_with_parent) { transaction.InsertEntity(&entity); - std::cout << entity.ToString() << std::endl; EXPECT_EQ(entity.GetName(), "entity_name"); EXPECT_EQ(entity.GetParents().Size(), 1); auto inserted_parent = entity.GetParents().At(0); @@ -251,18 +248,14 @@ TEST(test_entity, test_from_id_response) { info->set_description("info_desc"); info->set_code(MessageCode::UNSPECIFIED); - std::cout << entity.ToString() << std::endl; Entity other_ent(&idr_warnings_and_infos); - std::cout << entity.ToString() << std::endl; EXPECT_EQ(other_ent.GetId(), "other_entity_id"); - std::cout << entity.ToString() << std::endl; EXPECT_EQ(other_ent.GetWarnings().Size(), 1); EXPECT_TRUE(other_ent.HasWarnings()); EXPECT_EQ(other_ent.GetWarnings().At(0).GetDescription(), "warning_desc"); EXPECT_EQ(other_ent.GetWarnings().At(0).GetCode(), MessageCode::ENTITY_HAS_NO_PROPERTIES); - std::cout << entity.ToString() << std::endl; EXPECT_EQ(other_ent.GetInfos().Size(), 1); EXPECT_EQ(other_ent.GetInfos().At(0).GetDescription(), "info_desc"); EXPECT_EQ(other_ent.GetInfos().At(0).GetCode(), MessageCode::UNSPECIFIED);