From 764535d69269850f90c25f14ced070517e18aaef Mon Sep 17 00:00:00 2001 From: morzhovets Date: Tue, 14 May 2024 21:55:05 +0400 Subject: [PATCH] Improve functions `UpdateRow` --- include/momo/DataTable.h | 12 ++++++++---- test/sources/SimpleDataSampler.cpp | 13 +++++++------ test/sources/SimpleDataTester.cpp | 2 +- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/include/momo/DataTable.h b/include/momo/DataTable.h index 1552daa01..f9afe4561 100644 --- a/include/momo/DataTable.h +++ b/include/momo/DataTable.h @@ -608,7 +608,8 @@ class DataTable } template - RowReference UpdateRow(ConstRowReference rowRef, const Column& column, Item&& newItem) + RowReference UpdateRow(ConstRowReference rowRef, const Column& column, + internal::Identity&& newItem) { TryResult res = pvTryUpdateRow(rowRef, column, std::move(newItem)); if (res.uniqueHashIndex != UniqueHashIndex::empty) @@ -617,7 +618,8 @@ class DataTable } template - RowReference UpdateRow(ConstRowReference rowRef, const Column& column, const Item& newItem) + RowReference UpdateRow(ConstRowReference rowRef, const Column& column, + const internal::Identity& newItem) { TryResult res = pvTryUpdateRow(rowRef, column, newItem); if (res.uniqueHashIndex != UniqueHashIndex::empty) @@ -641,13 +643,15 @@ class DataTable } template - TryResult TryUpdateRow(ConstRowReference rowRef, const Column& column, Item&& newItem) + TryResult TryUpdateRow(ConstRowReference rowRef, const Column& column, + internal::Identity&& newItem) { return pvTryUpdateRow(rowRef, column, std::move(newItem)); } template - TryResult TryUpdateRow(ConstRowReference rowRef, const Column& column, const Item& newItem) + TryResult TryUpdateRow(ConstRowReference rowRef, const Column& column, + const internal::Identity& newItem) { return pvTryUpdateRow(rowRef, column, newItem); } diff --git a/test/sources/SimpleDataSampler.cpp b/test/sources/SimpleDataSampler.cpp index 2c0914ea8..4bf7d2a13 100644 --- a/test/sources/SimpleDataSampler.cpp +++ b/test/sources/SimpleDataSampler.cpp @@ -44,22 +44,23 @@ namespace sample_data1 table.AddUniqueHashIndex(strCol, intCol); table.AddRow(strCol = "b", intCol = 1, dblCol = 0.5); - table.AddRow(intCol = 2, dblCol = 0.5); // strCol = "" + table.AddRow(intCol = 2, dblCol = 2.5); // strCol = "" table.TryAddRow(intCol = 2); // not added because of unique index std::cout << table.GetCount() << std::endl; // 2 - // table[0][dblCol] = 1.5; - table.UpdateRow(table[0], dblCol, 1.5); + // table[0][dblCol] returns `const double&` + std::cout << table[0][dblCol] << std::endl; // 0.5 - // table[1][strCol] = "a"; - table.UpdateRow(table[1], strCol, std::string("a")); + // after adding the row can be modified by function `UpdateRow` + table.UpdateRow(table[0], dblCol, 1.5); + table.UpdateRow(table[1], strCol, "a"); for (auto row : table) std::cout << row[intCol] << " " << row[dblCol] << " " << row[strCol] << std::endl; // 1 1.5 b - // 2 0.5 a + // 2 2.5 a { // select by condition diff --git a/test/sources/SimpleDataTester.cpp b/test/sources/SimpleDataTester.cpp index 986a7a899..6c99dfbba 100644 --- a/test/sources/SimpleDataTester.cpp +++ b/test/sources/SimpleDataTester.cpp @@ -217,7 +217,7 @@ class SimpleDataTester } for (size_t i = 0; i < count; i += 2) - table.UpdateRow(table[i], strCol, std::string("0")); + table.UpdateRow(table[i], strCol, "0"); for (size_t i = 1; i < count; i += 2) {