Skip to content

Commit f229c0a

Browse files
committed
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 <[email protected]>
1 parent a6e85ca commit f229c0a

File tree

11 files changed

+43
-34
lines changed

11 files changed

+43
-34
lines changed

olp-cpp-sdk-core/src/cache/InMemoryCache.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ bool InMemoryCache::Put(const std::string& key, const boost::any& item,
6565
return ret.second;
6666
}
6767

68-
boost::any InMemoryCache::Get(const std::string& key) {
68+
olp::porting::any InMemoryCache::Get(const std::string& key) {
6969
std::lock_guard<std::mutex> lock{mutex_};
7070
auto it = item_tuples_.Find(key);
7171
if (it != item_tuples_.end()) {

olp-cpp-sdk-core/src/client/repository/ApiCacheRepository.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ porting::optional<std::string> ApiCacheRepository::Get(
5555
return porting::none;
5656
}
5757

58-
return boost::any_cast<std::string>(url);
58+
return olp::porting::any_cast<std::string>(url);
5959
}
6060

6161
} // namespace repository

olp-cpp-sdk-core/tests/cache/DefaultCacheImplTest.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ TEST_F(DefaultCacheImplTest, MutableCacheExpired) {
431431

432432
ASSERT_NE(value.get(), nullptr);
433433
ASSERT_EQ(value2.type(), typeid(std::string));
434-
auto str = boost::any_cast<std::string>(value2);
434+
auto str = olp::porting::any_cast<std::string>(value2);
435435
EXPECT_EQ(str, data_string);
436436

437437
std::this_thread::sleep_for(std::chrono::seconds(3));
@@ -473,7 +473,7 @@ TEST_F(DefaultCacheImplTest, ProtectedCacheExpired) {
473473

474474
EXPECT_FALSE(value.get() == nullptr);
475475
EXPECT_EQ(value2.type(), typeid(std::string));
476-
auto str = boost::any_cast<std::string>(value2);
476+
auto str = olp::porting::any_cast<std::string>(value2);
477477
EXPECT_EQ(str, data_string);
478478

479479
std::this_thread::sleep_for(std::chrono::seconds(3));
@@ -892,7 +892,8 @@ TEST_F(DefaultCacheImplTest, ProtectTest) {
892892
auto key2_data_read =
893893
cache.Get(key2, [](const std::string& data) { return data; });
894894
ASSERT_FALSE(key2_data_read.empty());
895-
ASSERT_EQ(key2_data_string, boost::any_cast<std::string>(key2_data_read));
895+
ASSERT_EQ(key2_data_string,
896+
olp::porting::any_cast<std::string>(key2_data_read));
896897
}
897898
{
898899
SCOPED_TRACE("Check if key still protected exist after closing");
@@ -901,7 +902,8 @@ TEST_F(DefaultCacheImplTest, ProtectTest) {
901902
auto key2_data_read =
902903
cache.Get(key2, [](const std::string& data) { return data; });
903904
ASSERT_FALSE(key2_data_read.empty());
904-
ASSERT_EQ(key2_data_string, boost::any_cast<std::string>(key2_data_read));
905+
ASSERT_EQ(key2_data_string,
906+
olp::porting::any_cast<std::string>(key2_data_read));
905907
ASSERT_TRUE(cache.IsProtected(key2));
906908
ASSERT_TRUE(cache.IsProtected(key3));
907909
// key which do not exist

olp-cpp-sdk-core/tests/cache/DefaultCacheTest.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ void BasicCacheTestWithSettings(const olp::cache::CacheSettings& settings) {
5555
cache.Get("key", [](const std::string& data) { return data; });
5656

5757
EXPECT_FALSE(data_read.empty());
58-
EXPECT_EQ(data_string, boost::any_cast<std::string>(data_read));
58+
EXPECT_EQ(data_string, olp::porting::any_cast<std::string>(data_read));
5959
}
6060

6161
{
@@ -218,7 +218,7 @@ TEST(DefaultCacheTest, BasicTest) {
218218
auto key1DataRead =
219219
cache.Get("key1", [](const std::string& data) { return data; });
220220
ASSERT_FALSE(key1DataRead.empty());
221-
ASSERT_EQ(key1DataString, boost::any_cast<std::string>(key1DataRead));
221+
ASSERT_EQ(key1DataString, olp::porting::any_cast<std::string>(key1DataRead));
222222
ASSERT_TRUE(cache.Clear());
223223
}
224224

@@ -232,7 +232,7 @@ TEST(DefaultCacheTest, BasicInMemTest) {
232232
auto key1DataRead =
233233
cache.Get("key1", [](const std::string& data) { return data; });
234234
ASSERT_FALSE(key1DataRead.empty());
235-
ASSERT_EQ(key1DataString, boost::any_cast<std::string>(key1DataRead));
235+
ASSERT_EQ(key1DataString, olp::porting::any_cast<std::string>(key1DataRead));
236236
ASSERT_TRUE(cache.Clear());
237237
}
238238

@@ -250,7 +250,8 @@ TEST(DefaultCacheTest, MemSizeTest) {
250250
auto key1DataRead =
251251
cache.Get(key1, [](const std::string& data) { return data; });
252252
ASSERT_FALSE(key1DataRead.empty());
253-
ASSERT_EQ(key1DataString, boost::any_cast<std::string>(key1DataRead));
253+
ASSERT_EQ(key1DataString,
254+
olp::porting::any_cast<std::string>(key1DataRead));
254255
}
255256

256257
std::string key2{"key2"};
@@ -261,7 +262,8 @@ TEST(DefaultCacheTest, MemSizeTest) {
261262
auto key2DataRead =
262263
cache.Get(key2, [](const std::string& data) { return data; });
263264
ASSERT_FALSE(key2DataRead.empty());
264-
ASSERT_EQ(key2DataString, boost::any_cast<std::string>(key2DataRead));
265+
ASSERT_EQ(key2DataString,
266+
olp::porting::any_cast<std::string>(key2DataRead));
265267

266268
auto key1DataRead =
267269
cache.Get(key1, [](const std::string& data) { return data; });
@@ -282,7 +284,7 @@ TEST(DefaultCacheTest, BasicDiskTest) {
282284
auto key1DataRead =
283285
cache.Get("key1", [](const std::string& data) { return data; });
284286
ASSERT_FALSE(key1DataRead.empty());
285-
ASSERT_EQ(key1DataString, boost::any_cast<std::string>(key1DataRead));
287+
ASSERT_EQ(key1DataString, olp::porting::any_cast<std::string>(key1DataRead));
286288
ASSERT_TRUE(cache.Clear());
287289
}
288290

@@ -367,7 +369,8 @@ TEST(DefaultCacheTest, ProtectedCacheTest) {
367369
auto key1_data_read =
368370
cache.Get(key1, [](const std::string& data) { return data; });
369371
ASSERT_FALSE(key1_data_read.empty());
370-
ASSERT_EQ(key1_data_string, boost::any_cast<std::string>(key1_data_read));
372+
ASSERT_EQ(key1_data_string,
373+
olp::porting::any_cast<std::string>(key1_data_read));
371374
}
372375
{
373376
SCOPED_TRACE("Get from protected - missing key");
@@ -402,7 +405,8 @@ TEST(DefaultCacheTest, ProtectedCacheTest) {
402405
auto key2_data_read =
403406
cache.Get(key2, [](const std::string& data) { return data; });
404407
ASSERT_FALSE(key2_data_read.empty());
405-
ASSERT_EQ(key2_data_string, boost::any_cast<std::string>(key2_data_read));
408+
ASSERT_EQ(key2_data_string,
409+
olp::porting::any_cast<std::string>(key2_data_read));
406410
ASSERT_TRUE(cache.Clear());
407411
}
408412
{
@@ -417,7 +421,8 @@ TEST(DefaultCacheTest, ProtectedCacheTest) {
417421
auto key1_data_read =
418422
cache.Get(key1, [](const std::string& data) { return data; });
419423
ASSERT_FALSE(key1_data_read.empty());
420-
ASSERT_EQ(key1_data_string, boost::any_cast<std::string>(key1_data_read));
424+
ASSERT_EQ(key1_data_string,
425+
olp::porting::any_cast<std::string>(key1_data_read));
421426
}
422427
{
423428
SCOPED_TRACE("Put to protected - blocked");
@@ -440,7 +445,8 @@ TEST(DefaultCacheTest, ProtectedCacheTest) {
440445
auto key1_data_read =
441446
cache.Get(key1, [](const std::string& data) { return data; });
442447
ASSERT_FALSE(key1_data_read.empty());
443-
ASSERT_EQ(key1_data_string, boost::any_cast<std::string>(key1_data_read));
448+
ASSERT_EQ(key1_data_string,
449+
olp::porting::any_cast<std::string>(key1_data_read));
444450
}
445451

446452
{

olp-cpp-sdk-core/tests/cache/InMemoryCacheTest.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ TEST(InMemoryCacheTest, NoLimit) {
6262

6363
auto i0 = cache.Get("key0");
6464
ASSERT_FALSE(i0.empty());
65-
ASSERT_EQ("value0", boost::any_cast<std::string>(i0));
65+
ASSERT_EQ("value0", olp::porting::any_cast<std::string>(i0));
6666

6767
auto i9 = cache.Get("key9");
6868
ASSERT_FALSE(i9.empty());
69-
ASSERT_EQ("value9", boost::any_cast<std::string>(i9));
69+
ASSERT_EQ("value9", olp::porting::any_cast<std::string>(i9));
7070

7171
ASSERT_TRUE(cache.Get("key10").empty());
7272
}
@@ -127,14 +127,14 @@ TEST(InMemoryCacheTest, PutOverwritesPrevious) {
127127
ASSERT_EQ(1u, cache.Size());
128128
auto value = cache.Get(key);
129129
ASSERT_FALSE(value.empty());
130-
ASSERT_EQ(orig_value, boost::any_cast<std::string>(value));
130+
ASSERT_EQ(orig_value, olp::porting::any_cast<std::string>(value));
131131

132132
std::string updated_value("updatedValue");
133133
cache.Put(key, updated_value);
134134

135135
value = cache.Get(key);
136136
ASSERT_FALSE(value.empty());
137-
ASSERT_EQ(updated_value, boost::any_cast<std::string>(value));
137+
ASSERT_EQ(updated_value, olp::porting::any_cast<std::string>(value));
138138
}
139139

140140
TEST(InMemoryCacheTest, InsertOverLimit) {
@@ -145,7 +145,7 @@ TEST(InMemoryCacheTest, InsertOverLimit) {
145145
ASSERT_TRUE(cache.Get("key0").empty());
146146
auto i1 = cache.Get("key1");
147147
ASSERT_FALSE(i1.empty());
148-
ASSERT_EQ("value1", boost::any_cast<std::string>(i1));
148+
ASSERT_EQ("value1", olp::porting::any_cast<std::string>(i1));
149149
}
150150

151151
TEST(InMemoryCacheTest, GetReorders) {
@@ -155,14 +155,14 @@ TEST(InMemoryCacheTest, GetReorders) {
155155

156156
auto i0 = cache.Get("key0");
157157
ASSERT_FALSE(i0.empty());
158-
ASSERT_EQ("value0", boost::any_cast<std::string>(i0));
158+
ASSERT_EQ("value0", olp::porting::any_cast<std::string>(i0));
159159

160160
Populate(cache, 1, 2);
161161
ASSERT_TRUE(cache.Get("key1").empty());
162162

163163
auto i2 = cache.Get("key2");
164164
ASSERT_FALSE(i2.empty());
165-
ASSERT_EQ("value2", boost::any_cast<std::string>(i2));
165+
ASSERT_EQ("value2", olp::porting::any_cast<std::string>(i2));
166166
}
167167

168168
TEST(InMemoryCacheTest, GetSingleExpired) {
@@ -370,7 +370,7 @@ TEST(InMemoryCacheTest, ClassBasedCustomCost) {
370370
auto model_item = std::get<2>(tuple);
371371
std::size_t result(1u);
372372

373-
if (auto data_container = boost::any_cast<Data>(model_item)) {
373+
if (auto data_container = olp::porting::any_cast<Data>(model_item)) {
374374
auto data_size = data_container->size();
375375
result = (data_size > 0) ? data_size : result;
376376
}

olp-cpp-sdk-dataservice-read/src/repositories/ApiCacheRepository.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ porting::optional<std::string> ApiCacheRepository::Get(
5757
return olp::porting::none;
5858
}
5959

60-
return boost::any_cast<std::string>(url);
60+
return olp::porting::any_cast<std::string>(url);
6161
}
6262

6363
} // namespace repository

olp-cpp-sdk-dataservice-read/src/repositories/CatalogCacheRepository.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ porting::optional<model::Catalog> CatalogCacheRepository::Get() {
7777
return olp::porting::none;
7878
}
7979

80-
return boost::any_cast<model::Catalog>(cached_catalog);
80+
return olp::porting::any_cast<model::Catalog>(cached_catalog);
8181
}
8282

8383
bool CatalogCacheRepository::PutVersion(const model::VersionResponse& version) {
@@ -102,7 +102,7 @@ porting::optional<model::VersionResponse> CatalogCacheRepository::GetVersion() {
102102
if (cached_version.empty()) {
103103
return olp::porting::none;
104104
}
105-
return boost::any_cast<model::VersionResponse>(cached_version);
105+
return olp::porting::any_cast<model::VersionResponse>(cached_version);
106106
}
107107

108108
bool CatalogCacheRepository::Clear() {

olp-cpp-sdk-dataservice-read/src/repositories/PartitionsCacheRepository.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ porting::optional<model::LayerVersions> PartitionsCacheRepository::Get(
190190
}
191191

192192
return std::move(
193-
boost::any_cast<model::LayerVersions&&>(cached_layer_versions));
193+
olp::porting::any_cast<model::LayerVersions&&>(cached_layer_versions));
194194
}
195195

196196
client::ApiNoResponse PartitionsCacheRepository::Put(

olp-cpp-sdk-dataservice-write/src/ApiClientLookup.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ ApiClientLookup::ApiClientResponse ApiClientLookup::LookupApiClient(
149149
auto url =
150150
cache->Get(cache_key, [](const std::string& value) { return value; });
151151
if (!url.empty()) {
152-
auto base_url = boost::any_cast<std::string>(url);
152+
auto base_url = olp::porting::any_cast<std::string>(url);
153153
OLP_SDK_LOG_INFO_F(kLogTag, "LookupApiClient(%s, %s) -> from cache",
154154
service.c_str(), service_version.c_str());
155155
client::OlpClient client(settings, base_url);

olp-cpp-sdk-dataservice-write/src/CatalogSettings.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ CatalogSettings::LayerSettingsResult CatalogSettings::GetLayerSettings(
112112
.str());
113113
}
114114

115-
const auto& catalog = boost::any_cast<const model::Catalog&>(cached_catalog);
115+
const auto& catalog =
116+
olp::porting::any_cast<const model::Catalog&>(cached_catalog);
116117
return GetLayerSettingsFromModel(catalog, layer_id);
117118
}
118119

0 commit comments

Comments
 (0)