Skip to content

Commit f13d510

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 f13d510

209 files changed

Lines changed: 1495 additions & 1376 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 `olp::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 olp::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+
olp::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+
olp::porting::optional<int64_t> catalog_version,
363363
client::OlpClientSettings settings);
364364
```
365365

examples/ProtectedCacheExample.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,13 @@ int RunExampleReadWithCache(const AccessKey& access_key,
108108

109109
// Create appropriate layer client with HRN, layer name and settings.
110110
olp::dataservice::read::VersionedLayerClient layer_client(
111-
olp::client::HRN(catalog), first_layer_id, boost::none, client_settings);
111+
olp::client::HRN(catalog), first_layer_id, olp::porting::none, client_settings);
112112

113113
// Retrieve the partition data
114114
// Create a DataRequest with appropriate LayerId and PartitionId
115115
auto request = olp::dataservice::read::DataRequest()
116116
.WithPartitionId(first_partition_id)
117-
.WithBillingTag(boost::none);
117+
.WithBillingTag(olp::porting::none);
118118
if (cache_settings.disk_path_protected.is_initialized()) {
119119
request.WithFetchOption(olp::dataservice::read::FetchOptions::CacheOnly);
120120
}
@@ -145,6 +145,6 @@ int RunExampleProtectedCache(const AccessKey& access_key, const std::string& cat
145145
}
146146
// Read data with protected cache. Set mutable cache to none.
147147
cache_settings.disk_path_protected = cache_settings.disk_path_mutable;
148-
cache_settings.disk_path_mutable = boost::none;
148+
cache_settings.disk_path_mutable = olp::porting::none;
149149
return RunExampleReadWithCache(access_key, cache_settings, catalog);
150150
}

examples/ReadExample.cpp

Lines changed: 4 additions & 4 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);
@@ -162,7 +162,7 @@ int RunExampleRead(const AccessKey& access_key, const std::string& catalog,
162162

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

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

190190
// Run the PartitionsRequest
191191
auto future = layer_client.GetPartitions(request);
@@ -206,7 +206,7 @@ int RunExampleRead(const AccessKey& access_key, const std::string& catalog,
206206
// Create a DataRequest with appropriate LayerId and PartitionId
207207
auto request = olp::dataservice::read::DataRequest()
208208
.WithPartitionId(first_partition_id)
209-
.WithBillingTag(boost::none);
209+
.WithBillingTag(olp::porting::none);
210210

211211
// Run the DataRequest
212212
auto future = layer_client.GetData(request);

examples/ReadExample.h

Lines changed: 2 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,4 @@
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 = olp::porting::none);

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+
olp::porting::optional<std::string> scope{olp::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+
olp::porting::optional<std::string> device_id{olp::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+
olp::porting::optional<std::string> custom_body{olp::porting::none};
9393
};
9494

9595
/**

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

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

2222
#include <string>
2323

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

2727
namespace olp {
@@ -58,7 +58,7 @@ class AUTHENTICATION_API AuthenticationCredentials {
5858
* @return An optional value with your credentials if the credentials were
5959
* read successfully, or no value in case of failure.
6060
*/
61-
static boost::optional<AuthenticationCredentials> ReadFromStream(
61+
static olp::porting::optional<AuthenticationCredentials> ReadFromStream(
6262
std::istream& stream);
6363

6464
/**
@@ -81,7 +81,7 @@ class AUTHENTICATION_API AuthenticationCredentials {
8181
* @return The optional value with your credentials if the credentials were
8282
* read successfully, or no value in case of failure.
8383
*/
84-
static boost::optional<AuthenticationCredentials> ReadFromFile(
84+
static olp::porting::optional<AuthenticationCredentials> ReadFromFile(
8585
std::string filename = {});
8686
AuthenticationCredentials() = delete;
8787

0 commit comments

Comments
 (0)