From e63d6ec81d0829d0c917948774492f8e2ff70731 Mon Sep 17 00:00:00 2001 From: Alexander Sopov Date: Thu, 7 Aug 2025 12:19:12 +0200 Subject: [PATCH] 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 commit is a first part of the task: olp-cpp-sdk-core. Relates-To: NLAM-23 Signed-off-by: sopov --- CMakeLists.txt | 1 + CONTRIBUTING.md | 5 +- docs/get-started.md | 1 + external/CMakeLists.txt | 2 +- olp-cpp-sdk-core/CMakeLists.txt | 6 ++ .../include/olp/core/cache/CacheSettings.h | 8 +- .../include/olp/core/cache/KeyGenerator.h | 9 +- .../olp/core/client/OlpClientSettings.h | 14 +-- .../core/client/OlpClientSettingsFactory.h | 2 - .../olp/core/generated/parser/ParserWrapper.h | 4 +- .../generated/serializer/SerializerWrapper.h | 6 +- .../include/olp/core/geo/tiling/PathTiling.h | 6 +- .../include/olp/core/geo/tiling/TileKey.h | 11 +-- .../include/olp/core/http/NetworkResponse.h | 7 +- .../include/olp/core/logging/FilterGroup.h | 28 +++--- .../include/olp/core/logging/Log.h | 5 +- .../include/olp/core/porting/optional.hpp | 98 +++++++++++++++++++ olp-cpp-sdk-core/include/olp/core/utils/Url.h | 6 +- .../src/cache/DefaultCacheImpl.cpp | 24 ++--- olp-cpp-sdk-core/src/cache/DefaultCacheImpl.h | 2 +- olp-cpp-sdk-core/src/cache/KeyGenerator.cpp | 6 +- .../src/client/ApiLookupClientImpl.cpp | 6 +- .../src/client/ApiLookupClientImpl.h | 6 +- olp-cpp-sdk-core/src/client/OlpClient.cpp | 12 +-- .../src/client/OlpClientSettingsFactory.cpp | 4 +- .../src/client/api/PlatformApi.cpp | 6 +- olp-cpp-sdk-core/src/client/api/PlatformApi.h | 4 +- .../src/client/api/ResourcesApi.cpp | 6 +- .../src/client/api/ResourcesApi.h | 4 +- .../client/repository/ApiCacheRepository.cpp | 8 +- .../client/repository/ApiCacheRepository.h | 6 +- olp-cpp-sdk-core/src/context/Context.cpp | 2 +- olp-cpp-sdk-core/src/geo/tiling/TileKey.cpp | 12 +-- olp-cpp-sdk-core/src/http/NetworkResponse.cpp | 2 +- .../src/http/curl/NetworkCurl.cpp | 15 +-- olp-cpp-sdk-core/src/http/curl/NetworkCurl.h | 6 +- olp-cpp-sdk-core/src/logging/FilterGroup.cpp | 6 +- olp-cpp-sdk-core/src/logging/Log.cpp | 10 +- olp-cpp-sdk-core/src/utils/Url.cpp | 4 +- .../tests/cache/DefaultCacheImplTest.cpp | 20 ++-- .../tests/cache/DefaultCacheTest.cpp | 12 +-- .../tests/cache/KeyGeneratorTest.cpp | 12 +-- .../tests/client/OlpClientTest.cpp | 2 +- .../tests/logging/FilterGroupTest.cpp | 44 ++++----- olp-cpp-sdk-core/tests/logging/LogTest.cpp | 6 +- 45 files changed, 283 insertions(+), 183 deletions(-) create mode 100644 olp-cpp-sdk-core/include/olp/core/porting/optional.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 5a6768ec3..b47bbb625 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,6 +37,7 @@ endif() option(OLP_SDK_ENABLE_TESTING "Flag to enable/disable building unit and integration tests" ON) option(OLP_SDK_BUILD_DOC "Build SDK documentation" OFF) option(OLP_SDK_NO_EXCEPTION "Disable exception handling" OFF) +option(OLP_SDK_FORCE_BOOST_OPTIONAL "Use boost::optional instead of std::optional with C++17 and above" OFF) option(OLP_SDK_BOOST_THROW_EXCEPTION_EXTERNAL "The boost::throw_exception() is defined externally" OFF) option(OLP_SDK_BUILD_EXTERNAL_DEPS "Download and build external dependencies" ON) option(OLP_SDK_BUILD_EXAMPLES "Enable examples targets" OFF) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d85ddac08..06bab658c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -257,12 +257,13 @@ inline PublishDataRequest& WithLayerId(std::string&& layer_id) { #### API optional parameters -The SDK uses `boost::optional` for optional members, parameters, or return types. Also, function comments should indicate whether the parameter is optional or required. +The SDK uses `porting::optional` mapped to either `boost::optional` or `std::optional` for optional members, +parameters, or return types. Also, function comments should indicate whether the parameter is optional or required. Example: ```cpp -inline const boost::optional& GetBillingTag() const { +inline const porting::optional& GetBillingTag() const { return billing_tag_; } diff --git a/docs/get-started.md b/docs/get-started.md index 18d274384..fba7df784 100644 --- a/docs/get-started.md +++ b/docs/get-started.md @@ -130,6 +130,7 @@ cmake --build . --target docs | `OLP_SDK_ENABLE_TESTING` | Defaults to `ON`. If enabled, unit tests are built for each library. | | `OLP_SDK_BUILD_EXTERNAL_DEPS` | Defaults to `ON`. If enabled, CMake downloads and compiles dependencies. | | `OLP_SDK_NO_EXCEPTION` | Defaults to `OFF`. If enabled, all libraries are built without exceptions. | +| `OLP_SDK_FORCE_BOOST_OPTIONAL` | Defaults to `OFF`. If enabled, all libraries are built with boost::optional type even when std::optional is available. | | `OLP_SDK_BOOST_THROW_EXCEPTION_EXTERNAL` | Defaults to `OFF`. When `OLP_SDK_NO_EXCEPTION` is `ON`, `boost` requires `boost::throw_exception()` to be defined. If enabled, the external definition of `boost::throw_exception()` is used. Otherwise, the library uses own definition. | | `OLP_SDK_MSVC_PARALLEL_BUILD_ENABLE` (Windows Only) | Defaults to `ON`. If enabled, the `/MP` compilation flag is added to build the Data SDK using multiple cores. | | `OLP_SDK_DISABLE_DEBUG_LOGGING`| Defaults to `OFF`. If enabled, the debug and trace level log messages are not printed. | diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index a7d07e2a0..b81b81125 100644 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -97,7 +97,7 @@ if(OLP_SDK_ENABLE_DEFAULT_CACHE_LMDB) endif() endif() -find_package(Boost QUIET) +find_package(Boost 1.82.0 QUIET) if(NOT TARGET Boost AND NOT Boost_FOUND) add_subdirectory(boost) set(BOOST_ROOT ${EXTERNAL_BOOST_ROOT} PARENT_SCOPE) diff --git a/olp-cpp-sdk-core/CMakeLists.txt b/olp-cpp-sdk-core/CMakeLists.txt index 6c2eead8c..ec84d313d 100644 --- a/olp-cpp-sdk-core/CMakeLists.txt +++ b/olp-cpp-sdk-core/CMakeLists.txt @@ -131,6 +131,7 @@ set(OLP_SDK_PORTING_HEADERS ./include/olp/core/porting/deprecated.h ./include/olp/core/porting/export.h ./include/olp/core/porting/make_unique.h + ./include/olp/core/porting/optional.hpp ./include/olp/core/porting/platform.h ./include/olp/core/porting/shared_mutex.h ./include/olp/core/porting/try_emplace.h @@ -439,6 +440,11 @@ if (OLP_SDK_NO_EXCEPTION AND NOT OLP_SDK_BOOST_THROW_EXCEPTION_EXTERNAL) PRIVATE OLP_SDK_BOOST_THROW_EXCEPTION=1) endif() +if (OLP_SDK_FORCE_BOOST_OPTIONAL) + target_compile_definitions(${PROJECT_NAME} + PUBLIC OLP_CPP_SDK_USE_BOOST_OPTIONAL) +endif() + target_include_directories(${PROJECT_NAME} PUBLIC $ $ diff --git a/olp-cpp-sdk-core/include/olp/core/cache/CacheSettings.h b/olp-cpp-sdk-core/include/olp/core/cache/CacheSettings.h index 144df9fd4..34b9cd845 100644 --- a/olp-cpp-sdk-core/include/olp/core/cache/CacheSettings.h +++ b/olp-cpp-sdk-core/include/olp/core/cache/CacheSettings.h @@ -24,9 +24,7 @@ #include #include - -#include -#include +#include namespace olp { namespace cache { @@ -72,7 +70,7 @@ struct CORE_API CacheSettings { * If this parameter is not set, the downloaded data is stored * only in the memory cache that is limited by `#max_memory_cache_size`. */ - boost::optional disk_path_mutable = boost::none; + porting::optional disk_path_mutable = porting::none; /** * @brief Sets the upper limit (in bytes) of the disk space that is used for @@ -161,7 +159,7 @@ struct CORE_API CacheSettings { * have a stable fallback state or offline data that you can always access * regardless of the network state. */ - boost::optional disk_path_protected = boost::none; + porting::optional disk_path_protected = porting::none; /** * @brief The extend permissions flag (applicable for Unix systems). diff --git a/olp-cpp-sdk-core/include/olp/core/cache/KeyGenerator.h b/olp-cpp-sdk-core/include/olp/core/cache/KeyGenerator.h index 93577e49d..b0cf8ccc5 100644 --- a/olp-cpp-sdk-core/include/olp/core/cache/KeyGenerator.h +++ b/olp-cpp-sdk-core/include/olp/core/cache/KeyGenerator.h @@ -22,9 +22,8 @@ #include #include -#include #include -#include +#include namespace olp { namespace cache { @@ -77,7 +76,7 @@ class CORE_API KeyGenerator { */ static std::string CreatePartitionKey( const std::string& hrn, const std::string& layer_id, - const std::string& partition_id, const boost::optional& version); + const std::string& partition_id, const porting::optional& version); /** * @brief Generates cache key for storing list of partitions. @@ -90,7 +89,7 @@ class CORE_API KeyGenerator { */ static std::string CreatePartitionsKey( const std::string& hrn, const std::string& layer_id, - const boost::optional& version); + const porting::optional& version); /** * @brief Generates cache key for storing list of available layer versions. @@ -117,7 +116,7 @@ class CORE_API KeyGenerator { static std::string CreateQuadTreeKey(const std::string& hrn, const std::string& layer_id, olp::geo::TileKey root, - const boost::optional& version, + const porting::optional& version, int32_t depth); /** diff --git a/olp-cpp-sdk-core/include/olp/core/client/OlpClientSettings.h b/olp-cpp-sdk-core/include/olp/core/client/OlpClientSettings.h index 580b12c6d..ad0d5b22b 100644 --- a/olp-cpp-sdk-core/include/olp/core/client/OlpClientSettings.h +++ b/olp-cpp-sdk-core/include/olp/core/client/OlpClientSettings.h @@ -24,16 +24,14 @@ #include #include -#include - #include -#include #include #include #include #include #include #include +#include namespace olp { namespace cache { @@ -191,16 +189,18 @@ struct CORE_API OlpClientSettings { /** * @brief The network proxy settings. * - * To remove any existing proxy settings, set to `boost::none`. + * To remove any existing proxy settings, set to `olp::porting::none`. */ - boost::optional proxy_settings = boost::none; + porting::optional proxy_settings = porting::none; /** * @brief The authentication settings. * - * To remove any existing authentication settings, set to `boost::none`. + * To remove any existing authentication settings, set to + * `olp::porting::none`. */ - boost::optional authentication_settings = boost::none; + porting::optional authentication_settings = + porting::none; /** * @brief The `TaskScheduler` instance. diff --git a/olp-cpp-sdk-core/include/olp/core/client/OlpClientSettingsFactory.h b/olp-cpp-sdk-core/include/olp/core/client/OlpClientSettingsFactory.h index 4d5f386d0..c2f98677f 100644 --- a/olp-cpp-sdk-core/include/olp/core/client/OlpClientSettingsFactory.h +++ b/olp-cpp-sdk-core/include/olp/core/client/OlpClientSettingsFactory.h @@ -22,8 +22,6 @@ #include #include -#include - #include "olp/core/CoreApi.h" #include "olp/core/http/Network.h" #include "olp/core/http/NetworkInitializationSettings.h" diff --git a/olp-cpp-sdk-core/include/olp/core/generated/parser/ParserWrapper.h b/olp-cpp-sdk-core/include/olp/core/generated/parser/ParserWrapper.h index 0a17b7bab..fd6b5d316 100644 --- a/olp-cpp-sdk-core/include/olp/core/generated/parser/ParserWrapper.h +++ b/olp-cpp-sdk-core/include/olp/core/generated/parser/ParserWrapper.h @@ -24,8 +24,8 @@ #include #include +#include #include -#include namespace olp { namespace parser { @@ -57,7 +57,7 @@ inline void from_json(const rapidjson::Value& value, } template -inline void from_json(const rapidjson::Value& value, boost::optional& x) { +inline void from_json(const rapidjson::Value& value, porting::optional& x) { T result = T(); from_json(value, result); x = result; diff --git a/olp-cpp-sdk-core/include/olp/core/generated/serializer/SerializerWrapper.h b/olp-cpp-sdk-core/include/olp/core/generated/serializer/SerializerWrapper.h index 5bec32f3e..50ee0117c 100644 --- a/olp-cpp-sdk-core/include/olp/core/generated/serializer/SerializerWrapper.h +++ b/olp-cpp-sdk-core/include/olp/core/generated/serializer/SerializerWrapper.h @@ -25,7 +25,7 @@ #include #include -#include +#include #include namespace olp { @@ -63,10 +63,10 @@ inline void to_json(const std::shared_ptr>& x, } template -inline void to_json(const boost::optional& x, rapidjson::Value& value, +inline void to_json(const porting::optional& x, rapidjson::Value& value, rapidjson::Document::AllocatorType& allocator) { if (x) { - to_json(x.get(), value, allocator); + to_json(*x, value, allocator); } else { value.SetNull(); } diff --git a/olp-cpp-sdk-core/include/olp/core/geo/tiling/PathTiling.h b/olp-cpp-sdk-core/include/olp/core/geo/tiling/PathTiling.h index e9ab17dc4..92eb1327b 100644 --- a/olp-cpp-sdk-core/include/olp/core/geo/tiling/PathTiling.h +++ b/olp-cpp-sdk-core/include/olp/core/geo/tiling/PathTiling.h @@ -26,7 +26,7 @@ #include #include #include -#include +#include namespace olp { namespace geo { @@ -378,7 +378,7 @@ class LineSliceIterator { LineSliceIterator& operator++() { if (!line_state_ || !detail::LineEvaluator::Iterate(*line_state_)) { - line_state_ = boost::none; + line_state_ = porting::none; ++segment_it_; } return *this; @@ -397,7 +397,7 @@ class LineSliceIterator { private: InputIterator segment_it_; int32_t half_line_width_; - boost::optional line_state_; + porting::optional line_state_; }; /** diff --git a/olp-cpp-sdk-core/include/olp/core/geo/tiling/TileKey.h b/olp-cpp-sdk-core/include/olp/core/geo/tiling/TileKey.h index c4445b357..8a6434e86 100644 --- a/olp-cpp-sdk-core/include/olp/core/geo/tiling/TileKey.h +++ b/olp-cpp-sdk-core/include/olp/core/geo/tiling/TileKey.h @@ -23,9 +23,8 @@ #include #include -#include - #include +#include namespace olp { namespace geo { @@ -66,7 +65,7 @@ class CORE_API TileKey { enum { MaxLevel = LevelCount - 1 }; /** - * @brief The main direction used to find a child node or + * @brief The main direction used to find a child node or * the relationship to the parent. * * Corresponds directly to the index in the `GetChild` function. @@ -504,7 +503,7 @@ using TileKeyLevels = std::bitset; * * @return The minimum level or `core::None` if the set is empty. */ -CORE_API boost::optional GetMinTileKeyLevel( +CORE_API porting::optional GetMinTileKeyLevel( const TileKeyLevels& levels); /** @@ -514,7 +513,7 @@ CORE_API boost::optional GetMinTileKeyLevel( * * @return The maximum level or `core::None` if the set is empty. */ -CORE_API boost::optional GetMaxTileKeyLevel( +CORE_API porting::optional GetMaxTileKeyLevel( const TileKeyLevels& levels); /** @@ -526,7 +525,7 @@ CORE_API boost::optional GetMaxTileKeyLevel( * * @return The nearest level or `core::None` if the set is empty. */ -CORE_API boost::optional GetNearestAvailableTileKeyLevel( +CORE_API porting::optional GetNearestAvailableTileKeyLevel( const TileKeyLevels& levels, const std::uint32_t reference_level); /** diff --git a/olp-cpp-sdk-core/include/olp/core/http/NetworkResponse.h b/olp-cpp-sdk-core/include/olp/core/http/NetworkResponse.h index bf76d4922..f0a4891e8 100644 --- a/olp-cpp-sdk-core/include/olp/core/http/NetworkResponse.h +++ b/olp-cpp-sdk-core/include/olp/core/http/NetworkResponse.h @@ -24,10 +24,9 @@ #include #include -#include - #include #include +#include namespace olp { namespace http { @@ -162,7 +161,7 @@ class CORE_API NetworkResponse final { * * @return Diagnostic values. */ - const boost::optional& GetDiagnostics() const; + const porting::optional& GetDiagnostics() const; /** * @brief Sets the request diagnostics. @@ -185,7 +184,7 @@ class CORE_API NetworkResponse final { /// The number of bytes downloaded during the network request. uint64_t bytes_downloaded_{0}; /// Diagnostics - boost::optional diagnostics_; + porting::optional diagnostics_; }; } // namespace http diff --git a/olp-cpp-sdk-core/include/olp/core/logging/FilterGroup.h b/olp-cpp-sdk-core/include/olp/core/logging/FilterGroup.h index d388a3331..881975972 100644 --- a/olp-cpp-sdk-core/include/olp/core/logging/FilterGroup.h +++ b/olp-cpp-sdk-core/include/olp/core/logging/FilterGroup.h @@ -24,11 +24,9 @@ #include #include -#include -#include - #include #include +#include namespace olp { namespace logging { @@ -56,9 +54,9 @@ class CORE_API FilterGroup { /** * @brief Gets the default log level. * - * @return The default log level or `boost::none` if the level is not set. + * @return The default log level or `olp::porting::none` if the level is not set. */ - inline boost::optional getLevel() const; + inline porting::optional getLevel() const; /** * @brief Sets the default log level. @@ -80,9 +78,9 @@ class CORE_API FilterGroup { * * @param tag The tag for which to get the log level. * - * @return The log level for the tag, or `boost::none` if the level is not set. + * @return The log level for the tag, or `olp::porting::none` if the level is not set. */ - inline boost::optional getLevel(const std::string& tag) const; + inline porting::optional getLevel(const std::string& tag) const; /** * @brief Sets the log level for a tag. @@ -148,16 +146,16 @@ class CORE_API FilterGroup { * * @return The converted level. */ - static boost::optional stringToLevel(const std::string& levelStr); + static porting::optional stringToLevel(const std::string& levelStr); private: friend class Log; - boost::optional m_defaultLevel; + porting::optional m_defaultLevel; std::unordered_map m_tagLevels; }; -inline FilterGroup::FilterGroup() : m_defaultLevel(boost::none) {} +inline FilterGroup::FilterGroup() : m_defaultLevel(porting::none) {} inline FilterGroup::FilterGroup(FilterGroup&& other) noexcept : m_defaultLevel(std::move(other.m_defaultLevel)), @@ -169,7 +167,7 @@ inline FilterGroup& FilterGroup::operator=(FilterGroup&& other) noexcept { return *this; } -inline boost::optional FilterGroup::getLevel() const { +inline porting::optional FilterGroup::getLevel() const { return m_defaultLevel; } @@ -179,14 +177,14 @@ inline FilterGroup& FilterGroup::setLevel(Level level) { } inline FilterGroup& FilterGroup::clearLevel() { - m_defaultLevel = boost::none; + m_defaultLevel = porting::none; return *this; } -inline boost::optional FilterGroup::getLevel( +inline porting::optional FilterGroup::getLevel( const std::string& tag) const { auto foundIter = m_tagLevels.find(tag); - if (foundIter == m_tagLevels.end()) return boost::none; + if (foundIter == m_tagLevels.end()) return porting::none; return foundIter->second; } @@ -201,7 +199,7 @@ inline FilterGroup& FilterGroup::clearLevel(const std::string& tag) { } inline FilterGroup& FilterGroup::clear() { - m_defaultLevel = boost::none; + m_defaultLevel = porting::none; m_tagLevels.clear(); return *this; } diff --git a/olp-cpp-sdk-core/include/olp/core/logging/Log.h b/olp-cpp-sdk-core/include/olp/core/logging/Log.h index be42f31fd..2e5a520fb 100644 --- a/olp-cpp-sdk-core/include/olp/core/logging/Log.h +++ b/olp-cpp-sdk-core/include/olp/core/logging/Log.h @@ -28,10 +28,9 @@ #include #include +#include #include -#include - /** * @file * @brief Provides the main interface for the logging library. @@ -498,7 +497,7 @@ class CORE_API Log { * @return The log level for the tag or `core::None` if the log level is * unset. */ - static boost::optional getLevel(const std::string& tag); + static porting::optional getLevel(const std::string& tag); /** * @brief Clears the log level for a tag and sets it to diff --git a/olp-cpp-sdk-core/include/olp/core/porting/optional.hpp b/olp-cpp-sdk-core/include/olp/core/porting/optional.hpp new file mode 100644 index 000000000..7afdc4c80 --- /dev/null +++ b/olp-cpp-sdk-core/include/olp/core/porting/optional.hpp @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2025 HERE Europe B.V. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * License-Filename: LICENSE + */ + +#pragma once + +#if (__cplusplus >= 201703L) && !defined(OLP_CPP_SDK_USE_BOOST_OPTIONAL) +#include + +namespace olp { +namespace porting { + +template +using optional = std::optional; +constexpr auto none = std::nullopt; + +template +constexpr auto value_or(const optional& opt, U&& def) { + return opt.value_or(std::forward(def)); +} + +template +constexpr const T* get_ptr(const optional& opt) { + return opt ? &*opt : nullptr; +} + +template +constexpr T* get_ptr(optional& opt) { + return opt ? &*opt : nullptr; +} + +template +optional> make_optional(T&& v) { + return optional>(std::forward(v)); +} + +} // namespace porting +} // namespace olp + +#else +#include + +namespace olp { +namespace porting { + +template +using optional = boost::optional; + +constexpr auto none = boost::none; + +template +constexpr typename optional::reference_const_type value_or( + const optional& opt, typename optional::reference_const_type def) { + return opt.get_value_or(def); +} + +template +constexpr typename optional::reference_type value_or( + optional& opt, typename optional::reference_type def) { + return opt.get_value_or(def); +} + +template +constexpr typename optional::pointer_const_type get_ptr( + const optional& opt) { + return opt.get_ptr(); +} + +template +constexpr typename optional::pointer_type get_ptr(optional& opt) { + return opt.get_ptr(); +} + +template +optional::type> make_optional(T&& v) { + return optional::type>( + boost::forward(v)); +} + +} // namespace porting +} // namespace olp + +#endif diff --git a/olp-cpp-sdk-core/include/olp/core/utils/Url.h b/olp-cpp-sdk-core/include/olp/core/utils/Url.h index 1d8374e10..e630e1a98 100644 --- a/olp-cpp-sdk-core/include/olp/core/utils/Url.h +++ b/olp-cpp-sdk-core/include/olp/core/utils/Url.h @@ -25,7 +25,7 @@ #include #include -#include +#include namespace olp { namespace utils { @@ -79,9 +79,9 @@ class CORE_API Url { * @param url Full URL. * * @return An optional pair representing host part and the rest of URL. - * Returns boost::none when url cannot be split. + * Returns olp::porting::none when url cannot be split. */ - static boost::optional ParseHostAndRest(const std::string& url); + static porting::optional ParseHostAndRest(const std::string& url); }; } // namespace utils diff --git a/olp-cpp-sdk-core/src/cache/DefaultCacheImpl.cpp b/olp-cpp-sdk-core/src/cache/DefaultCacheImpl.cpp index 2922d86ab..2d1bfd04f 100644 --- a/olp-cpp-sdk-core/src/cache/DefaultCacheImpl.cpp +++ b/olp-cpp-sdk-core/src/cache/DefaultCacheImpl.cpp @@ -763,36 +763,36 @@ DefaultCache::StorageOpenResult DefaultCacheImpl::SetupProtectedCache() { OpenOptions open_mode = settings_.openOptions; bool is_read_only = (settings_.openOptions & ReadOnly) == ReadOnly; if (!is_read_only) { - if (utils::Dir::IsReadOnly(settings_.disk_path_protected.get())) { + if (utils::Dir::IsReadOnly(*settings_.disk_path_protected)) { OLP_SDK_LOG_INFO_F(kLogTag, "R/W permission missing, opening protected cache in " "r/o mode, disk_path_protected='%s'", - settings_.disk_path_protected.get().c_str()); + settings_.disk_path_protected->c_str()); open_mode = static_cast(open_mode | OpenOptions::ReadOnly); is_read_only = true; } } auto status = protected_cache_->Open( - settings_.disk_path_protected.get(), settings_.disk_path_protected.get(), + *settings_.disk_path_protected, *settings_.disk_path_protected, protected_storage_settings, open_mode, false); if (status == OpenResult::IOError && !is_read_only) { OLP_SDK_LOG_INFO_F( kLogTag, "Failed to open in r/w mode, trying r/o, disk_path_protected='%s'", - settings_.disk_path_protected.get().c_str()); + settings_.disk_path_protected->c_str()); open_mode = static_cast(open_mode | OpenOptions::ReadOnly); status = - protected_cache_->Open(settings_.disk_path_protected.get(), - settings_.disk_path_protected.get(), + protected_cache_->Open(*settings_.disk_path_protected, + *settings_.disk_path_protected, protected_storage_settings, open_mode, false); } if (status != OpenResult::Success) { OLP_SDK_LOG_ERROR_F(kLogTag, "Failed to open protected cache %s", - settings_.disk_path_protected.get().c_str()); + settings_.disk_path_protected->c_str()); protected_cache_.reset(); return ToStorageOpenResult(status); @@ -805,14 +805,14 @@ DefaultCache::StorageOpenResult DefaultCacheImpl::SetupMutableCache() { auto storage_settings = CreateStorageSettings(settings_); mutable_cache_ = std::make_unique(settings_.extend_permissions); - auto status = mutable_cache_->Open(settings_.disk_path_mutable.get(), - settings_.disk_path_mutable.get(), + auto status = mutable_cache_->Open(*settings_.disk_path_mutable, + *settings_.disk_path_mutable, storage_settings, settings_.openOptions); if (status == OpenResult::Repaired) { OLP_SDK_LOG_INFO(kLogTag, "Mutable cache was repaired"); } else if (status == OpenResult::Fail) { OLP_SDK_LOG_ERROR_F(kLogTag, "Failed to open the mutable cache %s", - settings_.disk_path_mutable.get().c_str()); + settings_.disk_path_mutable->c_str()); mutable_cache_.reset(); return StorageOpenResult::OpenDiskPathFailure; @@ -913,7 +913,7 @@ OperationOutcomeEmpty DefaultCacheImpl::GetFromDiskCache( return client::ApiError::NotFound(); } -boost::optional> +porting::optional> DefaultCacheImpl::GetFromDiscCache(const std::string& key) { KeyValueCache::ValueTypePtr value = nullptr; time_t expiry = KeyValueCache::kDefaultExpiry; @@ -922,7 +922,7 @@ DefaultCacheImpl::GetFromDiscCache(const std::string& key) { return std::make_pair(std::string(value->begin(), value->end()), expiry); } - return boost::none; + return porting::none; } std::string DefaultCacheImpl::GetExpiryKey(const std::string& key) const { diff --git a/olp-cpp-sdk-core/src/cache/DefaultCacheImpl.h b/olp-cpp-sdk-core/src/cache/DefaultCacheImpl.h index 6abefbb15..9060902d5 100644 --- a/olp-cpp-sdk-core/src/cache/DefaultCacheImpl.h +++ b/olp-cpp-sdk-core/src/cache/DefaultCacheImpl.h @@ -176,7 +176,7 @@ class DefaultCacheImpl { KeyValueCache::ValueTypePtr& value, time_t& expiry); - boost::optional> GetFromDiscCache( + porting::optional> GetFromDiscCache( const std::string& key); time_t GetExpiryForMemoryCache(const std::string& key, diff --git a/olp-cpp-sdk-core/src/cache/KeyGenerator.cpp b/olp-cpp-sdk-core/src/cache/KeyGenerator.cpp index b64947a10..8b92ee391 100644 --- a/olp-cpp-sdk-core/src/cache/KeyGenerator.cpp +++ b/olp-cpp-sdk-core/src/cache/KeyGenerator.cpp @@ -43,7 +43,7 @@ std::string KeyGenerator::CreateLatestVersionKey(const std::string& hrn) { std::string KeyGenerator::CreatePartitionKey( const std::string& hrn, const std::string& layer_id, - const std::string& partition_id, const boost::optional& version) { + const std::string& partition_id, const porting::optional& version) { // Key format: hrn::layer_id::partition_id::[version::]partition std::string version_str = @@ -69,7 +69,7 @@ std::string KeyGenerator::CreatePartitionKey( std::string KeyGenerator::CreatePartitionsKey( const std::string& hrn, const std::string& layer_id, - const boost::optional& version) { + const porting::optional& version) { return hrn + "::" + layer_id + "::" + (version ? std::to_string(*version) + "::" : "") + "partitions"; } @@ -81,7 +81,7 @@ std::string KeyGenerator::CreateLayerVersionsKey(const std::string& hrn, std::string KeyGenerator::CreateQuadTreeKey( const std::string& hrn, const std::string& layer_id, olp::geo::TileKey root, - const boost::optional& version, int32_t depth) { + const porting::optional& version, int32_t depth) { return hrn + "::" + layer_id + "::" + root.ToHereTile() + "::" + (version ? std::to_string(*version) + "::" : "") + std::to_string(depth) + "::quadtree"; diff --git a/olp-cpp-sdk-core/src/client/ApiLookupClientImpl.cpp b/olp-cpp-sdk-core/src/client/ApiLookupClientImpl.cpp index d50b259e9..0210ca073 100644 --- a/olp-cpp-sdk-core/src/client/ApiLookupClientImpl.cpp +++ b/olp-cpp-sdk-core/src/client/ApiLookupClientImpl.cpp @@ -224,7 +224,7 @@ CancellationToken ApiLookupClientImpl::LookupApi( OlpClient ApiLookupClientImpl::CreateAndCacheClient( const std::string& base_url, const std::string& cache_key, - boost::optional expiration) { + porting::optional expiration) { const auto new_expiration = std::chrono::steady_clock::now() + std::chrono::seconds(expiration.value_or(kLookupApiDefaultExpiryTime)); @@ -250,7 +250,7 @@ OlpClient ApiLookupClientImpl::CreateAndCacheClient( return client_with_expiration.client; } -boost::optional ApiLookupClientImpl::GetCachedClient( +porting::optional ApiLookupClientImpl::GetCachedClient( const std::string& service, const std::string& service_version) { const std::string key = ClientCacheKey(service, service_version); @@ -278,7 +278,7 @@ boost::optional ApiLookupClientImpl::GetCachedClient( OLP_SDK_LOG_DEBUG_F( kLogTag, "LookupApi(%s/%s) cache miss in disk cache, hrn='%s'", service.c_str(), service_version.c_str(), catalog_string_.c_str()); - return boost::none; + return porting::none; } // When the service url is retrieved from disk cache we assume it is valid for diff --git a/olp-cpp-sdk-core/src/client/ApiLookupClientImpl.h b/olp-cpp-sdk-core/src/client/ApiLookupClientImpl.h index 21b07aa3a..14a6a8564 100644 --- a/olp-cpp-sdk-core/src/client/ApiLookupClientImpl.h +++ b/olp-cpp-sdk-core/src/client/ApiLookupClientImpl.h @@ -49,7 +49,7 @@ class ApiLookupClientImpl { ApiLookupClient::LookupApiCallback callback); protected: - using ApisResult = std::pair>; + using ApisResult = std::pair>; struct ClientWithExpiration { OlpClient client; @@ -58,9 +58,9 @@ class ApiLookupClientImpl { OlpClient CreateAndCacheClient(const std::string& base_url, const std::string& cache_key, - boost::optional expiration); + porting::optional expiration); - boost::optional GetCachedClient( + porting::optional GetCachedClient( const std::string& service, const std::string& service_version); void PutToDiskCache(const ApisResult& available_services); diff --git a/olp-cpp-sdk-core/src/client/OlpClient.cpp b/olp-cpp-sdk-core/src/client/OlpClient.cpp index cb4739216..6375bb158 100644 --- a/olp-cpp-sdk-core/src/client/OlpClient.cpp +++ b/olp-cpp-sdk-core/src/client/OlpClient.cpp @@ -488,7 +488,7 @@ class OlpClient::OlpClientImpl { const ParametersType& query_params, const ParametersType& header_params, const RequestBodyType& post_body, const std::string& content_type) const; - boost::optional AddBearer(bool query_empty, + porting::optional AddBearer(bool query_empty, http::NetworkRequest& request, CancellationContext& context) const; @@ -526,19 +526,19 @@ OlpClient::OlpClientImpl::GetMutableDefaultHeaders() { return default_headers_; } -boost::optional OlpClient::OlpClientImpl::AddBearer( +porting::optional OlpClient::OlpClientImpl::AddBearer( bool query_empty, http::NetworkRequest& request, CancellationContext& context) const { const auto& settings = settings_.authentication_settings; if (!settings) { - return boost::none; + return porting::none; } if (settings->api_key_provider) { const auto& api_key = settings->api_key_provider(); request.WithUrl(request.GetUrl() + (query_empty ? "?" : "&") + kApiKeyParam + api_key); - return boost::none; + return porting::none; } std::string token; @@ -552,7 +552,7 @@ boost::optional OlpClient::OlpClientImpl::AddBearer( token = response.GetResult().GetAccessToken(); } else { // There is no token provider defined. - return boost::none; + return porting::none; } if (token.empty()) { @@ -563,7 +563,7 @@ boost::optional OlpClient::OlpClientImpl::AddBearer( request.WithHeader(http::kAuthorizationHeader, http::kBearer + std::string(" ") + token); - return boost::none; + return porting::none; } bool OlpClient::OlpClientImpl::ValidateBaseUrl() const { diff --git a/olp-cpp-sdk-core/src/client/OlpClientSettingsFactory.cpp b/olp-cpp-sdk-core/src/client/OlpClientSettingsFactory.cpp index f49c7869a..5bc1a2ab8 100644 --- a/olp-cpp-sdk-core/src/client/OlpClientSettingsFactory.cpp +++ b/olp-cpp-sdk-core/src/client/OlpClientSettingsFactory.cpp @@ -65,8 +65,8 @@ OlpClientSettingsFactory::CreateDefaultCache(cache::CacheSettings settings) { kLogTag, "Error opening disk cache, disk_path_mutable=%s, " "disk_path_protected=%s", - settings.disk_path_mutable.get_value_or("(empty)").c_str(), - settings.disk_path_protected.get_value_or("(empty)").c_str()); + porting::value_or(settings.disk_path_mutable, "(empty)").c_str(), + porting::value_or(settings.disk_path_protected, "(empty)").c_str()); return nullptr; } return cache; diff --git a/olp-cpp-sdk-core/src/client/api/PlatformApi.cpp b/olp-cpp-sdk-core/src/client/api/PlatformApi.cpp index 79560672d..fe4a15206 100644 --- a/olp-cpp-sdk-core/src/client/api/PlatformApi.cpp +++ b/olp-cpp-sdk-core/src/client/api/PlatformApi.cpp @@ -37,20 +37,20 @@ namespace { using NetworkUtils = olp::http::NetworkUtils; const std::string kExpiryHeader = "cache-control"; -boost::optional GetExpiry(const olp::http::Headers& headers) { +olp::porting::optional GetExpiry(const olp::http::Headers& headers) { auto it = std::find_if(headers.begin(), headers.end(), [](const olp::http::Header& header) { return NetworkUtils::CaseInsensitiveCompare( header.first, kExpiryHeader); }); if (it == headers.end()) { - return boost::none; + return olp::porting::none; } const auto& expiry_str = it->second; std::size_t index = NetworkUtils::CaseInsensitiveFind(expiry_str, "max-age="); if (index == std::string::npos) { - return boost::none; + return olp::porting::none; } auto expiry = std::stoi(expiry_str.substr(index + 8)); diff --git a/olp-cpp-sdk-core/src/client/api/PlatformApi.h b/olp-cpp-sdk-core/src/client/api/PlatformApi.h index b12e645d8..0dbcdfef3 100644 --- a/olp-cpp-sdk-core/src/client/api/PlatformApi.h +++ b/olp-cpp-sdk-core/src/client/api/PlatformApi.h @@ -25,7 +25,7 @@ #include #include #include -#include +#include namespace olp { namespace client { @@ -37,7 +37,7 @@ class CancellationContext; */ class PlatformApi { public: - using ApisResult = std::pair>; + using ApisResult = std::pair>; using ApisResponse = ApiResponse; using ApisCallback = std::function; diff --git a/olp-cpp-sdk-core/src/client/api/ResourcesApi.cpp b/olp-cpp-sdk-core/src/client/api/ResourcesApi.cpp index e6c6b08a9..0ad6ddc02 100644 --- a/olp-cpp-sdk-core/src/client/api/ResourcesApi.cpp +++ b/olp-cpp-sdk-core/src/client/api/ResourcesApi.cpp @@ -35,20 +35,20 @@ namespace { using NetworkUtils = olp::http::NetworkUtils; const std::string kExpiryHeader = "cache-control"; -boost::optional GetExpiry(const olp::http::Headers& headers) { +olp::porting::optional GetExpiry(const olp::http::Headers& headers) { auto it = std::find_if(headers.begin(), headers.end(), [](const olp::http::Header& header) { return NetworkUtils::CaseInsensitiveCompare( header.first, kExpiryHeader); }); if (it == headers.end()) { - return boost::none; + return olp::porting::none; } const auto& expiry_str = it->second; std::size_t index = NetworkUtils::CaseInsensitiveFind(expiry_str, "max-age="); if (index == std::string::npos) { - return boost::none; + return olp::porting::none; } auto expiry = std::stoi(expiry_str.substr(index + 8)); diff --git a/olp-cpp-sdk-core/src/client/api/ResourcesApi.h b/olp-cpp-sdk-core/src/client/api/ResourcesApi.h index d10ca6a33..24535f8ec 100644 --- a/olp-cpp-sdk-core/src/client/api/ResourcesApi.h +++ b/olp-cpp-sdk-core/src/client/api/ResourcesApi.h @@ -25,7 +25,7 @@ #include #include #include -#include +#include namespace olp { namespace client { @@ -37,7 +37,7 @@ class CancellationContext; */ class ResourcesApi { public: - using ApisResult = std::pair>; + using ApisResult = std::pair>; using ApisResponse = ApiResponse; using ApisCallback = std::function; diff --git a/olp-cpp-sdk-core/src/client/repository/ApiCacheRepository.cpp b/olp-cpp-sdk-core/src/client/repository/ApiCacheRepository.cpp index 8393e78f2..a978f122c 100644 --- a/olp-cpp-sdk-core/src/client/repository/ApiCacheRepository.cpp +++ b/olp-cpp-sdk-core/src/client/repository/ApiCacheRepository.cpp @@ -37,22 +37,22 @@ ApiCacheRepository::ApiCacheRepository( void ApiCacheRepository::Put(const std::string& service, const std::string& version, const std::string& url, - boost::optional expiry) { + porting::optional expiry) { const auto key = cache::KeyGenerator::CreateApiKey(hrn_, service, version); OLP_SDK_LOG_TRACE_F(kLogTag, "Put -> '%s'", key.c_str()); cache_->Put(key, url, [&]() { return url; }, - expiry.get_value_or(kLookupApiExpiryTime)); + porting::value_or(expiry, kLookupApiExpiryTime)); } -boost::optional ApiCacheRepository::Get( +porting::optional ApiCacheRepository::Get( const std::string& service, const std::string& version) { const auto key = cache::KeyGenerator::CreateApiKey(hrn_, service, version); OLP_SDK_LOG_TRACE_F(kLogTag, "Get -> '%s'", key.c_str()); auto url = cache_->Get(key, [](const std::string& value) { return value; }); if (url.empty()) { - return boost::none; + return porting::none; } return boost::any_cast(url); diff --git a/olp-cpp-sdk-core/src/client/repository/ApiCacheRepository.h b/olp-cpp-sdk-core/src/client/repository/ApiCacheRepository.h index 4e94bf819..73cc00e49 100644 --- a/olp-cpp-sdk-core/src/client/repository/ApiCacheRepository.h +++ b/olp-cpp-sdk-core/src/client/repository/ApiCacheRepository.h @@ -24,7 +24,7 @@ #include #include -#include +#include namespace olp { namespace cache { @@ -41,9 +41,9 @@ class ApiCacheRepository final { ~ApiCacheRepository() = default; void Put(const std::string& service, const std::string& version, - const std::string& url, boost::optional expiry); + const std::string& url, porting::optional expiry); - boost::optional Get(const std::string& service, + porting::optional Get(const std::string& service, const std::string& version); private: diff --git a/olp-cpp-sdk-core/src/context/Context.cpp b/olp-cpp-sdk-core/src/context/Context.cpp index 45f3e4ce9..85721cae6 100644 --- a/olp-cpp-sdk-core/src/context/Context.cpp +++ b/olp-cpp-sdk-core/src/context/Context.cpp @@ -19,7 +19,7 @@ #include -#include +#include #include #include #include diff --git a/olp-cpp-sdk-core/src/geo/tiling/TileKey.cpp b/olp-cpp-sdk-core/src/geo/tiling/TileKey.cpp index d8037e305..9a5b625fb 100644 --- a/olp-cpp-sdk-core/src/geo/tiling/TileKey.cpp +++ b/olp-cpp-sdk-core/src/geo/tiling/TileKey.cpp @@ -297,9 +297,9 @@ TileKey::TileKeyQuadrant TileKey::RelationshipToParent() const { Column() - sw_tile.Column()); } -boost::optional GetMinTileKeyLevel(const TileKeyLevels& levels) { +porting::optional GetMinTileKeyLevel(const TileKeyLevels& levels) { if (levels.none()) { - return boost::none; + return porting::none; } const auto level_bits = levels.to_ulong(); @@ -319,20 +319,20 @@ boost::optional GetMinTileKeyLevel(const TileKeyLevels& levels) { PORTING_POP_WARNINGS(); } -boost::optional GetMaxTileKeyLevel(const TileKeyLevels& levels) { +porting::optional GetMaxTileKeyLevel(const TileKeyLevels& levels) { if (levels.none()) { - return boost::none; + return porting::none; } return static_cast(std::log2(levels.to_ulong())); } -boost::optional GetNearestAvailableTileKeyLevel( +porting::optional GetNearestAvailableTileKeyLevel( const TileKeyLevels& levels, const std::uint32_t reference_level) { const auto min_level = geo::GetMinTileKeyLevel(levels); const auto max_level = geo::GetMaxTileKeyLevel(levels); if (!min_level || !max_level) { - return boost::none; + return porting::none; } int level = std::max(std::min(reference_level, *max_level), *min_level); diff --git a/olp-cpp-sdk-core/src/http/NetworkResponse.cpp b/olp-cpp-sdk-core/src/http/NetworkResponse.cpp index 157b5b297..80692be5c 100644 --- a/olp-cpp-sdk-core/src/http/NetworkResponse.cpp +++ b/olp-cpp-sdk-core/src/http/NetworkResponse.cpp @@ -70,7 +70,7 @@ NetworkResponse& NetworkResponse::WithDiagnostics(Diagnostics diagnostics) { return *this; } -const boost::optional& NetworkResponse::GetDiagnostics() const { +const porting::optional& NetworkResponse::GetDiagnostics() const { return diagnostics_; } diff --git a/olp-cpp-sdk-core/src/http/curl/NetworkCurl.cpp b/olp-cpp-sdk-core/src/http/curl/NetworkCurl.cpp index 7590296f2..83f518e82 100644 --- a/olp-cpp-sdk-core/src/http/curl/NetworkCurl.cpp +++ b/olp-cpp-sdk-core/src/http/curl/NetworkCurl.cpp @@ -760,12 +760,15 @@ ErrorCode NetworkCurl::SendImplementation( #ifdef OLP_SDK_CURL_HAS_SUPPORT_SSL_BLOBS if (ssl_certificates_blobs_) { - curl_easy_setopt(curl_handle, CURLOPT_SSLCERT_BLOB, - ssl_certificates_blobs_->ssl_cert_blob.get_ptr()); - curl_easy_setopt(curl_handle, CURLOPT_SSLKEY_BLOB, - ssl_certificates_blobs_->ssl_key_blob.get_ptr()); - curl_easy_setopt(curl_handle, CURLOPT_CAINFO_BLOB, - ssl_certificates_blobs_->ca_info_blob.get_ptr()); + curl_easy_setopt( + curl_handle, CURLOPT_SSLCERT_BLOB, + olp::porting::get_ptr(ssl_certificates_blobs_->ssl_cert_blob)); + curl_easy_setopt( + curl_handle, CURLOPT_SSLKEY_BLOB, + olp::porting::get_ptr(ssl_certificates_blobs_->ssl_key_blob)); + curl_easy_setopt( + curl_handle, CURLOPT_CAINFO_BLOB, + olp::porting::get_ptr(ssl_certificates_blobs_->ca_info_blob)); } else #endif { diff --git a/olp-cpp-sdk-core/src/http/curl/NetworkCurl.h b/olp-cpp-sdk-core/src/http/curl/NetworkCurl.h index 5969530b4..c55b155b7 100644 --- a/olp-cpp-sdk-core/src/http/curl/NetworkCurl.h +++ b/olp-cpp-sdk-core/src/http/curl/NetworkCurl.h @@ -31,7 +31,7 @@ #include #include -#include +#include #if defined(OLP_SDK_ENABLE_ANDROID_CURL) && !defined(ANDROID_HOST) #include @@ -165,7 +165,7 @@ class NetworkCurl : public Network, * @brief Blobs required for custom certificate validation. */ struct SslCertificateBlobs { - using OptionalBlob = boost::optional; + using OptionalBlob = porting::optional; /// Certificate blob. OptionalBlob ssl_cert_blob; @@ -375,7 +375,7 @@ class NetworkCurl : public Network, #ifdef OLP_SDK_CURL_HAS_SUPPORT_SSL_BLOBS /// SSL certificate blobs. - boost::optional ssl_certificates_blobs_; + porting::optional ssl_certificates_blobs_; #endif }; diff --git a/olp-cpp-sdk-core/src/logging/FilterGroup.cpp b/olp-cpp-sdk-core/src/logging/FilterGroup.cpp index 1a117662c..8c952940d 100644 --- a/olp-cpp-sdk-core/src/logging/FilterGroup.cpp +++ b/olp-cpp-sdk-core/src/logging/FilterGroup.cpp @@ -59,7 +59,7 @@ static bool equalsIgnoreCase(const std::string& left, #endif } -boost::optional FilterGroup::stringToLevel(const std::string& levelStr) { +porting::optional FilterGroup::stringToLevel(const std::string& levelStr) { if (equalsIgnoreCase(levelStr, "trace")) return Level::Trace; else if (equalsIgnoreCase(levelStr, "debug")) @@ -75,7 +75,7 @@ boost::optional FilterGroup::stringToLevel(const std::string& levelStr) { else if (equalsIgnoreCase(levelStr, "off")) return Level::Off; else - return boost::none; + return porting::none; } bool FilterGroup::load(const std::string& fileName) { @@ -99,7 +99,7 @@ bool FilterGroup::load(std::istream& stream) { std::string tag = trim(splitLine.first); std::string levelStr = trim(splitLine.second); - boost::optional level = stringToLevel(levelStr); + porting::optional level = stringToLevel(levelStr); if (!level) return false; if (tag.empty()) diff --git a/olp-cpp-sdk-core/src/logging/Log.cpp b/olp-cpp-sdk-core/src/logging/Log.cpp index 93f0fb040..2fff401e4 100644 --- a/olp-cpp-sdk-core/src/logging/Log.cpp +++ b/olp-cpp-sdk-core/src/logging/Log.cpp @@ -55,7 +55,7 @@ class LogImpl { void setLevel(Level level); Level getLevel() const; void setLevel(Level level, const std::string& tag); - boost::optional getLevel(const std::string& tag) const; + porting::optional getLevel(const std::string& tag) const; void clearLevel(const std::string& tag); void clearLevels(); @@ -119,12 +119,12 @@ void LogImpl::setLevel(Level level, const std::string& tag) { m_logLevels[tag] = level; } -boost::optional LogImpl::getLevel(const std::string& tag) const { +porting::optional LogImpl::getLevel(const std::string& tag) const { if (tag.empty()) return getLevel(); auto foundIter = m_logLevels.find(tag); if (foundIter == m_logLevels.end()) - return boost::none; + return porting::none; else return foundIter->second; } @@ -229,8 +229,8 @@ void Log::setLevel(const std::string& level, const std::string& tag) { [&log_level, &tag](LogImpl& log) { log.setLevel(*log_level, tag); }); } -boost::optional Log::getLevel(const std::string& tag) { - if (!LogImpl::aliveStatus()) return boost::none; +porting::optional Log::getLevel(const std::string& tag) { + if (!LogImpl::aliveStatus()) return porting::none; return LogImpl::getInstance().locked( [&tag](const LogImpl& log) { return log.getLevel(tag); }); diff --git a/olp-cpp-sdk-core/src/utils/Url.cpp b/olp-cpp-sdk-core/src/utils/Url.cpp index 26b6e477b..503c14e57 100644 --- a/olp-cpp-sdk-core/src/utils/Url.cpp +++ b/olp-cpp-sdk-core/src/utils/Url.cpp @@ -125,14 +125,14 @@ std::string Url::Construct( return url_ss.str(); } -boost::optional Url::ParseHostAndRest( +porting::optional Url::ParseHostAndRest( const std::string& url) { const auto host_and_rest_regex = R"(^(.*:\/\/[A-Za-z0-9\-\.]+(:[0-9]+)?)(.*)$)"; std::regex regex{host_and_rest_regex}; std::smatch match; if (!std::regex_search(url, match, regex) || match.size() != 4) { - return boost::none; + return porting::none; } const auto host = std::string{match[1]}; diff --git a/olp-cpp-sdk-core/tests/cache/DefaultCacheImplTest.cpp b/olp-cpp-sdk-core/tests/cache/DefaultCacheImplTest.cpp index e78454d87..48436204d 100644 --- a/olp-cpp-sdk-core/tests/cache/DefaultCacheImplTest.cpp +++ b/olp-cpp-sdk-core/tests/cache/DefaultCacheImplTest.cpp @@ -1100,7 +1100,7 @@ TEST_F(DefaultCacheImplTest, ProtectTestWithoutMutableCache) { ASSERT_FALSE(cache.Release({key1})); ASSERT_FALSE(cache.Protect({key1})); cache.Close(); - ASSERT_TRUE(olp::utils::Dir::Remove(settings.disk_path_protected.get())); + ASSERT_TRUE(olp::utils::Dir::Remove(*settings.disk_path_protected)); } } @@ -1364,7 +1364,7 @@ TEST_F(DefaultCacheImplTest, ProtectedCacheSize) { cache.Compact(); } - settings.disk_path_mutable = boost::none; + settings.disk_path_mutable = olp::porting::none; } const uint64_t actual_size_on_disk = GetCacheSizeOnDisk(); @@ -1390,8 +1390,8 @@ TEST_F(DefaultCacheImplTest, ProtectedCacheSize) { struct OpenTestParameters { olp::cache::DefaultCache::StorageOpenResult expected_result; olp::cache::OpenOptions open_options; - boost::optional disk_path_mutable; - boost::optional disk_path_protected; + olp::porting::optional disk_path_mutable; + olp::porting::optional disk_path_protected; }; class DefaultCacheImplOpenTest @@ -1399,7 +1399,7 @@ class DefaultCacheImplOpenTest public testing::WithParamInterface {}; TEST_P(DefaultCacheImplOpenTest, ReadOnlyDir) { - const auto setup_dir = [&](const boost::optional& cache_path) { + const auto setup_dir = [&](const olp::porting::optional& cache_path) { if (cache_path) { if (olp::utils::Dir::Exists(*cache_path)) { ASSERT_TRUE(olp::utils::Dir::Remove(*cache_path)); @@ -1409,7 +1409,7 @@ TEST_P(DefaultCacheImplOpenTest, ReadOnlyDir) { } }; - const auto reset_dir = [&](const boost::optional& cache_path) { + const auto reset_dir = [&](const olp::porting::optional& cache_path) { if (cache_path) { ASSERT_TRUE(olp::utils::Dir::Remove(*cache_path)); } @@ -1435,13 +1435,13 @@ std::vector DefaultCacheImplOpenParams() { const std::string cache_path = olp::utils::Dir::TempDirectory() + "/unittest_readonly"; return {{olp::cache::DefaultCache::StorageOpenResult::Success, - olp::cache::OpenOptions::Default, boost::none, cache_path}, + olp::cache::OpenOptions::Default, olp::porting::none, cache_path}, {olp::cache::DefaultCache::StorageOpenResult::Success, - olp::cache::OpenOptions::ReadOnly, boost::none, cache_path}, + olp::cache::OpenOptions::ReadOnly, olp::porting::none, cache_path}, {olp::cache::DefaultCache::StorageOpenResult::OpenDiskPathFailure, - olp::cache::OpenOptions::Default, cache_path, boost::none}, + olp::cache::OpenOptions::Default, cache_path, olp::porting::none}, {olp::cache::DefaultCache::StorageOpenResult::OpenDiskPathFailure, - olp::cache::OpenOptions::ReadOnly, cache_path, boost::none}}; + olp::cache::OpenOptions::ReadOnly, cache_path, olp::porting::none}}; } INSTANTIATE_TEST_SUITE_P(, DefaultCacheImplOpenTest, diff --git a/olp-cpp-sdk-core/tests/cache/DefaultCacheTest.cpp b/olp-cpp-sdk-core/tests/cache/DefaultCacheTest.cpp index b3a593524..f93399c72 100644 --- a/olp-cpp-sdk-core/tests/cache/DefaultCacheTest.cpp +++ b/olp-cpp-sdk-core/tests/cache/DefaultCacheTest.cpp @@ -33,7 +33,7 @@ namespace { using CacheType = olp::cache::DefaultCache::CacheType; using KeyValueCache = olp::cache::KeyValueCache; -using OptionalString = boost::optional; +using OptionalString = olp::porting::optional; auto kDefaultExpiry = std::numeric_limits::max(); const auto kTempDirMutable = olp::utils::Dir::TempDirectory() + "/unittest"; @@ -751,7 +751,7 @@ TEST(DefaultCacheTest, OpenTypeCache) { struct TestParameters { OptionalString disk_path_mutable = kTempDirMutable; - OptionalString disk_path_protected = boost::none; + OptionalString disk_path_protected = olp::porting::none; size_t max_memory_cache_size = 1024u * 1024u; }; @@ -998,19 +998,19 @@ std::vector Configuration() { // Mutable, no protected, no in-memory params.disk_path_mutable = kTempDirMutable; - params.disk_path_protected = boost::none; + params.disk_path_protected = olp::porting::none; params.max_memory_cache_size = 0u; config.emplace_back(params); // Mutable, no protected, in-memory params.disk_path_mutable = kTempDirMutable; - params.disk_path_protected = boost::none; + params.disk_path_protected = olp::porting::none; params.max_memory_cache_size = 1024u * 1024u; config.emplace_back(params); // No mutable, no protected, in-memory - params.disk_path_mutable = boost::none; - params.disk_path_protected = boost::none; + params.disk_path_mutable = olp::porting::none; + params.disk_path_protected = olp::porting::none; params.max_memory_cache_size = 1024u * 1024u; config.emplace_back(params); diff --git a/olp-cpp-sdk-core/tests/cache/KeyGeneratorTest.cpp b/olp-cpp-sdk-core/tests/cache/KeyGeneratorTest.cpp index e86466542..07dddf915 100644 --- a/olp-cpp-sdk-core/tests/cache/KeyGeneratorTest.cpp +++ b/olp-cpp-sdk-core/tests/cache/KeyGeneratorTest.cpp @@ -106,7 +106,7 @@ TEST(KeyGeneratorTest, CreatePartitionKey) { SCOPED_TRACE("No version"); const auto key = KeyGenerator::CreatePartitionKey( - kCatalogHrn, kLayerName, kPartitionName, boost::none); + kCatalogHrn, kLayerName, kPartitionName, olp::porting::none); EXPECT_EQ(key, kCatalogHrn + "::" + kLayerName + "::" + kPartitionName + "::partition"); @@ -116,7 +116,7 @@ TEST(KeyGeneratorTest, CreatePartitionKey) { SCOPED_TRACE("Empty values"); // Not a special case, just make sure it will not crash. - const auto key = KeyGenerator::CreatePartitionKey("", "", "", boost::none); + const auto key = KeyGenerator::CreatePartitionKey("", "", "", olp::porting::none); EXPECT_EQ(key, "::::::partition"); } @@ -137,7 +137,7 @@ TEST(KeyGeneratorTest, CreatePatitionsKey) { SCOPED_TRACE("No version"); const auto key = - KeyGenerator::CreatePartitionsKey(kCatalogHrn, kLayerName, boost::none); + KeyGenerator::CreatePartitionsKey(kCatalogHrn, kLayerName, olp::porting::none); EXPECT_EQ(key, kCatalogHrn + "::" + kLayerName + "::partitions"); } @@ -146,7 +146,7 @@ TEST(KeyGeneratorTest, CreatePatitionsKey) { SCOPED_TRACE("Empty values"); // Not a special case, just make sure it will not crash. - const auto key = KeyGenerator::CreatePartitionsKey("", "", boost::none); + const auto key = KeyGenerator::CreatePartitionsKey("", "", olp::porting::none); EXPECT_EQ(key, "::::partitions"); } @@ -193,7 +193,7 @@ TEST(KeyGeneratorTest, CreateQuadTreeKey) { SCOPED_TRACE("No version"); const auto key = KeyGenerator::CreateQuadTreeKey( - kCatalogHrn, kLayerName, root_tile, boost::none, depth); + kCatalogHrn, kLayerName, root_tile, olp::porting::none, depth); EXPECT_EQ(key, kCatalogHrn + "::" + kLayerName + "::" + root_tile.ToHereTile() + @@ -205,7 +205,7 @@ TEST(KeyGeneratorTest, CreateQuadTreeKey) { // Not a special case, just make sure it will not crash. const auto key = - KeyGenerator::CreateQuadTreeKey("", "", root_tile, boost::none, depth); + KeyGenerator::CreateQuadTreeKey("", "", root_tile, olp::porting::none, depth); EXPECT_EQ(key, "::::" + root_tile.ToHereTile() + "::" + std::to_string(depth) + "::quadtree"); diff --git a/olp-cpp-sdk-core/tests/client/OlpClientTest.cpp b/olp-cpp-sdk-core/tests/client/OlpClientTest.cpp index 2d9df84d5..2f557af10 100644 --- a/olp-cpp-sdk-core/tests/client/OlpClientTest.cpp +++ b/olp-cpp-sdk-core/tests/client/OlpClientTest.cpp @@ -636,7 +636,7 @@ TEST_P(OlpClientTest, Proxy) { TEST_P(OlpClientTest, EmptyProxy) { auto network = network_; client_settings_.retry_settings.timeout = 100; - client_settings_.proxy_settings = boost::none; + client_settings_.proxy_settings = olp::porting::none; ASSERT_FALSE(client_settings_.proxy_settings); olp::http::NetworkProxySettings result_settings; diff --git a/olp-cpp-sdk-core/tests/logging/FilterGroupTest.cpp b/olp-cpp-sdk-core/tests/logging/FilterGroupTest.cpp index ca77b0f22..4edaca0a7 100644 --- a/olp-cpp-sdk-core/tests/logging/FilterGroupTest.cpp +++ b/olp-cpp-sdk-core/tests/logging/FilterGroupTest.cpp @@ -33,13 +33,13 @@ using olp::logging::Log; TEST(FilterGroupTest, DefaultLevel) { FilterGroup filter_group; - EXPECT_EQ(boost::none, filter_group.getLevel()); + EXPECT_EQ(olp::porting::none, filter_group.getLevel()); filter_group.setLevel(Level::Info); - ASSERT_NE(boost::none, filter_group.getLevel()); + ASSERT_NE(olp::porting::none, filter_group.getLevel()); EXPECT_EQ(Level::Info, *filter_group.getLevel()); filter_group.clearLevel(); - EXPECT_EQ(boost::none, filter_group.getLevel()); + EXPECT_EQ(olp::porting::none, filter_group.getLevel()); } TEST(FilterGroupTest, TagLevels) { @@ -47,20 +47,20 @@ TEST(FilterGroupTest, TagLevels) { filter_group.setLevel(Level::Info, "test1"); filter_group.setLevel(Level::Warning, "test2"); - ASSERT_NE(boost::none, filter_group.getLevel("test1")); + ASSERT_NE(olp::porting::none, filter_group.getLevel("test1")); EXPECT_EQ(Level::Info, *filter_group.getLevel("test1")); - ASSERT_NE(boost::none, filter_group.getLevel("test2")); + ASSERT_NE(olp::porting::none, filter_group.getLevel("test2")); EXPECT_EQ(Level::Warning, *filter_group.getLevel("test2")); - EXPECT_EQ(boost::none, filter_group.getLevel("asdf")); + EXPECT_EQ(olp::porting::none, filter_group.getLevel("asdf")); filter_group.setLevel(Level::Error, "test1"); - ASSERT_NE(boost::none, filter_group.getLevel("test1")); + ASSERT_NE(olp::porting::none, filter_group.getLevel("test1")); EXPECT_EQ(Level::Error, *filter_group.getLevel("test1")); filter_group.clearLevel("test1"); - EXPECT_EQ(boost::none, filter_group.getLevel("test1")); - ASSERT_NE(boost::none, filter_group.getLevel("test2")); + EXPECT_EQ(olp::porting::none, filter_group.getLevel("test1")); + ASSERT_NE(olp::porting::none, filter_group.getLevel("test2")); EXPECT_EQ(Level::Warning, *filter_group.getLevel("test2")); } @@ -71,9 +71,9 @@ TEST(FilterGroupTest, Clear) { filter_group.setLevel(Level::Warning, "test2"); filter_group.clear(); - EXPECT_EQ(boost::none, filter_group.getLevel()); - EXPECT_EQ(boost::none, filter_group.getLevel("test1")); - EXPECT_EQ(boost::none, filter_group.getLevel("test2")); + EXPECT_EQ(olp::porting::none, filter_group.getLevel()); + EXPECT_EQ(olp::porting::none, filter_group.getLevel("test1")); + EXPECT_EQ(olp::porting::none, filter_group.getLevel("test2")); } TEST(FilterGroupTest, Apply) { @@ -140,9 +140,9 @@ TEST(FilterGroupTest, LoadEmpty) { std::stringstream stream(""); EXPECT_TRUE(filter_group.load(stream)); - EXPECT_EQ(boost::none, filter_group.getLevel()); - EXPECT_EQ(boost::none, filter_group.getLevel("test1")); - EXPECT_EQ(boost::none, filter_group.getLevel("test2")); + EXPECT_EQ(olp::porting::none, filter_group.getLevel()); + EXPECT_EQ(olp::porting::none, filter_group.getLevel("test1")); + EXPECT_EQ(olp::porting::none, filter_group.getLevel("test2")); } TEST(FilterGroupTest, Load) { @@ -159,12 +159,12 @@ TEST(FilterGroupTest, Load) { ": info"); EXPECT_TRUE(filter_group.load(stream)); - ASSERT_NE(boost::none, filter_group.getLevel()); + ASSERT_NE(olp::porting::none, filter_group.getLevel()); EXPECT_EQ(Level::Info, *filter_group.getLevel()); - EXPECT_EQ(boost::none, filter_group.getLevel("test1")); - ASSERT_NE(boost::none, filter_group.getLevel("test2")); + EXPECT_EQ(olp::porting::none, filter_group.getLevel("test1")); + ASSERT_NE(olp::porting::none, filter_group.getLevel("test2")); EXPECT_EQ(Level::Error, *filter_group.getLevel("test2")); - ASSERT_NE(boost::none, filter_group.getLevel("test3")); + ASSERT_NE(olp::porting::none, filter_group.getLevel("test3")); EXPECT_EQ(Level::Off, *filter_group.getLevel("test3")); } @@ -177,9 +177,9 @@ TEST(FilterGroupTest, LoadBadSyntax) { { std::stringstream stream("asdf"); EXPECT_FALSE(filter_group.load(stream)); - EXPECT_EQ(boost::none, filter_group.getLevel()); - EXPECT_EQ(boost::none, filter_group.getLevel("test1")); - EXPECT_EQ(boost::none, filter_group.getLevel("test2")); + EXPECT_EQ(olp::porting::none, filter_group.getLevel()); + EXPECT_EQ(olp::porting::none, filter_group.getLevel("test1")); + EXPECT_EQ(olp::porting::none, filter_group.getLevel("test2")); } { diff --git a/olp-cpp-sdk-core/tests/logging/LogTest.cpp b/olp-cpp-sdk-core/tests/logging/LogTest.cpp index c93616908..d3c8d11e5 100644 --- a/olp-cpp-sdk-core/tests/logging/LogTest.cpp +++ b/olp-cpp-sdk-core/tests/logging/LogTest.cpp @@ -67,15 +67,15 @@ TEST(LogTest, Levels) { olp::logging::Log::clearLevel("test2"); EXPECT_EQ(olp::logging::Level::Debug, olp::logging::Log::getLevel("test1")); - EXPECT_EQ(boost::none, olp::logging::Log::getLevel("test2")); + EXPECT_EQ(olp::porting::none, olp::logging::Log::getLevel("test2")); EXPECT_TRUE( olp::logging::Log::isEnabled(olp::logging::Level::Warning, "test2")); EXPECT_FALSE( olp::logging::Log::isEnabled(olp::logging::Level::Debug, "test2")); olp::logging::Log::clearLevels(); - EXPECT_EQ(boost::none, olp::logging::Log::getLevel("test1")); - EXPECT_EQ(boost::none, olp::logging::Log::getLevel("test2")); + EXPECT_EQ(olp::porting::none, olp::logging::Log::getLevel("test1")); + EXPECT_EQ(olp::porting::none, olp::logging::Log::getLevel("test2")); EXPECT_TRUE( olp::logging::Log::isEnabled(olp::logging::Level::Warning, "test1")); EXPECT_FALSE(