Rename CollectionChangeIndices to CollectionChangeSet

This commit is contained in:
Thomas Goyne 2016-04-19 14:05:15 -07:00
parent 953e1b15a8
commit c0350b9001
8 changed files with 40 additions and 40 deletions

View File

@ -49,7 +49,7 @@ private:
size_t m_token; size_t m_token;
}; };
struct CollectionChangeIndices { struct CollectionChangeSet {
struct Move { struct Move {
size_t from; size_t from;
size_t to; size_t to;
@ -65,7 +65,7 @@ struct CollectionChangeIndices {
bool empty() const { return deletions.empty() && insertions.empty() && modifications.empty() && moves.empty(); } bool empty() const { return deletions.empty() && insertions.empty() && modifications.empty() && moves.empty(); }
}; };
using CollectionChangeCallback = std::function<void (CollectionChangeIndices, std::exception_ptr)>; using CollectionChangeCallback = std::function<void (CollectionChangeSet, std::exception_ptr)>;
} // namespace realm } // namespace realm
#endif // REALM_COLLECTION_NOTIFICATIONS_HPP #endif // REALM_COLLECTION_NOTIFICATIONS_HPP

View File

@ -557,7 +557,7 @@ struct RowInfo {
size_t shifted_tv_index; size_t shifted_tv_index;
}; };
void calculate_moves_unsorted(std::vector<RowInfo>& new_rows, IndexSet& removed, CollectionChangeIndices& changeset) void calculate_moves_unsorted(std::vector<RowInfo>& new_rows, IndexSet& removed, CollectionChangeSet& changeset)
{ {
size_t expected = 0; size_t expected = 0;
for (auto& row : new_rows) { for (auto& row : new_rows) {
@ -587,7 +587,7 @@ void calculate_moves_unsorted(std::vector<RowInfo>& new_rows, IndexSet& removed,
class SortedMoveCalculator { class SortedMoveCalculator {
public: public:
SortedMoveCalculator(std::vector<RowInfo>& new_rows, CollectionChangeIndices& changeset) SortedMoveCalculator(std::vector<RowInfo>& new_rows, CollectionChangeSet& changeset)
: m_modified(changeset.modifications) : m_modified(changeset.modifications)
{ {
std::vector<Row> old_candidates; std::vector<Row> old_candidates;

View File

@ -34,7 +34,7 @@ namespace realm {
class Realm; class Realm;
namespace _impl { namespace _impl {
class CollectionChangeBuilder : public CollectionChangeIndices { class CollectionChangeBuilder : public CollectionChangeSet {
public: public:
CollectionChangeBuilder(CollectionChangeBuilder const&) = default; CollectionChangeBuilder(CollectionChangeBuilder const&) = default;
CollectionChangeBuilder(CollectionChangeBuilder&&) = default; CollectionChangeBuilder(CollectionChangeBuilder&&) = default;
@ -170,7 +170,7 @@ private:
std::exception_ptr m_error; std::exception_ptr m_error;
CollectionChangeBuilder m_accumulated_changes; CollectionChangeBuilder m_accumulated_changes;
CollectionChangeIndices m_changes_to_deliver; CollectionChangeSet m_changes_to_deliver;
// Tables which this collection needs change information for // Tables which this collection needs change information for
std::vector<size_t> m_relevant_tables; std::vector<size_t> m_relevant_tables;

View File

@ -447,7 +447,7 @@ void Results::prepare_async()
NotificationToken Results::async(std::function<void (std::exception_ptr)> target) NotificationToken Results::async(std::function<void (std::exception_ptr)> target)
{ {
prepare_async(); 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)}; return {m_notifier, m_notifier->add_callback(wrap)};
} }

View File

@ -60,7 +60,7 @@ TEST_CASE("list") {
r->commit_transaction(); r->commit_transaction();
SECTION("add_notification_block()") { SECTION("add_notification_block()") {
CollectionChangeIndices change; CollectionChangeSet change;
List lst(r, *r->config().schema->find("origin"), lv); List lst(r, *r->config().schema->find("origin"), lv);
auto write = [&](auto&& f) { auto write = [&](auto&& f) {
@ -72,7 +72,7 @@ TEST_CASE("list") {
}; };
auto require_change = [&] { 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; change = c;
}); });
advance_and_notify(*r); advance_and_notify(*r);
@ -81,7 +81,7 @@ TEST_CASE("list") {
auto require_no_change = [&] { auto require_no_change = [&] {
bool first = true; 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); REQUIRE(first);
first = false; first = false;
}); });
@ -198,11 +198,11 @@ TEST_CASE("list") {
List lists[3]; List lists[3];
NotificationToken tokens[3]; NotificationToken tokens[3];
CollectionChangeIndices changes[3]; CollectionChangeSet changes[3];
for (int i = 0; i < 3; ++i) { for (int i = 0; i < 3; ++i) {
lists[i] = get_list(); 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); changes[i] = std::move(c);
}); });
change_list(); change_list();
@ -248,14 +248,14 @@ TEST_CASE("list") {
// Add a callback for list1, advance the version, then add a // Add a callback for list1, advance the version, then add a
// callback for list2, so that the notifiers added at each source // callback for list2, so that the notifiers added at each source
// version have different tables watched for modifications // version have different tables watched for modifications
CollectionChangeIndices changes1, changes2; CollectionChangeSet changes1, changes2;
auto token1 = lst.add_notification_callback([&](CollectionChangeIndices c, std::exception_ptr) { auto token1 = lst.add_notification_callback([&](CollectionChangeSet c, std::exception_ptr) {
changes1 = std::move(c); changes1 = std::move(c);
}); });
r->begin_transaction(); r->commit_transaction(); 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); changes2 = std::move(c);
}); });
@ -296,8 +296,8 @@ TEST_CASE("list") {
Results results = lst.sort({{0}, {false}}); Results results = lst.sort({{0}, {false}});
int notification_calls = 0; int notification_calls = 0;
CollectionChangeIndices change; CollectionChangeSet change;
auto token = results.add_notification_callback([&](CollectionChangeIndices c, std::exception_ptr err) { auto token = results.add_notification_callback([&](CollectionChangeSet c, std::exception_ptr err) {
REQUIRE_FALSE(err); REQUIRE_FALSE(err);
change = c; change = c;
++notification_calls; ++notification_calls;
@ -352,8 +352,8 @@ TEST_CASE("list") {
Results results = lst.filter(target->where().less(0, 9)); Results results = lst.filter(target->where().less(0, 9));
int notification_calls = 0; int notification_calls = 0;
CollectionChangeIndices change; CollectionChangeSet change;
auto token = results.add_notification_callback([&](CollectionChangeIndices c, std::exception_ptr err) { auto token = results.add_notification_callback([&](CollectionChangeSet c, std::exception_ptr err) {
REQUIRE_FALSE(err); REQUIRE_FALSE(err);
change = c; change = c;
++notification_calls; ++notification_calls;

View File

@ -51,8 +51,8 @@ TEST_CASE("Results") {
SECTION("unsorted notifications") { SECTION("unsorted notifications") {
int notification_calls = 0; int notification_calls = 0;
CollectionChangeIndices change; CollectionChangeSet change;
auto token = results.add_notification_callback([&](CollectionChangeIndices c, std::exception_ptr err) { auto token = results.add_notification_callback([&](CollectionChangeSet c, std::exception_ptr err) {
REQUIRE_FALSE(err); REQUIRE_FALSE(err);
change = c; change = c;
++notification_calls; ++notification_calls;
@ -107,8 +107,8 @@ TEST_CASE("Results") {
SECTION("notifications are delivered when a new callback is added from within a callback") { SECTION("notifications are delivered when a new callback is added from within a callback") {
NotificationToken token2, token3; NotificationToken token2, token3;
bool called = false; bool called = false;
token2 = results.add_notification_callback([&](CollectionChangeIndices, std::exception_ptr) { token2 = results.add_notification_callback([&](CollectionChangeSet, std::exception_ptr) {
token3 = results.add_notification_callback([&](CollectionChangeIndices, std::exception_ptr) { token3 = results.add_notification_callback([&](CollectionChangeSet, std::exception_ptr) {
called = true; called = true;
}); });
}); });
@ -119,10 +119,10 @@ TEST_CASE("Results") {
SECTION("notifications are not delivered when a callback is removed from within a callback") { SECTION("notifications are not delivered when a callback is removed from within a callback") {
NotificationToken token2, token3; NotificationToken token2, token3;
token2 = results.add_notification_callback([&](CollectionChangeIndices, std::exception_ptr) { token2 = results.add_notification_callback([&](CollectionChangeSet, std::exception_ptr) {
token3 = {}; token3 = {};
}); });
token3 = results.add_notification_callback([&](CollectionChangeIndices, std::exception_ptr) { token3 = results.add_notification_callback([&](CollectionChangeSet, std::exception_ptr) {
REQUIRE(false); REQUIRE(false);
}); });
@ -132,10 +132,10 @@ TEST_CASE("Results") {
SECTION("removing the current callback does not stop later ones from being called") { SECTION("removing the current callback does not stop later ones from being called") {
NotificationToken token2, token3; NotificationToken token2, token3;
bool called = false; bool called = false;
token2 = results.add_notification_callback([&](CollectionChangeIndices, std::exception_ptr) { token2 = results.add_notification_callback([&](CollectionChangeSet, std::exception_ptr) {
token2 = {}; token2 = {};
}); });
token3 = results.add_notification_callback([&](CollectionChangeIndices, std::exception_ptr) { token3 = results.add_notification_callback([&](CollectionChangeSet, std::exception_ptr) {
called = true; 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") { 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()); REQUIRE(!c.empty());
}); });
@ -292,8 +292,8 @@ TEST_CASE("Results") {
SECTION("sorted notifications") { SECTION("sorted notifications") {
int notification_calls = 0; int notification_calls = 0;
CollectionChangeIndices change; CollectionChangeSet change;
auto token = results.add_notification_callback([&](CollectionChangeIndices c, std::exception_ptr err) { auto token = results.add_notification_callback([&](CollectionChangeSet c, std::exception_ptr err) {
REQUIRE_FALSE(err); REQUIRE_FALSE(err);
change = c; change = c;
++notification_calls; ++notification_calls;
@ -447,7 +447,7 @@ TEST_CASE("Async Results error handling") {
SECTION("error is delivered asynchronously") { SECTION("error is delivered asynchronously") {
bool called = false; 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(err);
called = true; called = true;
}); });
@ -461,7 +461,7 @@ TEST_CASE("Async Results error handling") {
SECTION("adding another callback does not send the error again") { SECTION("adding another callback does not send the error again") {
bool called = false; 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(err);
REQUIRE_FALSE(called); REQUIRE_FALSE(called);
called = true; called = true;
@ -470,7 +470,7 @@ TEST_CASE("Async Results error handling") {
advance_and_notify(*r); advance_and_notify(*r);
bool called2 = false; 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(err);
REQUIRE_FALSE(called2); REQUIRE_FALSE(called2);
called2 = true; called2 = true;
@ -484,7 +484,7 @@ TEST_CASE("Async Results error handling") {
SECTION("error when opening the executor SG") { SECTION("error when opening the executor SG") {
SECTION("error is delivered asynchronously") { SECTION("error is delivered asynchronously") {
bool called = false; 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(err);
called = true; called = true;
}); });
@ -499,7 +499,7 @@ TEST_CASE("Async Results error handling") {
SECTION("adding another callback does not send the error again") { SECTION("adding another callback does not send the error again") {
bool called = false; 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(err);
REQUIRE_FALSE(called); REQUIRE_FALSE(called);
called = true; called = true;
@ -509,7 +509,7 @@ TEST_CASE("Async Results error handling") {
advance_and_notify(*r); advance_and_notify(*r);
bool called2 = false; 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(err);
REQUIRE_FALSE(called2); REQUIRE_FALSE(called2);
called2 = true; called2 = true;

View File

@ -31,7 +31,7 @@ public:
m_initial.push_back(lv->get(i).get_int(0)); m_initial.push_back(lv->get(i).get_int(0));
} }
CollectionChangeIndices finish(size_t ndx) { CollectionChangeSet finish(size_t ndx) {
m_realm->commit_transaction(); m_realm->commit_transaction();
_impl::CollectionChangeBuilder c; _impl::CollectionChangeBuilder c;
@ -61,7 +61,7 @@ private:
LinkViewRef m_linkview; LinkViewRef m_linkview;
std::vector<int> m_initial; std::vector<int> m_initial;
void validate(CollectionChangeIndices const& info) void validate(CollectionChangeSet const& info)
{ {
info.insertions.verify(); info.insertions.verify();
info.deletions.verify(); info.deletions.verify();
@ -445,7 +445,7 @@ TEST_CASE("Transaction log parsing") {
#define VALIDATE_CHANGES(out) \ #define VALIDATE_CHANGES(out) \
for (CaptureHelper helper(config.path, r, lv); helper; out = helper.finish(origin->get_index_in_group())) 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("single change type") {
SECTION("add single") { SECTION("add single") {
VALIDATE_CHANGES(changes) { VALIDATE_CHANGES(changes) {

View File

@ -12,7 +12,7 @@
#define REQUIRE_MOVES(c, ...) do { \ #define REQUIRE_MOVES(c, ...) do { \
auto actual = (c); \ auto actual = (c); \
std::initializer_list<CollectionChangeIndices::Move> expected = {__VA_ARGS__}; \ std::initializer_list<CollectionChangeSet::Move> expected = {__VA_ARGS__}; \
REQUIRE(expected.size() == actual.moves.size()); \ REQUIRE(expected.size() == actual.moves.size()); \
auto begin = actual.moves.begin(); \ auto begin = actual.moves.begin(); \
for (auto move : expected) { \ for (auto move : expected) { \