From f229c0a6071d8148a15f12ea86ff3c9c9d3739f5 Mon Sep 17 00:00:00 2001 From: Khomenko Denys Date: Tue, 18 Nov 2025 14:11:59 +0200 Subject: [PATCH] Replace boost with olp::porting any_cast Replace occurences of the boost::any_cast with olp::porting::any_cast Relates-To: NLAM-157 Signed-off-by: Khomenko Denys --- olp-cpp-sdk-core/src/cache/InMemoryCache.cpp | 2 +- .../client/repository/ApiCacheRepository.cpp | 2 +- .../tests/cache/DefaultCacheImplTest.cpp | 10 ++++--- .../tests/cache/DefaultCacheTest.cpp | 26 ++++++++++++------- .../tests/cache/InMemoryCacheTest.cpp | 16 ++++++------ .../src/repositories/ApiCacheRepository.cpp | 2 +- .../repositories/CatalogCacheRepository.cpp | 4 +-- .../PartitionsCacheRepository.cpp | 2 +- .../src/ApiClientLookup.cpp | 2 +- .../src/CatalogSettings.cpp | 3 ++- .../src/StreamLayerClientImpl.cpp | 8 +++--- 11 files changed, 43 insertions(+), 34 deletions(-) diff --git a/olp-cpp-sdk-core/src/cache/InMemoryCache.cpp b/olp-cpp-sdk-core/src/cache/InMemoryCache.cpp index f67edca1f..91409221e 100644 --- a/olp-cpp-sdk-core/src/cache/InMemoryCache.cpp +++ b/olp-cpp-sdk-core/src/cache/InMemoryCache.cpp @@ -65,7 +65,7 @@ bool InMemoryCache::Put(const std::string& key, const boost::any& item, return ret.second; } -boost::any InMemoryCache::Get(const std::string& key) { +olp::porting::any InMemoryCache::Get(const std::string& key) { std::lock_guard lock{mutex_}; auto it = item_tuples_.Find(key); if (it != item_tuples_.end()) { diff --git a/olp-cpp-sdk-core/src/client/repository/ApiCacheRepository.cpp b/olp-cpp-sdk-core/src/client/repository/ApiCacheRepository.cpp index a978f122c..8b1c93393 100644 --- a/olp-cpp-sdk-core/src/client/repository/ApiCacheRepository.cpp +++ b/olp-cpp-sdk-core/src/client/repository/ApiCacheRepository.cpp @@ -55,7 +55,7 @@ porting::optional ApiCacheRepository::Get( return porting::none; } - return boost::any_cast(url); + return olp::porting::any_cast(url); } } // namespace repository diff --git a/olp-cpp-sdk-core/tests/cache/DefaultCacheImplTest.cpp b/olp-cpp-sdk-core/tests/cache/DefaultCacheImplTest.cpp index 3b1598ec0..6fed681f6 100644 --- a/olp-cpp-sdk-core/tests/cache/DefaultCacheImplTest.cpp +++ b/olp-cpp-sdk-core/tests/cache/DefaultCacheImplTest.cpp @@ -431,7 +431,7 @@ TEST_F(DefaultCacheImplTest, MutableCacheExpired) { ASSERT_NE(value.get(), nullptr); ASSERT_EQ(value2.type(), typeid(std::string)); - auto str = boost::any_cast(value2); + auto str = olp::porting::any_cast(value2); EXPECT_EQ(str, data_string); std::this_thread::sleep_for(std::chrono::seconds(3)); @@ -473,7 +473,7 @@ TEST_F(DefaultCacheImplTest, ProtectedCacheExpired) { EXPECT_FALSE(value.get() == nullptr); EXPECT_EQ(value2.type(), typeid(std::string)); - auto str = boost::any_cast(value2); + auto str = olp::porting::any_cast(value2); EXPECT_EQ(str, data_string); std::this_thread::sleep_for(std::chrono::seconds(3)); @@ -892,7 +892,8 @@ TEST_F(DefaultCacheImplTest, ProtectTest) { auto key2_data_read = cache.Get(key2, [](const std::string& data) { return data; }); ASSERT_FALSE(key2_data_read.empty()); - ASSERT_EQ(key2_data_string, boost::any_cast(key2_data_read)); + ASSERT_EQ(key2_data_string, + olp::porting::any_cast(key2_data_read)); } { SCOPED_TRACE("Check if key still protected exist after closing"); @@ -901,7 +902,8 @@ TEST_F(DefaultCacheImplTest, ProtectTest) { auto key2_data_read = cache.Get(key2, [](const std::string& data) { return data; }); ASSERT_FALSE(key2_data_read.empty()); - ASSERT_EQ(key2_data_string, boost::any_cast(key2_data_read)); + ASSERT_EQ(key2_data_string, + olp::porting::any_cast(key2_data_read)); ASSERT_TRUE(cache.IsProtected(key2)); ASSERT_TRUE(cache.IsProtected(key3)); // key which do not exist diff --git a/olp-cpp-sdk-core/tests/cache/DefaultCacheTest.cpp b/olp-cpp-sdk-core/tests/cache/DefaultCacheTest.cpp index a793e7f06..17347f4dc 100644 --- a/olp-cpp-sdk-core/tests/cache/DefaultCacheTest.cpp +++ b/olp-cpp-sdk-core/tests/cache/DefaultCacheTest.cpp @@ -55,7 +55,7 @@ void BasicCacheTestWithSettings(const olp::cache::CacheSettings& settings) { cache.Get("key", [](const std::string& data) { return data; }); EXPECT_FALSE(data_read.empty()); - EXPECT_EQ(data_string, boost::any_cast(data_read)); + EXPECT_EQ(data_string, olp::porting::any_cast(data_read)); } { @@ -218,7 +218,7 @@ TEST(DefaultCacheTest, BasicTest) { auto key1DataRead = cache.Get("key1", [](const std::string& data) { return data; }); ASSERT_FALSE(key1DataRead.empty()); - ASSERT_EQ(key1DataString, boost::any_cast(key1DataRead)); + ASSERT_EQ(key1DataString, olp::porting::any_cast(key1DataRead)); ASSERT_TRUE(cache.Clear()); } @@ -232,7 +232,7 @@ TEST(DefaultCacheTest, BasicInMemTest) { auto key1DataRead = cache.Get("key1", [](const std::string& data) { return data; }); ASSERT_FALSE(key1DataRead.empty()); - ASSERT_EQ(key1DataString, boost::any_cast(key1DataRead)); + ASSERT_EQ(key1DataString, olp::porting::any_cast(key1DataRead)); ASSERT_TRUE(cache.Clear()); } @@ -250,7 +250,8 @@ TEST(DefaultCacheTest, MemSizeTest) { auto key1DataRead = cache.Get(key1, [](const std::string& data) { return data; }); ASSERT_FALSE(key1DataRead.empty()); - ASSERT_EQ(key1DataString, boost::any_cast(key1DataRead)); + ASSERT_EQ(key1DataString, + olp::porting::any_cast(key1DataRead)); } std::string key2{"key2"}; @@ -261,7 +262,8 @@ TEST(DefaultCacheTest, MemSizeTest) { auto key2DataRead = cache.Get(key2, [](const std::string& data) { return data; }); ASSERT_FALSE(key2DataRead.empty()); - ASSERT_EQ(key2DataString, boost::any_cast(key2DataRead)); + ASSERT_EQ(key2DataString, + olp::porting::any_cast(key2DataRead)); auto key1DataRead = cache.Get(key1, [](const std::string& data) { return data; }); @@ -282,7 +284,7 @@ TEST(DefaultCacheTest, BasicDiskTest) { auto key1DataRead = cache.Get("key1", [](const std::string& data) { return data; }); ASSERT_FALSE(key1DataRead.empty()); - ASSERT_EQ(key1DataString, boost::any_cast(key1DataRead)); + ASSERT_EQ(key1DataString, olp::porting::any_cast(key1DataRead)); ASSERT_TRUE(cache.Clear()); } @@ -367,7 +369,8 @@ TEST(DefaultCacheTest, ProtectedCacheTest) { auto key1_data_read = cache.Get(key1, [](const std::string& data) { return data; }); ASSERT_FALSE(key1_data_read.empty()); - ASSERT_EQ(key1_data_string, boost::any_cast(key1_data_read)); + ASSERT_EQ(key1_data_string, + olp::porting::any_cast(key1_data_read)); } { SCOPED_TRACE("Get from protected - missing key"); @@ -402,7 +405,8 @@ TEST(DefaultCacheTest, ProtectedCacheTest) { auto key2_data_read = cache.Get(key2, [](const std::string& data) { return data; }); ASSERT_FALSE(key2_data_read.empty()); - ASSERT_EQ(key2_data_string, boost::any_cast(key2_data_read)); + ASSERT_EQ(key2_data_string, + olp::porting::any_cast(key2_data_read)); ASSERT_TRUE(cache.Clear()); } { @@ -417,7 +421,8 @@ TEST(DefaultCacheTest, ProtectedCacheTest) { auto key1_data_read = cache.Get(key1, [](const std::string& data) { return data; }); ASSERT_FALSE(key1_data_read.empty()); - ASSERT_EQ(key1_data_string, boost::any_cast(key1_data_read)); + ASSERT_EQ(key1_data_string, + olp::porting::any_cast(key1_data_read)); } { SCOPED_TRACE("Put to protected - blocked"); @@ -440,7 +445,8 @@ TEST(DefaultCacheTest, ProtectedCacheTest) { auto key1_data_read = cache.Get(key1, [](const std::string& data) { return data; }); ASSERT_FALSE(key1_data_read.empty()); - ASSERT_EQ(key1_data_string, boost::any_cast(key1_data_read)); + ASSERT_EQ(key1_data_string, + olp::porting::any_cast(key1_data_read)); } { diff --git a/olp-cpp-sdk-core/tests/cache/InMemoryCacheTest.cpp b/olp-cpp-sdk-core/tests/cache/InMemoryCacheTest.cpp index d18b720ab..8aab35b73 100644 --- a/olp-cpp-sdk-core/tests/cache/InMemoryCacheTest.cpp +++ b/olp-cpp-sdk-core/tests/cache/InMemoryCacheTest.cpp @@ -62,11 +62,11 @@ TEST(InMemoryCacheTest, NoLimit) { auto i0 = cache.Get("key0"); ASSERT_FALSE(i0.empty()); - ASSERT_EQ("value0", boost::any_cast(i0)); + ASSERT_EQ("value0", olp::porting::any_cast(i0)); auto i9 = cache.Get("key9"); ASSERT_FALSE(i9.empty()); - ASSERT_EQ("value9", boost::any_cast(i9)); + ASSERT_EQ("value9", olp::porting::any_cast(i9)); ASSERT_TRUE(cache.Get("key10").empty()); } @@ -127,14 +127,14 @@ TEST(InMemoryCacheTest, PutOverwritesPrevious) { ASSERT_EQ(1u, cache.Size()); auto value = cache.Get(key); ASSERT_FALSE(value.empty()); - ASSERT_EQ(orig_value, boost::any_cast(value)); + ASSERT_EQ(orig_value, olp::porting::any_cast(value)); std::string updated_value("updatedValue"); cache.Put(key, updated_value); value = cache.Get(key); ASSERT_FALSE(value.empty()); - ASSERT_EQ(updated_value, boost::any_cast(value)); + ASSERT_EQ(updated_value, olp::porting::any_cast(value)); } TEST(InMemoryCacheTest, InsertOverLimit) { @@ -145,7 +145,7 @@ TEST(InMemoryCacheTest, InsertOverLimit) { ASSERT_TRUE(cache.Get("key0").empty()); auto i1 = cache.Get("key1"); ASSERT_FALSE(i1.empty()); - ASSERT_EQ("value1", boost::any_cast(i1)); + ASSERT_EQ("value1", olp::porting::any_cast(i1)); } TEST(InMemoryCacheTest, GetReorders) { @@ -155,14 +155,14 @@ TEST(InMemoryCacheTest, GetReorders) { auto i0 = cache.Get("key0"); ASSERT_FALSE(i0.empty()); - ASSERT_EQ("value0", boost::any_cast(i0)); + ASSERT_EQ("value0", olp::porting::any_cast(i0)); Populate(cache, 1, 2); ASSERT_TRUE(cache.Get("key1").empty()); auto i2 = cache.Get("key2"); ASSERT_FALSE(i2.empty()); - ASSERT_EQ("value2", boost::any_cast(i2)); + ASSERT_EQ("value2", olp::porting::any_cast(i2)); } TEST(InMemoryCacheTest, GetSingleExpired) { @@ -370,7 +370,7 @@ TEST(InMemoryCacheTest, ClassBasedCustomCost) { auto model_item = std::get<2>(tuple); std::size_t result(1u); - if (auto data_container = boost::any_cast(model_item)) { + if (auto data_container = olp::porting::any_cast(model_item)) { auto data_size = data_container->size(); result = (data_size > 0) ? data_size : result; } diff --git a/olp-cpp-sdk-dataservice-read/src/repositories/ApiCacheRepository.cpp b/olp-cpp-sdk-dataservice-read/src/repositories/ApiCacheRepository.cpp index 3291b4017..12fd59f69 100644 --- a/olp-cpp-sdk-dataservice-read/src/repositories/ApiCacheRepository.cpp +++ b/olp-cpp-sdk-dataservice-read/src/repositories/ApiCacheRepository.cpp @@ -57,7 +57,7 @@ porting::optional ApiCacheRepository::Get( return olp::porting::none; } - return boost::any_cast(url); + return olp::porting::any_cast(url); } } // namespace repository diff --git a/olp-cpp-sdk-dataservice-read/src/repositories/CatalogCacheRepository.cpp b/olp-cpp-sdk-dataservice-read/src/repositories/CatalogCacheRepository.cpp index 3e9844c40..9ac0fb72a 100644 --- a/olp-cpp-sdk-dataservice-read/src/repositories/CatalogCacheRepository.cpp +++ b/olp-cpp-sdk-dataservice-read/src/repositories/CatalogCacheRepository.cpp @@ -77,7 +77,7 @@ porting::optional CatalogCacheRepository::Get() { return olp::porting::none; } - return boost::any_cast(cached_catalog); + return olp::porting::any_cast(cached_catalog); } bool CatalogCacheRepository::PutVersion(const model::VersionResponse& version) { @@ -102,7 +102,7 @@ porting::optional CatalogCacheRepository::GetVersion() { if (cached_version.empty()) { return olp::porting::none; } - return boost::any_cast(cached_version); + return olp::porting::any_cast(cached_version); } bool CatalogCacheRepository::Clear() { diff --git a/olp-cpp-sdk-dataservice-read/src/repositories/PartitionsCacheRepository.cpp b/olp-cpp-sdk-dataservice-read/src/repositories/PartitionsCacheRepository.cpp index 46b5f89a1..55701ce85 100644 --- a/olp-cpp-sdk-dataservice-read/src/repositories/PartitionsCacheRepository.cpp +++ b/olp-cpp-sdk-dataservice-read/src/repositories/PartitionsCacheRepository.cpp @@ -190,7 +190,7 @@ porting::optional PartitionsCacheRepository::Get( } return std::move( - boost::any_cast(cached_layer_versions)); + olp::porting::any_cast(cached_layer_versions)); } client::ApiNoResponse PartitionsCacheRepository::Put( diff --git a/olp-cpp-sdk-dataservice-write/src/ApiClientLookup.cpp b/olp-cpp-sdk-dataservice-write/src/ApiClientLookup.cpp index d31c1c7f1..64ea2f788 100644 --- a/olp-cpp-sdk-dataservice-write/src/ApiClientLookup.cpp +++ b/olp-cpp-sdk-dataservice-write/src/ApiClientLookup.cpp @@ -149,7 +149,7 @@ ApiClientLookup::ApiClientResponse ApiClientLookup::LookupApiClient( auto url = cache->Get(cache_key, [](const std::string& value) { return value; }); if (!url.empty()) { - auto base_url = boost::any_cast(url); + auto base_url = olp::porting::any_cast(url); OLP_SDK_LOG_INFO_F(kLogTag, "LookupApiClient(%s, %s) -> from cache", service.c_str(), service_version.c_str()); client::OlpClient client(settings, base_url); diff --git a/olp-cpp-sdk-dataservice-write/src/CatalogSettings.cpp b/olp-cpp-sdk-dataservice-write/src/CatalogSettings.cpp index ff77b7d76..5d3476263 100644 --- a/olp-cpp-sdk-dataservice-write/src/CatalogSettings.cpp +++ b/olp-cpp-sdk-dataservice-write/src/CatalogSettings.cpp @@ -112,7 +112,8 @@ CatalogSettings::LayerSettingsResult CatalogSettings::GetLayerSettings( .str()); } - const auto& catalog = boost::any_cast(cached_catalog); + const auto& catalog = + olp::porting::any_cast(cached_catalog); return GetLayerSettingsFromModel(catalog, layer_id); } diff --git a/olp-cpp-sdk-dataservice-write/src/StreamLayerClientImpl.cpp b/olp-cpp-sdk-dataservice-write/src/StreamLayerClientImpl.cpp index e24908dc8..f88c938fc 100644 --- a/olp-cpp-sdk-dataservice-write/src/StreamLayerClientImpl.cpp +++ b/olp-cpp-sdk-dataservice-write/src/StreamLayerClientImpl.cpp @@ -94,7 +94,7 @@ size_t StreamLayerClientImpl::QueueSize() const { cache_->Get(GetUuidListKey(), [](const std::string& s) { return s; }); std::string uuid_list = ""; if (!uuid_list_any.empty()) { - uuid_list = boost::any_cast(uuid_list_any); + uuid_list = olp::porting::any_cast(uuid_list_any); return std::count(uuid_list.cbegin(), uuid_list.cend(), ','); } @@ -135,7 +135,7 @@ porting::optional StreamLayerClientImpl::Queue( cache_->Get(GetUuidListKey(), [](const std::string& s) { return s; }); std::string uuid_list = ""; if (!uuid_list_any.empty()) { - uuid_list = boost::any_cast(uuid_list_any); + uuid_list = olp::porting::any_cast(uuid_list_any); } uuid_list += publish_data_key + ","; @@ -158,7 +158,7 @@ StreamLayerClientImpl::PopFromQueue() { return olp::porting::none; } - auto uuid_list = boost::any_cast(uuid_list_any); + auto uuid_list = olp::porting::any_cast(uuid_list_any); auto pos = uuid_list.find(","); if (pos == std::string::npos) { @@ -182,7 +182,7 @@ StreamLayerClientImpl::PopFromQueue() { return olp::porting::none; } - return boost::any_cast(publish_data_any); + return olp::porting::any_cast(publish_data_any); } olp::client::CancellableFuture