Skip to content

Commit 7c1dccc

Browse files
Add build with std::any and std::optional (#1693)
* Add build with std::any and std::optional boost::any and boost::optional used by default and it make sense to check that alternative options are not broken Relates-To: MINOR Signed-off-by: Rustam Gamidov <ext-rustam.gamidov@here.com> * Use olp::porting wrappers instead of direct `any` This allows to use either std for newer c++ or boost for older c++ or those who prefer boost Relates-To: MINOR Signed-off-by: Rustam Gamidov <ext-rustam.gamidov@here.com> --------- Signed-off-by: Rustam Gamidov <ext-rustam.gamidov@here.com>
1 parent 29d3e3c commit 7c1dccc

10 files changed

Lines changed: 51 additions & 23 deletions

File tree

.github/workflows/psv_pipelines.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,22 @@ jobs:
8888
run: ./scripts/linux/psv/test_psv.sh
8989
shell: bash
9090

91+
psv-linux-22-04-gcc11-build-porting-std:
92+
name: PSV.Linux.22.04.gcc11.OLP_SDK_USE_STD_OPTIONAL.OLP_SDK_USE_STD_ANY
93+
runs-on: ubuntu-22.04
94+
env:
95+
BUILD_TYPE: RelWithDebInfo
96+
EXTRA_CMAKE_OPTIONS: -DCMAKE_CXX_STANDARD=17 -DOLP_SDK_USE_STD_OPTIONAL=ON -DOLP_SDK_USE_STD_ANY=ON -DOLP_SDK_ENABLE_TESTING=OFF
97+
steps:
98+
- name: Check out repository
99+
uses: actions/checkout@v4
100+
- name: Install Ubuntu dependencies
101+
run: sudo apt-get update && sudo apt-get install -y libboost-all-dev ccache libssl-dev libcurl4-openssl-dev --no-install-recommends
102+
shell: bash
103+
- name: Compile project with cmake and ccache
104+
run: gcc --version && ./scripts/linux/psv/build_psv.sh
105+
shell: bash
106+
91107
psv-linux-latest-gcc14-build:
92108
name: PSV.Linux.latest.gcc14.Tests
93109
runs-on: ubuntu-latest

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2024 HERE Europe B.V.
2+
* Copyright (C) 2019-2026 HERE Europe B.V.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -311,7 +311,7 @@ olp::porting::any DefaultCacheImpl::Get(const std::string& key,
311311

312312
if (memory_cache_) {
313313
auto value = memory_cache_->Get(key);
314-
if (!value.empty()) {
314+
if (olp::porting::has_value(value)) {
315315
PromoteKeyLru(key);
316316
return value;
317317
}
@@ -1066,7 +1066,7 @@ OperationOutcome<KeyValueCache::ValueTypePtr> DefaultCacheImpl::Read(
10661066

10671067
if (memory_cache_) {
10681068
auto value = memory_cache_->Get(key);
1069-
if (!value.empty()) {
1069+
if (olp::porting::has_value(value)) {
10701070
PromoteKeyLru(key);
10711071
return olp::porting::any_cast<KeyValueCache::ValueTypePtr>(value);
10721072
}

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2021 HERE Europe B.V.
2+
* Copyright (C) 2019-2026 HERE Europe B.V.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,6 +17,9 @@
1717
* License-Filename: LICENSE
1818
*/
1919

20+
#include <cstring>
21+
#include <utility>
22+
2023
#include "InMemoryCache.h"
2124

2225
namespace olp {
@@ -41,7 +44,7 @@ InMemoryCache::InMemoryCache(size_t max_size, ModelCacheCostFunc cache_cost,
4144
});
4245
}
4346

44-
bool InMemoryCache::Put(const std::string& key, const boost::any& item,
47+
bool InMemoryCache::Put(const std::string& key, const olp::porting::any& item,
4548
time_t expire_seconds, size_t size) {
4649
std::lock_guard<std::mutex> lock{mutex_};
4750

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2020-2024 HERE Europe B.V.
2+
* Copyright (C) 2020-2026 HERE Europe B.V.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -51,7 +51,7 @@ porting::optional<std::string> ApiCacheRepository::Get(
5151
OLP_SDK_LOG_TRACE_F(kLogTag, "Get -> '%s'", key.c_str());
5252

5353
auto url = cache_->Get(key, [](const std::string& value) { return value; });
54-
if (url.empty()) {
54+
if (!olp::porting::has_value(url)) {
5555
return porting::none;
5656
}
5757

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2024 HERE Europe B.V.
2+
* Copyright (C) 2019-2026 HERE Europe B.V.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -53,7 +53,7 @@ porting::optional<std::string> ApiCacheRepository::Get(
5353
OLP_SDK_LOG_TRACE_F(kLogTag, "Get -> '%s'", key.c_str());
5454

5555
auto url = cache_->Get(key, [](const std::string& value) { return value; });
56-
if (url.empty()) {
56+
if (!olp::porting::has_value(url)) {
5757
return olp::porting::none;
5858
}
5959

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2025 HERE Europe B.V.
2+
* Copyright (C) 2019-2026 HERE Europe B.V.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,6 +19,7 @@
1919

2020
#include "CatalogCacheRepository.h"
2121

22+
#include <limits>
2223
#include <string>
2324

2425
#include <olp/core/cache/KeyGenerator.h>
@@ -73,7 +74,7 @@ porting::optional<model::Catalog> CatalogCacheRepository::Get() {
7374
return parser::parse<model::Catalog>(value);
7475
});
7576

76-
if (cached_catalog.empty()) {
77+
if (!olp::porting::has_value(cached_catalog)) {
7778
return olp::porting::none;
7879
}
7980

@@ -99,7 +100,7 @@ porting::optional<model::VersionResponse> CatalogCacheRepository::GetVersion() {
99100
return parser::parse<model::VersionResponse>(value);
100101
});
101102

102-
if (cached_version.empty()) {
103+
if (!olp::porting::has_value(cached_version)) {
103104
return olp::porting::none;
104105
}
105106
return olp::porting::any_cast<model::VersionResponse>(cached_version);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,12 @@ porting::optional<model::LayerVersions> PartitionsCacheRepository::Get(
185185
return parser::parse<model::LayerVersions>(serialized_object);
186186
});
187187

188-
if (cached_layer_versions.empty()) {
188+
if (!olp::porting::has_value(cached_layer_versions)) {
189189
return olp::porting::none;
190190
}
191191

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

196196
client::ApiNoResponse PartitionsCacheRepository::Put(

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2024 HERE Europe B.V.
2+
* Copyright (C) 2019-2026 HERE Europe B.V.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,6 +19,10 @@
1919

2020
#include "ApiClientLookup.h"
2121

22+
#include <map>
23+
#include <memory>
24+
#include <utility>
25+
2226
#include <olp/core/cache/KeyValueCache.h>
2327
#include <olp/core/client/ApiError.h>
2428
#include <olp/core/client/Condition.h>
@@ -148,7 +152,7 @@ ApiClientLookup::ApiClientResponse ApiClientLookup::LookupApiClient(
148152
if (cache) {
149153
auto url =
150154
cache->Get(cache_key, [](const std::string& value) { return value; });
151-
if (!url.empty()) {
155+
if (olp::porting::has_value(url)) {
152156
auto base_url = olp::porting::any_cast<std::string>(url);
153157
OLP_SDK_LOG_INFO_F(kLogTag, "LookupApiClient(%s, %s) -> from cache",
154158
service.c_str(), service_version.c_str());

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ CatalogSettings::LayerSettingsResult CatalogSettings::GetLayerSettings(
107107
return parser::parse<model::Catalog>(model);
108108
});
109109

110-
if (cached_catalog.empty()) {
110+
if (!olp::porting::has_value(cached_catalog)) {
111111
return client::ApiError(
112112
client::ErrorCode::Unknown,
113113
(boost::format("Cached catalog '%1' is empty") % catalog_.ToString())

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2021 HERE Europe B.V.
2+
* Copyright (C) 2019-2026 HERE Europe B.V.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,6 +19,10 @@
1919

2020
#include "StreamLayerClientImpl.h"
2121

22+
#include <memory>
23+
#include <string>
24+
#include <utility>
25+
2226
#include <boost/uuid/uuid.hpp>
2327
#include <boost/uuid/uuid_generators.hpp>
2428
#include <boost/uuid/uuid_io.hpp>
@@ -93,7 +97,7 @@ size_t StreamLayerClientImpl::QueueSize() const {
9397
const auto uuid_list_any =
9498
cache_->Get(GetUuidListKey(), [](const std::string& s) { return s; });
9599
std::string uuid_list = "";
96-
if (!uuid_list_any.empty()) {
100+
if (olp::porting::has_value(uuid_list_any)) {
97101
uuid_list = olp::porting::any_cast<std::string>(uuid_list_any);
98102
return std::count(uuid_list.cbegin(), uuid_list.cend(), ',');
99103
}
@@ -134,7 +138,7 @@ porting::optional<std::string> StreamLayerClientImpl::Queue(
134138
const auto uuid_list_any =
135139
cache_->Get(GetUuidListKey(), [](const std::string& s) { return s; });
136140
std::string uuid_list = "";
137-
if (!uuid_list_any.empty()) {
141+
if (olp::porting::has_value(uuid_list_any)) {
138142
uuid_list = olp::porting::any_cast<std::string>(uuid_list_any);
139143
}
140144
uuid_list += publish_data_key + ",";
@@ -153,7 +157,7 @@ StreamLayerClientImpl::PopFromQueue() {
153157
const auto uuid_list_any =
154158
cache_->Get(GetUuidListKey(), [](const std::string& s) { return s; });
155159

156-
if (uuid_list_any.empty()) {
160+
if (!olp::porting::has_value(uuid_list_any)) {
157161
OLP_SDK_LOG_ERROR(kLogTag, "Unable to Restore UUID list from Cache");
158162
return olp::porting::none;
159163
}
@@ -176,7 +180,7 @@ StreamLayerClientImpl::PopFromQueue() {
176180
cache_->Put(GetUuidListKey(), uuid_list,
177181
[&uuid_list]() { return uuid_list; });
178182

179-
if (publish_data_any.empty()) {
183+
if (!olp::porting::has_value(publish_data_any)) {
180184
OLP_SDK_LOG_ERROR(kLogTag,
181185
"Unable to Restore PublishData Request from Cache");
182186
return olp::porting::none;

0 commit comments

Comments
 (0)