Skip to content

Commit 1ed5783

Browse files
committed
Use std::optional if available.
Currently, SDK requires C++11 minimum. So, boost::optional type is used for optional values. For C++17 and above more convenient is to use std::optional instead. This PR makes the optional type used configurable. Relates-To: NLAM-23 Signed-off-by: sopov <ext-alexander.sopov@here.com>
1 parent 7d33c0b commit 1ed5783

211 files changed

Lines changed: 1654 additions & 1646 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CONTRIBUTING.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,12 +257,13 @@ inline PublishDataRequest& WithLayerId(std::string&& layer_id) {
257257

258258
#### API optional parameters
259259

260-
The SDK uses `boost::optional` for optional members, parameters, or return types. Also, function comments should indicate whether the parameter is optional or required.
260+
The SDK uses `porting::optional` mapped to either `boost::optional` or `std::optional` for optional members,
261+
parameters, or return types. Also, function comments should indicate whether the parameter is optional or required.
261262

262263
Example:
263264

264265
```cpp
265-
inline const boost::optional<std::string>& GetBillingTag() const {
266+
inline const porting::optional<std::string>& GetBillingTag() const {
266267
return billing_tag_;
267268
}
268269

docs/dataservice-cache-example.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ You can get data from a [versioned layer](https://www.here.com/docs/bundle/data-
8989
olp::dataservice::read::VersionedLayerClient layer_client (
9090
client::HRN catalog,
9191
std::string layer_id,
92-
boost::optional<int64_t> catalog_version,
92+
porting::optional<int64_t> catalog_version,
9393
client::OlpClientSettings settings);
9494
```
9595
@@ -102,7 +102,7 @@ You can get data from a [versioned layer](https://www.here.com/docs/bundle/data-
102102
```cpp
103103
auto request = olp::dataservice::read::DataRequest()
104104
.WithPartitionId(first_partition_id)
105-
.WithBillingTag(boost::none)
105+
.WithBillingTag(olp::porting::none)
106106
.WithFetchOption(olp::dataservice::read::FetchOptions::OnlineIfNotFound);
107107
```
108108

docs/dataservice-read-catalog-example.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ You can request any data version from a [versioned layer](https://www.here.com/d
359359
olp::dataservice::read::VersionedLayerClient layer_client (
360360
client::HRN catalog,
361361
std::string layer_id,
362-
boost::optional<int64_t> catalog_version,
362+
porting::optional<int64_t> catalog_version,
363363
client::OlpClientSettings settings);
364364
```
365365

examples/ProtectedCacheExample.cpp

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,16 @@ bool HandleDataResponse(
6262
} // namespace
6363

6464
int RunExampleReadWithCache(const AccessKey& access_key,
65-
const olp::cache::CacheSettings& cache_settings, const std::string& catalog) {
65+
const olp::cache::CacheSettings& cache_settings,
66+
const std::string& catalog) {
6667
OLP_SDK_LOG_INFO_F(
6768
kLogTag, "Mutable cache path is \"%s\"",
68-
cache_settings.disk_path_mutable.get_value_or("none").c_str());
69+
olp::porting::get_value_or(cache_settings.disk_path_mutable, "none")
70+
.c_str());
6971
OLP_SDK_LOG_INFO_F(
7072
kLogTag, "Protected cache path is \"%s\"",
71-
cache_settings.disk_path_protected.get_value_or("none").c_str());
73+
olp::porting::get_value_or(cache_settings.disk_path_protected, "none")
74+
.c_str());
7275
// Create a task scheduler instance
7376
std::shared_ptr<olp::thread::TaskScheduler> task_scheduler =
7477
olp::client::OlpClientSettingsFactory::CreateDefaultTaskScheduler(1u);
@@ -84,8 +87,8 @@ int RunExampleReadWithCache(const AccessKey& access_key,
8487
olp::authentication::AuthenticationCredentials::ReadFromFile();
8588

8689
// Initialize authentication settings.
87-
olp::authentication::Settings settings{
88-
read_credentials_result.get_value_or({access_key.id, access_key.secret})};
90+
olp::authentication::Settings settings{olp::porting::get_value_or(
91+
read_credentials_result, {access_key.id, access_key.secret})};
8992
settings.task_scheduler = task_scheduler;
9093
settings.network_request_handler = http_client;
9194

@@ -108,23 +111,22 @@ int RunExampleReadWithCache(const AccessKey& access_key,
108111

109112
// Create appropriate layer client with HRN, layer name and settings.
110113
olp::dataservice::read::VersionedLayerClient layer_client(
111-
olp::client::HRN(catalog), first_layer_id, boost::none, client_settings);
114+
olp::client::HRN(catalog), first_layer_id, olp::porting::none,
115+
client_settings);
112116

113117
// Retrieve the partition data
114118
// Create a DataRequest with appropriate LayerId and PartitionId
115-
auto request = olp::dataservice::read::DataRequest()
116-
.WithPartitionId(first_partition_id)
117-
.WithBillingTag(boost::none);
118-
if (cache_settings.disk_path_protected.is_initialized()) {
119+
auto request =
120+
olp::dataservice::read::DataRequest().WithPartitionId(first_partition_id);
121+
if (cache_settings.disk_path_protected.has_value()) {
119122
request.WithFetchOption(olp::dataservice::read::FetchOptions::CacheOnly);
120123
}
121124

122125
// Run the DataRequest
123126
auto future = layer_client.GetData(request);
124127

125128
// Wait for DataResponse
126-
olp::dataservice::read::DataResponse data_response =
127-
future.GetFuture().get();
129+
olp::dataservice::read::DataResponse data_response = future.GetFuture().get();
128130

129131
// Compact mutable cache, so it can be used as protected cache
130132
cache->Compact();
@@ -133,8 +135,8 @@ int RunExampleReadWithCache(const AccessKey& access_key,
133135
return (HandleDataResponse(data_response) ? 0 : -1);
134136
}
135137

136-
int RunExampleProtectedCache(const AccessKey& access_key, const std::string& catalog)
137-
{
138+
int RunExampleProtectedCache(const AccessKey& access_key,
139+
const std::string& catalog) {
138140
// Read data with mutable cache.
139141
olp::cache::CacheSettings cache_settings;
140142
cache_settings.disk_path_mutable =
@@ -145,6 +147,6 @@ int RunExampleProtectedCache(const AccessKey& access_key, const std::string& cat
145147
}
146148
// Read data with protected cache. Set mutable cache to none.
147149
cache_settings.disk_path_protected = cache_settings.disk_path_mutable;
148-
cache_settings.disk_path_mutable = boost::none;
150+
cache_settings.disk_path_mutable = olp::porting::none;
149151
return RunExampleReadWithCache(access_key, cache_settings, catalog);
150152
}

examples/ReadExample.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ bool HandleDataResponse(
119119
} // namespace
120120

121121
int RunExampleRead(const AccessKey& access_key, const std::string& catalog,
122-
const boost::optional<int64_t>& catalog_version) {
122+
const olp::porting::optional<int64_t>& catalog_version) {
123123
// Create a task scheduler instance
124124
std::shared_ptr<olp::thread::TaskScheduler> task_scheduler =
125125
olp::client::OlpClientSettingsFactory::CreateDefaultTaskScheduler(1u);
@@ -135,8 +135,8 @@ int RunExampleRead(const AccessKey& access_key, const std::string& catalog,
135135
olp::authentication::AuthenticationCredentials::ReadFromFile();
136136

137137
// Initialize authentication settings.
138-
olp::authentication::Settings settings{
139-
read_credentials_result.get_value_or({access_key.id, access_key.secret})};
138+
olp::authentication::Settings settings{olp::porting::get_value_or(
139+
read_credentials_result, {access_key.id, access_key.secret})};
140140
settings.task_scheduler = task_scheduler;
141141
settings.network_request_handler = http_client;
142142

@@ -161,8 +161,8 @@ int RunExampleRead(const AccessKey& access_key, const std::string& catalog,
161161
olp::client::HRN(catalog), client_settings);
162162

163163
// Create CatalogRequest
164-
auto request =
165-
olp::dataservice::read::CatalogRequest().WithBillingTag(boost::none);
164+
auto request = olp::dataservice::read::CatalogRequest().WithBillingTag(
165+
olp::porting::none);
166166

167167
// Run the CatalogRequest
168168
auto future = catalog_client.GetCatalog(request);
@@ -184,8 +184,8 @@ int RunExampleRead(const AccessKey& access_key, const std::string& catalog,
184184
if (!first_layer_id.empty()) {
185185
// Retrieve the partitions metadata
186186
// Create a PartitionsRequest with appropriate LayerId
187-
auto request =
188-
olp::dataservice::read::PartitionsRequest().WithBillingTag(boost::none);
187+
auto request = olp::dataservice::read::PartitionsRequest().WithBillingTag(
188+
olp::porting::none);
189189

190190
// Run the PartitionsRequest
191191
auto future = layer_client.GetPartitions(request);
@@ -204,9 +204,8 @@ int RunExampleRead(const AccessKey& access_key, const std::string& catalog,
204204
if (!first_partition_id.empty()) {
205205
// Retrieve the partition data
206206
// Create a DataRequest with appropriate LayerId and PartitionId
207-
auto request = olp::dataservice::read::DataRequest()
208-
.WithPartitionId(first_partition_id)
209-
.WithBillingTag(boost::none);
207+
auto request = olp::dataservice::read::DataRequest().WithPartitionId(
208+
first_partition_id);
210209

211210
// Run the DataRequest
212211
auto future = layer_client.GetData(request);

examples/ReadExample.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
#include "Examples.h"
2323

24-
#include <boost/optional.hpp>
24+
#include <olp/core/porting/optional.hpp>
2525

2626
/**
2727
* @brief Dataservice read example. Authenticate client using access key id and
@@ -35,4 +35,5 @@
3535
*/
3636
int RunExampleRead(
3737
const AccessKey& access_key, const std::string& catalog,
38-
const boost::optional<int64_t>& catalog_version = boost::none);
38+
const olp::porting::optional<int64_t>& catalog_version =
39+
olp::porting::none);

examples/StreamLayerReadExample.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ int GetDataFromMessages(dataread::StreamLayerClient& client,
6363
auto handle = message.GetMetaData().GetDataHandle();
6464
if (handle) {
6565
OLP_SDK_LOG_INFO_F(kLogTag, "Message data: handle - %s, size - %lu",
66-
handle.get().c_str(),
67-
message.GetMetaData().GetDataSize().get());
66+
handle->c_str(), *message.GetMetaData().GetDataSize());
6867
// use GetData(const model::Message& message) with message instance to
6968
// request actual data with data handle.
7069
auto message_future = client.GetData(message);
@@ -73,14 +72,14 @@ int GetDataFromMessages(dataread::StreamLayerClient& client,
7372
OLP_SDK_LOG_WARNING_F(kLogTag,
7473
"Failed to get data for data handle %s - HTTP "
7574
"Status: %d Message: %s",
76-
handle.get().c_str(),
75+
handle->c_str(),
7776
message_result.GetError().GetHttpStatusCode(),
7877
message_result.GetError().GetMessage().c_str());
7978
continue;
8079
}
8180
auto message_data = message_result.MoveResult();
8281
OLP_SDK_LOG_INFO_F(kLogTag, "GetData for %s successful: size - %lu",
83-
handle.get().c_str(), message_data->size());
82+
handle->c_str(), message_data->size());
8483
} else {
8584
// If data is less than 1 MB, the data content published directly in the
8685
// metadata and encoded in Base64.

examples/main.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ int RequiredArgumentError(const tools::Option& arg) {
6868
}
6969
int ParseArguments(const int argc, char** argv, AccessKey& access_key,
7070
std::string& catalog,
71-
boost::optional<int64_t>& catalog_version,
71+
olp::porting::optional<int64_t>& catalog_version,
7272
std::string& layer_id,
7373
olp::dataservice::read::SubscribeRequest::SubscriptionMode&
7474
subscription_mode) {
@@ -128,7 +128,7 @@ int ParseArguments(const int argc, char** argv, AccessKey& access_key,
128128
if (ss.fail() || !ss.eof()) {
129129
std::cout << "invalid catalog version value -- '" << *it
130130
<< "', but int64 is expected." << std::endl;
131-
catalog_version = boost::none;
131+
catalog_version = olp::porting::none;
132132
}
133133
} else if (IsMatch(*it, tools::kLayerIdOption)) {
134134
if (++it == arguments.end()) {
@@ -168,7 +168,7 @@ int ParseArguments(const int argc, char** argv, AccessKey& access_key,
168168

169169
int RunExamples(const AccessKey& access_key, int examples_to_run,
170170
const std::string& catalog,
171-
const boost::optional<int64_t>& catalog_version,
171+
const olp::porting::optional<int64_t>& catalog_version,
172172
const std::string& layer_id,
173173
olp::dataservice::read::SubscribeRequest::SubscriptionMode
174174
subscription_mode) {
@@ -213,7 +213,7 @@ int main(int argc, char** argv) {
213213
std::string catalog; // the HRN of the catalog to which you to publish data
214214
std::string layer_id; // the of the layer inside the catalog to which you
215215
// want to publish data
216-
boost::optional<int64_t> catalog_version; // version of the catalog.
216+
olp::porting::optional<int64_t> catalog_version; // version of the catalog.
217217
auto subscription_mode =
218218
olp::dataservice::read::SubscribeRequest::SubscriptionMode::
219219
kSerial; // subscription mode for read stream layer example

external/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ if(OLP_SDK_ENABLE_DEFAULT_CACHE_LMDB)
9797
endif()
9898
endif()
9999

100-
find_package(Boost QUIET)
100+
find_package(Boost 1.82.0 QUIET)
101101
if(NOT TARGET Boost AND NOT Boost_FOUND)
102102
add_subdirectory(boost)
103103
set(BOOST_ROOT ${EXTERNAL_BOOST_ROOT} PARENT_SCOPE)

olp-cpp-sdk-authentication/include/olp/authentication/AuthenticationClient.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
#include <olp/authentication/Types.h>
3737
#include <olp/core/client/ApiResponse.h>
3838
#include <olp/core/client/CancellationToken.h>
39-
#include <boost/optional.hpp>
39+
#include <olp/core/porting/optional.hpp>
4040

4141
/**
4242
* @brief Rules all the other namespaces.
@@ -65,15 +65,15 @@ class AUTHENTICATION_API AuthenticationClient {
6565
/**
6666
* @brief (Optional) The scope assigned to the access token.
6767
*/
68-
boost::optional<std::string> scope{boost::none};
68+
porting::optional<std::string> scope{porting::none};
6969

7070
/**
7171
* @brief (Optional) The device ID assigned to the access token.
7272
*
7373
* @note This field is only necessary if you want to apply a oauth rate
7474
* limit on a particular device.
7575
*/
76-
boost::optional<std::string> device_id{boost::none};
76+
porting::optional<std::string> device_id{porting::none};
7777

7878
/**
7979
* @brief (Optional) The number of seconds left before the access
@@ -89,7 +89,7 @@ class AUTHENTICATION_API AuthenticationClient {
8989
* requires it. Fully overrides default body and resets the request content
9090
* type.
9191
*/
92-
boost::optional<std::string> custom_body{boost::none};
92+
porting::optional<std::string> custom_body{olp::porting::none};
9393
};
9494

9595
/**

0 commit comments

Comments
 (0)