Skip to content

Commit c7d1812

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. The task NLAM-23 is about making this type configurable. This PR is a first part of the task: olp-cpp-sdk-core. Relates-To: NLAM-23 Signed-off-by: sopov <[email protected]>
1 parent 7d33c0b commit c7d1812

Some content is hidden

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

44 files changed

+280
-176
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ endif()
3737
option(OLP_SDK_ENABLE_TESTING "Flag to enable/disable building unit and integration tests" ON)
3838
option(OLP_SDK_BUILD_DOC "Build SDK documentation" OFF)
3939
option(OLP_SDK_NO_EXCEPTION "Disable exception handling" OFF)
40+
option(OLP_SDK_FORCE_BOOST_OPTIONAL "Use boost::optional instead of std::optional with C++17 and above" OFF)
4041
option(OLP_SDK_BOOST_THROW_EXCEPTION_EXTERNAL "The boost::throw_exception() is defined externally" OFF)
4142
option(OLP_SDK_BUILD_EXTERNAL_DEPS "Download and build external dependencies" ON)
4243
option(OLP_SDK_BUILD_EXAMPLES "Enable examples targets" OFF)

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

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-core/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ set(OLP_SDK_PORTING_HEADERS
131131
./include/olp/core/porting/deprecated.h
132132
./include/olp/core/porting/export.h
133133
./include/olp/core/porting/make_unique.h
134+
./include/olp/core/porting/optional.hpp
134135
./include/olp/core/porting/platform.h
135136
./include/olp/core/porting/shared_mutex.h
136137
./include/olp/core/porting/try_emplace.h
@@ -439,6 +440,11 @@ if (OLP_SDK_NO_EXCEPTION AND NOT OLP_SDK_BOOST_THROW_EXCEPTION_EXTERNAL)
439440
PRIVATE OLP_SDK_BOOST_THROW_EXCEPTION=1)
440441
endif()
441442

443+
if (OLP_SDK_FORCE_BOOST_OPTIONAL)
444+
target_compile_definitions(${PROJECT_NAME}
445+
PUBLIC OLP_CPP_SDK_USE_BOOST_OPTIONAL)
446+
endif()
447+
442448
target_include_directories(${PROJECT_NAME} PUBLIC
443449
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
444450
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>

olp-cpp-sdk-core/include/olp/core/cache/CacheSettings.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
#include <olp/core/Config.h>
2626
#include <olp/core/CoreApi.h>
2727

28-
#include <olp/core/porting/deprecated.h>
29-
#include <boost/optional.hpp>
28+
#include <olp/core/porting/optional.hpp>
3029

3130
namespace olp {
3231
namespace cache {
@@ -72,7 +71,7 @@ struct CORE_API CacheSettings {
7271
* If this parameter is not set, the downloaded data is stored
7372
* only in the memory cache that is limited by `#max_memory_cache_size`.
7473
*/
75-
boost::optional<std::string> disk_path_mutable = boost::none;
74+
porting::optional<std::string> disk_path_mutable = porting::none;
7675

7776
/**
7877
* @brief Sets the upper limit (in bytes) of the disk space that is used for
@@ -161,7 +160,7 @@ struct CORE_API CacheSettings {
161160
* have a stable fallback state or offline data that you can always access
162161
* regardless of the network state.
163162
*/
164-
boost::optional<std::string> disk_path_protected = boost::none;
163+
porting::optional<std::string> disk_path_protected = porting::none;
165164

166165
/**
167166
* @brief The extend permissions flag (applicable for Unix systems).

olp-cpp-sdk-core/include/olp/core/cache/KeyGenerator.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@
2222
#include <string>
2323

2424
#include <olp/core/CoreApi.h>
25-
#include <olp/core/client/HRN.h>
2625
#include <olp/core/geo/tiling/TileKey.h>
27-
#include <boost/optional.hpp>
26+
#include <olp/core/porting/optional.hpp>
2827

2928
namespace olp {
3029
namespace cache {
@@ -77,7 +76,7 @@ class CORE_API KeyGenerator {
7776
*/
7877
static std::string CreatePartitionKey(
7978
const std::string& hrn, const std::string& layer_id,
80-
const std::string& partition_id, const boost::optional<int64_t>& version);
79+
const std::string& partition_id, const porting::optional<int64_t>& version);
8180

8281
/**
8382
* @brief Generates cache key for storing list of partitions.
@@ -90,7 +89,7 @@ class CORE_API KeyGenerator {
9089
*/
9190
static std::string CreatePartitionsKey(
9291
const std::string& hrn, const std::string& layer_id,
93-
const boost::optional<int64_t>& version);
92+
const porting::optional<int64_t>& version);
9493

9594
/**
9695
* @brief Generates cache key for storing list of available layer versions.
@@ -117,7 +116,7 @@ class CORE_API KeyGenerator {
117116
static std::string CreateQuadTreeKey(const std::string& hrn,
118117
const std::string& layer_id,
119118
olp::geo::TileKey root,
120-
const boost::optional<int64_t>& version,
119+
const porting::optional<int64_t>& version,
121120
int32_t depth);
122121

123122
/**

olp-cpp-sdk-core/include/olp/core/client/OlpClientSettings.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,9 @@
2424
#include <memory>
2525
#include <string>
2626

27-
#include <boost/optional.hpp>
27+
#include <olp/core/porting/optional.hpp>
2828

2929
#include <olp/core/client/CancellationContext.h>
30-
#include <olp/core/client/CancellationToken.h>
3130
#include <olp/core/client/DefaultLookupEndpointProvider.h>
3231
#include <olp/core/client/HRN.h>
3332
#include <olp/core/client/HttpResponse.h>
@@ -191,16 +190,16 @@ struct CORE_API OlpClientSettings {
191190
/**
192191
* @brief The network proxy settings.
193192
*
194-
* To remove any existing proxy settings, set to `boost::none`.
193+
* To remove any existing proxy settings, set to `olp::porting::none`.
195194
*/
196-
boost::optional<http::NetworkProxySettings> proxy_settings = boost::none;
195+
porting::optional<http::NetworkProxySettings> proxy_settings = porting::none;
197196

198197
/**
199198
* @brief The authentication settings.
200199
*
201-
* To remove any existing authentication settings, set to `boost::none`.
200+
* To remove any existing authentication settings, set to `olp::porting::none`.
202201
*/
203-
boost::optional<AuthenticationSettings> authentication_settings = boost::none;
202+
porting::optional<AuthenticationSettings> authentication_settings = porting::none;
204203

205204
/**
206205
* @brief The `TaskScheduler` instance.

olp-cpp-sdk-core/include/olp/core/client/OlpClientSettingsFactory.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
#include <memory>
2323
#include <string>
2424

25-
#include <boost/optional.hpp>
26-
2725
#include "olp/core/CoreApi.h"
2826
#include "olp/core/http/Network.h"
2927
#include "olp/core/http/NetworkInitializationSettings.h"

olp-cpp-sdk-core/include/olp/core/generated/parser/ParserWrapper.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include <vector>
2626

2727
#include <rapidjson/rapidjson.h>
28-
#include <boost/optional.hpp>
28+
#include <olp/core/porting/optional.hpp>
2929

3030
namespace olp {
3131
namespace parser {
@@ -57,7 +57,8 @@ inline void from_json(const rapidjson::Value& value,
5757
}
5858

5959
template <typename T>
60-
inline void from_json(const rapidjson::Value& value, boost::optional<T>& x) {
60+
inline void from_json(const rapidjson::Value& value,
61+
porting::optional<T>& x) {
6162
T result = T();
6263
from_json(value, result);
6364
x = result;

olp-cpp-sdk-core/include/olp/core/generated/serializer/SerializerWrapper.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include <vector>
2626
#include <utility>
2727

28-
#include <boost/optional.hpp>
28+
#include <olp/core/porting/optional.hpp>
2929
#include <rapidjson/document.h>
3030

3131
namespace olp {
@@ -63,10 +63,10 @@ inline void to_json(const std::shared_ptr<std::vector<unsigned char>>& x,
6363
}
6464

6565
template <typename T>
66-
inline void to_json(const boost::optional<T>& x, rapidjson::Value& value,
66+
inline void to_json(const porting::optional<T>& x, rapidjson::Value& value,
6767
rapidjson::Document::AllocatorType& allocator) {
6868
if (x) {
69-
to_json(x.get(), value, allocator);
69+
to_json(*x, value, allocator);
7070
} else {
7171
value.SetNull();
7272
}

0 commit comments

Comments
 (0)