Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ option(OLP_SDK_ENABLE_TESTING "Flag to enable/disable building unit and integrat
option(OLP_SDK_BUILD_DOC "Build SDK documentation" OFF)
option(OLP_SDK_NO_EXCEPTION "Disable exception handling" OFF)
option(OLP_SDK_USE_STD_OPTIONAL "Use std::optional instead of boost::optional with C++17 and above" OFF)
option(OLP_SDK_USE_STD_ANY "Use std::any instead of boost::any 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)
Expand Down
1 change: 1 addition & 0 deletions docs/get-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ cmake --build . --target docs
| `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_USE_STD_OPTIONAL` | Defaults to `OFF`. If enabled, all libraries are built with std::optional type instead of boost::optional for C++17 and above. |
| `OLP_SDK_USE_STD_ANY` | Defaults to `OFF`. If enabled, all libraries are built with std::any type instead of boost::any for C++17 and above. |
| `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. |
Expand Down
6 changes: 6 additions & 0 deletions olp-cpp-sdk-core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ set(OLP_SDK_PLATFORM_HEADERS
)

set(OLP_SDK_PORTING_HEADERS
./include/olp/core/porting/any.h
./include/olp/core/porting/deprecated.h
./include/olp/core/porting/export.h
./include/olp/core/porting/make_unique.h
Expand Down Expand Up @@ -450,6 +451,11 @@ if (OLP_SDK_USE_STD_OPTIONAL)
PUBLIC OLP_CPP_SDK_USE_STD_OPTIONAL)
endif()

if (OLP_SDK_USE_STD_ANY)
target_compile_definitions(${PROJECT_NAME}
PUBLIC OLP_SDK_USE_STD_ANY)
endif()

target_include_directories(${PROJECT_NAME} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
Expand Down
5 changes: 3 additions & 2 deletions olp-cpp-sdk-core/include/olp/core/cache/DefaultCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class CORE_API DefaultCache : public KeyValueCache {
*
* @return True if the operation is successful; false otherwise.
*/
bool Put(const std::string& key, const boost::any& value,
bool Put(const std::string& key, const olp::porting::any& value,
const Encoder& encoder, time_t expiry) override;

/**
Expand All @@ -181,7 +181,8 @@ class CORE_API DefaultCache : public KeyValueCache {
*
* @return The key-value pair.
*/
boost::any Get(const std::string& key, const Decoder& decoder) override;
olp::porting::any Get(const std::string& key,
const Decoder& decoder) override;

/**
* @brief Gets the key and binary data from the cache.
Expand Down
9 changes: 5 additions & 4 deletions olp-cpp-sdk-core/include/olp/core/cache/KeyValueCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@
#include <olp/core/client/ApiError.h>
#include <olp/core/client/ApiNoResult.h>
#include <olp/core/client/ApiResponse.h>
#include <olp/core/porting/any.h>
#include <olp/core/utils/WarningWorkarounds.h>
#include <boost/any.hpp>

namespace olp {
namespace cache {

using Encoder = std::function<std::string()>;
using Decoder = std::function<boost::any(const std::string&)>;
using Decoder = std::function<olp::porting::any(const std::string&)>;

template <typename Result>
using OperationOutcome = client::ApiResponse<Result, client::ApiError>;
Expand Down Expand Up @@ -74,7 +74,7 @@ class CORE_API KeyValueCache {
*
* @return True if the operation is successful; false otherwise.
*/
virtual bool Put(const std::string& key, const boost::any& value,
virtual bool Put(const std::string& key, const olp::porting::any& value,
const Encoder& encoder, time_t expiry = kDefaultExpiry) = 0;

/**
Expand All @@ -97,7 +97,8 @@ class CORE_API KeyValueCache {
*
* @return The key-value pair.
*/
virtual boost::any Get(const std::string& key, const Decoder& encoder) = 0;
virtual olp::porting::any Get(const std::string& key,
const Decoder& encoder) = 0;

/**
* @brief Gets the key and binary data from the cache.
Expand Down
124 changes: 124 additions & 0 deletions olp-cpp-sdk-core/include/olp/core/porting/any.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
/*
* 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_SDK_USE_STD_ANY)
#include <any>

namespace olp {
namespace porting {

using any = std::any;

template <typename T>
inline T any_cast(const any& operand) {
return std::any_cast<T>(operand);
}

template <typename T>
inline T any_cast(any& operand) {
return std::any_cast<T>(operand);
}

template <typename T>
inline T any_cast(any&& operand) {
return std::any_cast<T>(std::move(operand));
}

template <typename T>
inline const T* any_cast(const any* operand) noexcept {
return std::any_cast<T>(operand);
}

template <typename T>
inline T* any_cast(any* operand) noexcept {
return std::any_cast<T>(operand);
}

inline bool has_value(const any& operand) noexcept {
return operand.has_value();
}

inline void reset(any& operand) noexcept { operand.reset(); }

template <typename T, typename... Args>
inline any make_any(Args&&... args) {
return std::make_any<T>(std::forward<Args>(args)...);
}

template <typename T, typename U, typename... Args>
inline any make_any(std::initializer_list<U> il, Args&&... args) {
return std::make_any<T>(il, std::forward<Args>(args)...);
}

} // namespace porting
} // namespace olp

#else
#include <boost/any.hpp>

namespace olp {
namespace porting {

using any = boost::any;

template <typename T>
inline T any_cast(const any& operand) {
return boost::any_cast<T>(operand);
}

template <typename T>
inline T any_cast(any& operand) {
return boost::any_cast<T>(operand);
}

template <typename T>
inline T any_cast(any&& operand) {
return boost::any_cast<T>(operand);
}

template <typename T>
inline const T* any_cast(const any* operand) noexcept {
return boost::any_cast<T>(operand);
}

template <typename T>
inline T* any_cast(any* operand) noexcept {
return boost::any_cast<T>(operand);
}

inline bool has_value(const any& operand) noexcept { return !operand.empty(); }

inline void reset(any& operand) noexcept { operand = boost::any(); }

template <typename T, typename... Args>
inline any make_any(Args&&... args) {
return any(T(std::forward<Args>(args)...));
}

template <typename T, typename U, typename... Args>
inline any make_any(std::initializer_list<U> il, Args&&... args) {
return any(T(il, std::forward<Args>(args)...));
}

} // namespace porting
} // namespace olp

#endif
5 changes: 3 additions & 2 deletions olp-cpp-sdk-core/src/cache/DefaultCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ bool DefaultCache::Clear() { return impl_->Clear(); }

void DefaultCache::Compact() { return impl_->Compact(); }

bool DefaultCache::Put(const std::string& key, const boost::any& value,
bool DefaultCache::Put(const std::string& key, const olp::porting::any& value,
const Encoder& encoder, time_t expiry) {
return impl_->Put(key, value, encoder, expiry);
}
Expand All @@ -52,7 +52,8 @@ bool DefaultCache::Put(const std::string& key,
return impl_->Put(key, value, expiry);
}

boost::any DefaultCache::Get(const std::string& key, const Decoder& decoder) {
olp::porting::any DefaultCache::Get(const std::string& key,
const Decoder& decoder) {
return impl_->Get(key, decoder);
}

Expand Down
20 changes: 10 additions & 10 deletions olp-cpp-sdk-core/src/cache/DefaultCacheImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,8 @@ void DefaultCacheImpl::Compact() {
}
}

bool DefaultCacheImpl::Put(const std::string& key, const boost::any& value,
bool DefaultCacheImpl::Put(const std::string& key,
const olp::porting::any& value,
const Encoder& encoder, time_t expiry) {
std::lock_guard<std::mutex> lock(cache_lock_);
if (!is_open_) {
Expand Down Expand Up @@ -301,11 +302,11 @@ bool DefaultCacheImpl::Put(const std::string& key,
return Write(key, value, expiry).IsSuccessful();
}

boost::any DefaultCacheImpl::Get(const std::string& key,
const Decoder& decoder) {
olp::porting::any DefaultCacheImpl::Get(const std::string& key,
const Decoder& decoder) {
std::lock_guard<std::mutex> lock(cache_lock_);
if (!is_open_) {
return boost::any();
return olp::porting::any();
}

if (memory_cache_) {
Expand All @@ -329,7 +330,7 @@ boost::any DefaultCacheImpl::Get(const std::string& key,
return decoded_item;
}

return boost::any();
return olp::porting::any();
}

KeyValueCache::ValueTypePtr DefaultCacheImpl::Get(const std::string& key) {
Expand Down Expand Up @@ -784,10 +785,9 @@ DefaultCache::StorageOpenResult DefaultCacheImpl::SetupProtectedCache() {
settings_.disk_path_protected->c_str());

open_mode = static_cast<OpenOptions>(open_mode | OpenOptions::ReadOnly);
status =
protected_cache_->Open(*settings_.disk_path_protected,
*settings_.disk_path_protected,
protected_storage_settings, open_mode, false);
status = protected_cache_->Open(
*settings_.disk_path_protected, *settings_.disk_path_protected,
protected_storage_settings, open_mode, false);
}

if (status != OpenResult::Success) {
Expand Down Expand Up @@ -1068,7 +1068,7 @@ OperationOutcome<KeyValueCache::ValueTypePtr> DefaultCacheImpl::Read(
auto value = memory_cache_->Get(key);
if (!value.empty()) {
PromoteKeyLru(key);
return boost::any_cast<KeyValueCache::ValueTypePtr>(value);
return olp::porting::any_cast<KeyValueCache::ValueTypePtr>(value);
}
}

Expand Down
4 changes: 2 additions & 2 deletions olp-cpp-sdk-core/src/cache/DefaultCacheImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ class DefaultCacheImpl {
bool Put(const std::string& key, const KeyValueCache::ValueTypePtr value,
time_t expiry);

bool Put(const std::string& key, const boost::any& value,
bool Put(const std::string& key, const olp::porting::any& value,
const Encoder& encoder, time_t expiry);

boost::any Get(const std::string& key, const Decoder& decoder);
olp::porting::any Get(const std::string& key, const Decoder& decoder);

DefaultCache::ValueTypePtr Get(const std::string& key);

Expand Down
8 changes: 4 additions & 4 deletions olp-cpp-sdk-core/src/cache/InMemoryCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
#include <tuple>
#include <vector>

#include <olp/core/porting/any.h>
#include <olp/core/utils/LruCache.h>
#include <boost/any.hpp>

namespace olp {
namespace cache {
Expand All @@ -42,7 +42,7 @@ class InMemoryCache {
static constexpr size_t kSizeMax = std::numeric_limits<std::size_t>::max();
static constexpr time_t kExpiryMax = std::numeric_limits<time_t>::max();

using ItemTuple = std::tuple<std::string, time_t, boost::any, size_t>;
using ItemTuple = std::tuple<std::string, time_t, olp::porting::any, size_t>;
using ItemTuples = std::vector<ItemTuple>;
using TimeProvider = std::function<time_t()>;
using ModelCacheCostFunc = std::function<std::size_t(const ItemTuple&)>;
Expand Down Expand Up @@ -70,10 +70,10 @@ class InMemoryCache {
ModelCacheCostFunc cache_cost = DefaultCacheCost(),
TimeProvider time_provider = DefaultTimeProvider());

bool Put(const std::string& key, const boost::any& item,
bool Put(const std::string& key, const olp::porting::any& item,
time_t expire_seconds = kExpiryMax, size_t = 1u);

boost::any Get(const std::string& key);
olp::porting::any Get(const std::string& key);
size_t Size() const;
void Clear();

Expand Down
2 changes: 2 additions & 0 deletions olp-cpp-sdk-core/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ set(OLP_CPP_SDK_CORE_TESTS_SOURCES
./logging/MessageFormatterTest.cpp
./logging/MockAppender.cpp

./porting/AnyTest.cpp

./thread/ContinuationTest.cpp
./thread/ExecutionContextTest.cpp
./thread/PriorityQueueExtendedTest.cpp
Expand Down
Loading
Loading