Skip to content
Closed
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
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
# Save root sdk folder path
get_filename_component(OLP_CPP_SDK_ROOT "${CMAKE_CURRENT_SOURCE_DIR}" ABSOLUTE)

set(INTERNAL_INCLUDE_DIR "${OLP_CPP_SDK_ROOT}/internal/include")

# Include common scripts
include(common)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019-2024 HERE Europe B.V.
* Copyright (C) 2019-2026 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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019-2023 HERE Europe B.V.
* Copyright (C) 2019-2026 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.
Expand All @@ -22,6 +22,7 @@
#include <map>
#include <memory>
#include <string>
#include <utility>
#include <vector>

#include <olp/core/porting/optional.h>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019-2021 HERE Europe B.V.
* Copyright (C) 2019-2026 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.
Expand Down
78 changes: 78 additions & 0 deletions internal/include/json_boost/parser/JsonParser.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Copyright (C) 2019-2026 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

#include <memory>
#include <sstream>
#include <string>
#include <vector>

#include <boost/json/parse.hpp>

#include "ParserWrapper.h"

namespace olp {
namespace parser {

template <typename T>
inline T parse(const std::string& json) {
boost::json::error_code ec;
auto value = boost::json::parse(json, ec);
T result{};
if (value.is_object() || value.is_array()) {
from_json(value, result);
}
return result;
}

template <typename T>
inline T parse(std::stringstream& json_stream, bool& res) {
res = false;
boost::json::error_code ec;
auto value = boost::json::parse(json_stream, ec);
T result{};
if (value.is_object() || value.is_array()) {
from_json(value, result);
res = true;
}
return result;
}

template <typename T>
inline T parse(std::stringstream& json_stream) {
bool res = true;
return parse<T>(json_stream, res);
}

template <typename T>
inline T parse(const std::shared_ptr<std::vector<unsigned char>>& json_bytes) {
boost::json::string_view json(reinterpret_cast<char*>(json_bytes->data()),
json_bytes->size());
boost::json::error_code ec;
auto value = boost::json::parse(json, ec);
T result{};
if (value.is_object() || value.is_array()) {
from_json(value, result);
}
return result;
}

} // namespace parser
} // namespace olp
102 changes: 102 additions & 0 deletions internal/include/json_boost/parser/ParserWrapper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
* Copyright (C) 2019-2026 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

#include <map>
#include <memory>
#include <string>
#include <utility>
#include <vector>

#include <olp/core/porting/optional.h>
#include <boost/json/value.hpp>

namespace olp {
namespace parser {

inline void from_json(const boost::json::value& value, std::string& x) {
const auto& str = value.get_string();
x.assign(str.begin(), str.end());
}

inline void from_json(const boost::json::value& value, int32_t& x) {
x = static_cast<int32_t>(value.to_number<int64_t>());
}

inline void from_json(const boost::json::value& value, int64_t& x) {
x = value.to_number<int64_t>();
}

inline void from_json(const boost::json::value& value, double& x) {
x = value.to_number<double>();
}

inline void from_json(const boost::json::value& value, bool& x) {
x = value.get_bool();
}

inline void from_json(const boost::json::value& value,
std::shared_ptr<std::vector<unsigned char>>& x) {
const auto& s = value.get_string();
x = std::make_shared<std::vector<unsigned char>>(s.begin(), s.end());
}

template <typename T>
inline void from_json(const boost::json::value& value,
porting::optional<T>& x) {
T result = T();
from_json(value, result);
x = result;
}

template <typename T>
inline void from_json(const boost::json::value& value,
std::map<std::string, T>& results) {
const auto& object = value.get_object();
for (const auto& object_value : object) {
std::string key = object_value.key();
from_json(object_value.value(), results[key]);
}
}

template <typename T>
inline void from_json(const boost::json::value& value,
std::vector<T>& results) {
const auto& array = value.get_array();
for (const auto& array_value : array) {
T result;
from_json(array_value, result);
results.emplace_back(std::move(result));
}
}

template <typename T>
inline T parse(const boost::json::value& value, const std::string& name) {
T result = T();
const auto& object = value.get_object();
auto itr = object.find(name);
if (itr != object.end()) {
from_json(itr->value(), result);
}
return result;
}

} // namespace parser
} // namespace olp
102 changes: 102 additions & 0 deletions internal/include/json_boost/serializer/SerializerWrapper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
* Copyright (C) 2019-2026 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

#include <map>
#include <memory>
#include <string>
#include <utility>
#include <vector>

#include <olp/core/porting/optional.h>
#include <boost/json/value.hpp>

namespace olp {
namespace serializer {

inline void to_json(const std::string& x, boost::json::value& value) {
value.emplace_string() = x;
}

inline void to_json(int32_t x, boost::json::value& value) {
value.emplace_int64() = x;
}

inline void to_json(int64_t x, boost::json::value& value) {
value.emplace_int64() = x;
}

inline void to_json(double x, boost::json::value& value) {
value.emplace_double() = x;
}
inline void to_json(bool x, boost::json::value& value) {
value.emplace_bool() = x;
}

inline void to_json(const std::shared_ptr<std::vector<unsigned char>>& x,
boost::json::value& value) {
value.emplace_string().assign(x->begin(), x->end());
}

template <typename T>
inline void to_json(const porting::optional<T>& x, boost::json::value& value) {
if (x) {
to_json(*x, value);
} else {
value.emplace_null();
}
}

template <typename T>
inline void to_json(const std::map<std::string, T>& x,
boost::json::value& value) {
auto& object = value.emplace_object();
for (auto itr = x.begin(); itr != x.end(); ++itr) {
const auto& key = itr->first;
boost::json::value item_value;
to_json(itr->second, item_value);
object.emplace(key, std::move(item_value));
}
}

template <typename T>
inline void to_json(const std::vector<T>& x, boost::json::value& value) {
auto& array = value.emplace_array();
array.reserve(x.size());
for (typename std::vector<T>::const_iterator itr = x.begin(); itr != x.end();
++itr) {
boost::json::value item_value;
to_json(*itr, item_value);
array.emplace_back(std::move(item_value));
}
}

template <typename T>
inline void serialize(const std::string& key, const T& x,
boost::json::object& value) {
boost::json::value item_value;
to_json(x, item_value);
if (!item_value.is_null()) {
value.emplace(key, std::move(item_value));
}
}

} // namespace serializer
} // namespace olp
10 changes: 3 additions & 7 deletions olp-cpp-sdk-core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,6 @@ set(OLP_SDK_CLIENT_HEADERS
./include/olp/core/client/TaskContext.h
)

set(OLP_SDK_GENERATED_HEADERS
./include/olp/core/generated/parser/JsonParser.h
./include/olp/core/generated/parser/ParserWrapper.h
./include/olp/core/generated/serializer/SerializerWrapper.h
)

set(OLP_SDK_HTTP_HEADERS
./include/olp/core/http/adapters/HarCaptureAdapter.h
./include/olp/core/http/CertificateSettings.h
Expand Down Expand Up @@ -390,7 +384,6 @@ set(OLP_SDK_THREAD_SOURCES
set(OLP_SDK_CORE_HEADERS
${OLP_SDK_CACHE_HEADERS}
${OLP_SDK_CLIENT_HEADERS}
${OLP_SDK_GENERATED_HEADERS}
${OLP_SDK_HTTP_HEADERS}
${OLP_SDK_MODEL_HEADERS}
${OLP_SDK_PLATFORM_HEADERS}
Expand Down Expand Up @@ -470,6 +463,9 @@ target_include_directories(${PROJECT_NAME} PUBLIC

$<INSTALL_INTERFACE:include>)

target_include_directories(${PROJECT_NAME} PRIVATE
$<BUILD_INTERFACE:${INTERNAL_INCLUDE_DIR}>)

if (ANDROID)
set(ADDITIONAL_LIBRARIES log)
else()
Expand Down
4 changes: 2 additions & 2 deletions olp-cpp-sdk-core/src/client/api/JsonResultParser.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 HERE Europe B.V.
* Copyright (C) 2020-2026 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.
Expand All @@ -23,8 +23,8 @@
#include <string>
#include <utility>

#include <generated/parser/JsonParser.h>
#include <olp/core/client/ApiError.h>
#include <olp/core/generated/parser/JsonParser.h>
#include <olp/core/logging/Log.h>

namespace olp {
Expand Down
7 changes: 5 additions & 2 deletions olp-cpp-sdk-core/src/client/parser/ApiParser.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 HERE Europe B.V.
* Copyright (C) 2020-2026 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.
Expand All @@ -19,7 +19,10 @@

#include "ApiParser.h"

#include <olp/core/generated/parser/ParserWrapper.h>
#include <map>
#include <string>

#include <generated/parser/ParserWrapper.h>

namespace olp {
namespace parser {
Expand Down
3 changes: 3 additions & 0 deletions olp-cpp-sdk-dataservice-read/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ target_include_directories(${PROJECT_NAME}
$<BUILD_INTERFACE:${Boost_INCLUDE_DIR}>
PRIVATE ${olp-cpp-sdk-core_INCLUDE_DIRS})

target_include_directories(${PROJECT_NAME} PRIVATE
$<BUILD_INTERFACE:${INTERNAL_INCLUDE_DIR}>)

target_link_libraries(${PROJECT_NAME}
PUBLIC
olp-cpp-sdk-core
Expand Down
Loading
Loading