From c0350b900136ffbe2df72ec3f255704ff469fa0e Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Tue, 19 Apr 2016 14:05:15 -0700 Subject: [PATCH] Rename CollectionChangeIndices to CollectionChangeSet --- src/collection_notifications.hpp | 4 ++-- src/impl/collection_notifier.cpp | 4 ++-- src/impl/collection_notifier.hpp | 4 ++-- src/results.cpp | 2 +- tests/list.cpp | 24 +++++++++++----------- tests/results.cpp | 34 +++++++++++++++---------------- tests/transaction_log_parsing.cpp | 6 +++--- tests/util/index_helpers.hpp | 2 +- 8 files changed, 40 insertions(+), 40 deletions(-) diff --git a/src/collection_notifications.hpp b/src/collection_notifications.hpp index 8fc2c0c8..ed75c315 100644 --- a/src/collection_notifications.hpp +++ b/src/collection_notifications.hpp @@ -49,7 +49,7 @@ private: size_t m_token; }; -struct CollectionChangeIndices { +struct CollectionChangeSet { struct Move { size_t from; size_t to; @@ -65,7 +65,7 @@ struct CollectionChangeIndices { bool empty() const { return deletions.empty() && insertions.empty() && modifications.empty() && moves.empty(); } }; -using CollectionChangeCallback = std::function; +using CollectionChangeCallback = std::function; } // namespace realm #endif // REALM_COLLECTION_NOTIFICATIONS_HPP diff --git a/src/impl/collection_notifier.cpp b/src/impl/collection_notifier.cpp index acf95d71..aa96ea8b 100644 --- a/src/impl/collection_notifier.cpp +++ b/src/impl/collection_notifier.cpp @@ -557,7 +557,7 @@ struct RowInfo { size_t shifted_tv_index; }; -void calculate_moves_unsorted(std::vector& new_rows, IndexSet& removed, CollectionChangeIndices& changeset) +void calculate_moves_unsorted(std::vector& new_rows, IndexSet& removed, CollectionChangeSet& changeset) { size_t expected = 0; for (auto& row : new_rows) { @@ -587,7 +587,7 @@ void calculate_moves_unsorted(std::vector& new_rows, IndexSet& removed, class SortedMoveCalculator { public: - SortedMoveCalculator(std::vector& new_rows, CollectionChangeIndices& changeset) + SortedMoveCalculator(std::vector& new_rows, CollectionChangeSet& changeset) : m_modified(changeset.modifications) { std::vector old_candidates; diff --git a/src/impl/collection_notifier.hpp b/src/impl/collection_notifier.hpp index a21ff042..eb906d8d 100644 --- a/src/impl/collection_notifier.hpp +++ b/src/impl/collection_notifier.hpp @@ -34,7 +34,7 @@ namespace realm { class Realm; namespace _impl { -class CollectionChangeBuilder : public CollectionChangeIndices { +class CollectionChangeBuilder : public CollectionChangeSet { public: CollectionChangeBuilder(CollectionChangeBuilder const&) = default; CollectionChangeBuilder(CollectionChangeBuilder&&) = default; @@ -170,7 +170,7 @@ private: std::exception_ptr m_error; CollectionChangeBuilder m_accumulated_changes; - CollectionChangeIndices m_changes_to_deliver; + CollectionChangeSet m_changes_to_deliver; // Tables which this collection needs change information for std::vector m_relevant_tables; diff --git a/src/results.cpp b/src/results.cpp index b5048003..1095731a 100644 --- a/src/results.cpp +++ b/src/results.cpp @@ -447,7 +447,7 @@ void Results::prepare_async() NotificationToken Results::async(std::function target) { prepare_async(); - auto wrap = [=](CollectionChangeIndices, std::exception_ptr e) { target(e); }; + auto wrap = [=](CollectionChangeSet, std::exception_ptr e) { target(e); }; return {m_notifier, m_notifier->add_callback(wrap)}; } diff --git a/tests/list.cpp b/tests/list.cpp index 37f2381a..79153e7a 100644 --- a/tests/list.cpp +++ b/tests/list.cpp @@ -60,7 +60,7 @@ TEST_CASE("list") { r->commit_transaction(); SECTION("add_notification_block()") { - CollectionChangeIndices change; + CollectionChangeSet change; List lst(r, *r->config().schema->find("origin"), lv); auto write = [&](auto&& f) { @@ -72,7 +72,7 @@ TEST_CASE("list") { }; auto require_change = [&] { - auto token = lst.add_notification_callback([&](CollectionChangeIndices c, std::exception_ptr err) { + auto token = lst.add_notification_callback([&](CollectionChangeSet c, std::exception_ptr err) { change = c; }); advance_and_notify(*r); @@ -81,7 +81,7 @@ TEST_CASE("list") { auto require_no_change = [&] { bool first = true; - auto token = lst.add_notification_callback([&, first](CollectionChangeIndices c, std::exception_ptr err) mutable { + auto token = lst.add_notification_callback([&, first](CollectionChangeSet c, std::exception_ptr err) mutable { REQUIRE(first); first = false; }); @@ -198,11 +198,11 @@ TEST_CASE("list") { List lists[3]; NotificationToken tokens[3]; - CollectionChangeIndices changes[3]; + CollectionChangeSet changes[3]; for (int i = 0; i < 3; ++i) { lists[i] = get_list(); - tokens[i] = lists[i].add_notification_callback([i, &changes](CollectionChangeIndices c, std::exception_ptr) { + tokens[i] = lists[i].add_notification_callback([i, &changes](CollectionChangeSet c, std::exception_ptr) { changes[i] = std::move(c); }); change_list(); @@ -248,14 +248,14 @@ TEST_CASE("list") { // Add a callback for list1, advance the version, then add a // callback for list2, so that the notifiers added at each source // version have different tables watched for modifications - CollectionChangeIndices changes1, changes2; - auto token1 = lst.add_notification_callback([&](CollectionChangeIndices c, std::exception_ptr) { + CollectionChangeSet changes1, changes2; + auto token1 = lst.add_notification_callback([&](CollectionChangeSet c, std::exception_ptr) { changes1 = std::move(c); }); r->begin_transaction(); r->commit_transaction(); - auto token2 = lst2.add_notification_callback([&](CollectionChangeIndices c, std::exception_ptr) { + auto token2 = lst2.add_notification_callback([&](CollectionChangeSet c, std::exception_ptr) { changes2 = std::move(c); }); @@ -296,8 +296,8 @@ TEST_CASE("list") { Results results = lst.sort({{0}, {false}}); int notification_calls = 0; - CollectionChangeIndices change; - auto token = results.add_notification_callback([&](CollectionChangeIndices c, std::exception_ptr err) { + CollectionChangeSet change; + auto token = results.add_notification_callback([&](CollectionChangeSet c, std::exception_ptr err) { REQUIRE_FALSE(err); change = c; ++notification_calls; @@ -352,8 +352,8 @@ TEST_CASE("list") { Results results = lst.filter(target->where().less(0, 9)); int notification_calls = 0; - CollectionChangeIndices change; - auto token = results.add_notification_callback([&](CollectionChangeIndices c, std::exception_ptr err) { + CollectionChangeSet change; + auto token = results.add_notification_callback([&](CollectionChangeSet c, std::exception_ptr err) { REQUIRE_FALSE(err); change = c; ++notification_calls; diff --git a/tests/results.cpp b/tests/results.cpp index fb039d44..fffff6c8 100644 --- a/tests/results.cpp +++ b/tests/results.cpp @@ -51,8 +51,8 @@ TEST_CASE("Results") { SECTION("unsorted notifications") { int notification_calls = 0; - CollectionChangeIndices change; - auto token = results.add_notification_callback([&](CollectionChangeIndices c, std::exception_ptr err) { + CollectionChangeSet change; + auto token = results.add_notification_callback([&](CollectionChangeSet c, std::exception_ptr err) { REQUIRE_FALSE(err); change = c; ++notification_calls; @@ -107,8 +107,8 @@ TEST_CASE("Results") { SECTION("notifications are delivered when a new callback is added from within a callback") { NotificationToken token2, token3; bool called = false; - token2 = results.add_notification_callback([&](CollectionChangeIndices, std::exception_ptr) { - token3 = results.add_notification_callback([&](CollectionChangeIndices, std::exception_ptr) { + token2 = results.add_notification_callback([&](CollectionChangeSet, std::exception_ptr) { + token3 = results.add_notification_callback([&](CollectionChangeSet, std::exception_ptr) { called = true; }); }); @@ -119,10 +119,10 @@ TEST_CASE("Results") { SECTION("notifications are not delivered when a callback is removed from within a callback") { NotificationToken token2, token3; - token2 = results.add_notification_callback([&](CollectionChangeIndices, std::exception_ptr) { + token2 = results.add_notification_callback([&](CollectionChangeSet, std::exception_ptr) { token3 = {}; }); - token3 = results.add_notification_callback([&](CollectionChangeIndices, std::exception_ptr) { + token3 = results.add_notification_callback([&](CollectionChangeSet, std::exception_ptr) { REQUIRE(false); }); @@ -132,10 +132,10 @@ TEST_CASE("Results") { SECTION("removing the current callback does not stop later ones from being called") { NotificationToken token2, token3; bool called = false; - token2 = results.add_notification_callback([&](CollectionChangeIndices, std::exception_ptr) { + token2 = results.add_notification_callback([&](CollectionChangeSet, std::exception_ptr) { token2 = {}; }); - token3 = results.add_notification_callback([&](CollectionChangeIndices, std::exception_ptr) { + token3 = results.add_notification_callback([&](CollectionChangeSet, std::exception_ptr) { called = true; }); @@ -277,7 +277,7 @@ TEST_CASE("Results") { } SECTION("the first call of a notification can include changes if it previously ran for a different callback") { - auto token2 = results.add_notification_callback([&](CollectionChangeIndices c, std::exception_ptr) { + auto token2 = results.add_notification_callback([&](CollectionChangeSet c, std::exception_ptr) { REQUIRE(!c.empty()); }); @@ -292,8 +292,8 @@ TEST_CASE("Results") { SECTION("sorted notifications") { int notification_calls = 0; - CollectionChangeIndices change; - auto token = results.add_notification_callback([&](CollectionChangeIndices c, std::exception_ptr err) { + CollectionChangeSet change; + auto token = results.add_notification_callback([&](CollectionChangeSet c, std::exception_ptr err) { REQUIRE_FALSE(err); change = c; ++notification_calls; @@ -447,7 +447,7 @@ TEST_CASE("Async Results error handling") { SECTION("error is delivered asynchronously") { bool called = false; - auto token = results.add_notification_callback([&](CollectionChangeIndices, std::exception_ptr err) { + auto token = results.add_notification_callback([&](CollectionChangeSet, std::exception_ptr err) { REQUIRE(err); called = true; }); @@ -461,7 +461,7 @@ TEST_CASE("Async Results error handling") { SECTION("adding another callback does not send the error again") { bool called = false; - auto token = results.add_notification_callback([&](CollectionChangeIndices, std::exception_ptr err) { + auto token = results.add_notification_callback([&](CollectionChangeSet, std::exception_ptr err) { REQUIRE(err); REQUIRE_FALSE(called); called = true; @@ -470,7 +470,7 @@ TEST_CASE("Async Results error handling") { advance_and_notify(*r); bool called2 = false; - auto token2 = results.add_notification_callback([&](CollectionChangeIndices, std::exception_ptr err) { + auto token2 = results.add_notification_callback([&](CollectionChangeSet, std::exception_ptr err) { REQUIRE(err); REQUIRE_FALSE(called2); called2 = true; @@ -484,7 +484,7 @@ TEST_CASE("Async Results error handling") { SECTION("error when opening the executor SG") { SECTION("error is delivered asynchronously") { bool called = false; - auto token = results.add_notification_callback([&](CollectionChangeIndices, std::exception_ptr err) { + auto token = results.add_notification_callback([&](CollectionChangeSet, std::exception_ptr err) { REQUIRE(err); called = true; }); @@ -499,7 +499,7 @@ TEST_CASE("Async Results error handling") { SECTION("adding another callback does not send the error again") { bool called = false; - auto token = results.add_notification_callback([&](CollectionChangeIndices, std::exception_ptr err) { + auto token = results.add_notification_callback([&](CollectionChangeSet, std::exception_ptr err) { REQUIRE(err); REQUIRE_FALSE(called); called = true; @@ -509,7 +509,7 @@ TEST_CASE("Async Results error handling") { advance_and_notify(*r); bool called2 = false; - auto token2 = results.add_notification_callback([&](CollectionChangeIndices, std::exception_ptr err) { + auto token2 = results.add_notification_callback([&](CollectionChangeSet, std::exception_ptr err) { REQUIRE(err); REQUIRE_FALSE(called2); called2 = true; diff --git a/tests/transaction_log_parsing.cpp b/tests/transaction_log_parsing.cpp index 319a08ca..92748568 100644 --- a/tests/transaction_log_parsing.cpp +++ b/tests/transaction_log_parsing.cpp @@ -31,7 +31,7 @@ public: m_initial.push_back(lv->get(i).get_int(0)); } - CollectionChangeIndices finish(size_t ndx) { + CollectionChangeSet finish(size_t ndx) { m_realm->commit_transaction(); _impl::CollectionChangeBuilder c; @@ -61,7 +61,7 @@ private: LinkViewRef m_linkview; std::vector m_initial; - void validate(CollectionChangeIndices const& info) + void validate(CollectionChangeSet const& info) { info.insertions.verify(); info.deletions.verify(); @@ -445,7 +445,7 @@ TEST_CASE("Transaction log parsing") { #define VALIDATE_CHANGES(out) \ for (CaptureHelper helper(config.path, r, lv); helper; out = helper.finish(origin->get_index_in_group())) - CollectionChangeIndices changes; + CollectionChangeSet changes; SECTION("single change type") { SECTION("add single") { VALIDATE_CHANGES(changes) { diff --git a/tests/util/index_helpers.hpp b/tests/util/index_helpers.hpp index 5ca6803c..bb5145b5 100644 --- a/tests/util/index_helpers.hpp +++ b/tests/util/index_helpers.hpp @@ -12,7 +12,7 @@ #define REQUIRE_MOVES(c, ...) do { \ auto actual = (c); \ - std::initializer_list expected = {__VA_ARGS__}; \ + std::initializer_list expected = {__VA_ARGS__}; \ REQUIRE(expected.size() == actual.moves.size()); \ auto begin = actual.moves.begin(); \ for (auto move : expected) { \