-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* jsoncons * Fixed imports * layout src_folder=src * Fixed get * Fixed build and other improvements * Added settings * More fixes
- Loading branch information
1 parent
62d319c
commit 0de381f
Showing
8 changed files
with
167 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
sources: | ||
"0.169.0": | ||
url: "https://github.com/danielaparker/jsoncons/archive/refs/tags/v0.169.0.tar.gz" | ||
sha256: 423dc99d6950056fb55782513daf74adf37501eaf01b977b2415873cd0c44243 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from conan import ConanFile | ||
from conan.tools.files import get, copy | ||
from conan.tools.layout import basic_layout | ||
import os | ||
|
||
required_conan_version = ">=1.50.0" | ||
|
||
|
||
class JsonconsConan(ConanFile): | ||
name = "jsoncons" | ||
description = "A C++, header-only library for constructing JSON and JSON-like data formats, with JSON Pointer, JSON Patch, JSON Schema, JSONPath, JMESPath, CSV, MessagePack, CBOR, BSON, UBJSON" | ||
license = "BSL-1.0" | ||
url = "https://github.com/conan-io/conan-center-index" | ||
homepage = "https://github.com/danielaparker/jsoncons" | ||
topics = ("json", "csv", "cpp", "json-serialization", "cbor", "json-parser", "messagepack", "json-pointer", "json-patch", "json-diff", "bson", "ubjson", "json-parsing", "jsonpath", "jmespath", "csv-parser", "csv-reader", "jsonschema", "json-construction", "streaming-json-read", "header-only") | ||
settings = "os", "arch", "compiler", "build_type" | ||
no_copy_source = True | ||
|
||
def layout(self): | ||
basic_layout(self, src_folder="src") | ||
|
||
def package_id(self): | ||
self.info.clear() | ||
|
||
def source(self): | ||
get( | ||
self, | ||
**self.conan_data["sources"][self.version], | ||
destination=self.source_folder, | ||
strip_root=True | ||
) | ||
|
||
def package(self): | ||
copy(self, pattern="LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses")) | ||
copy(self, pattern="*", src=os.path.join(self.source_folder, "include"), dst=os.path.join(self.package_folder, "include")) | ||
|
||
def package_info(self): | ||
# Folders not used for header-only | ||
self.cpp_info.bindirs = [] | ||
self.cpp_info.libdirs = [] | ||
|
||
self.cpp_info.set_property("cmake_file_name", "jsoncons") | ||
self.cpp_info.set_property("cmake_target_name", "jsoncons") | ||
|
||
# TODO: to remove in conan v2 once cmake_find_package* generators removed | ||
self.cpp_info.names["cmake_find_package"] = "jsoncons" | ||
self.cpp_info.names["cmake_find_package_multi"] = "jsoncons" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
cmake_minimum_required(VERSION 3.8) | ||
project(test_package) | ||
|
||
find_package(jsoncons CONFIG REQUIRED) | ||
|
||
add_executable(${PROJECT_NAME} test_package.cpp) | ||
target_link_libraries(${PROJECT_NAME} PRIVATE jsoncons) | ||
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import os | ||
from conan import ConanFile | ||
from conan.tools.build import can_run | ||
from conan.tools.cmake import CMake, cmake_layout | ||
|
||
required_conan_version = ">=1.50.0" | ||
|
||
class TestPackageConan(ConanFile): | ||
settings = "os", "compiler", "build_type", "arch" | ||
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv" | ||
test_type = "explicit" | ||
|
||
def requirements(self): | ||
self.requires(self.tested_reference_str) | ||
|
||
def layout(self): | ||
cmake_layout(self) | ||
|
||
def build(self): | ||
cmake = CMake(self) | ||
cmake.configure() | ||
cmake.build() | ||
|
||
def test(self): | ||
if can_run(self): | ||
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package") | ||
self.run(bin_path, env="conanrun") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#include <jsoncons/json.hpp> | ||
#include <jsoncons_ext/jsonpath/jsonpath.hpp> | ||
#include <iostream> | ||
|
||
using namespace jsoncons; // for convenience | ||
|
||
std::string data = R"( | ||
{ | ||
"application": "hiking", | ||
"reputons": [ | ||
{ | ||
"rater": "HikingAsylum", | ||
"assertion": "advanced", | ||
"rated": "Marilyn C", | ||
"rating": 0.90, | ||
"generated": 1514862245 | ||
} | ||
] | ||
} | ||
)"; | ||
|
||
int main() | ||
{ | ||
// Parse the string of data into a json value | ||
json j = json::parse(data); | ||
|
||
// Does object member reputons exist? | ||
std::cout << "(1) " << std::boolalpha << j.contains("reputons") << "\n\n"; | ||
|
||
// Get a reference to reputons array | ||
const json& v = j["reputons"]; | ||
|
||
// Iterate over reputons array | ||
std::cout << "(2)\n"; | ||
for (const auto& item : v.array_range()) | ||
{ | ||
// Access rated as string and rating as double | ||
std::cout << item["rated"].as<std::string>() << ", " << item["rating"].as<double>() << "\n"; | ||
} | ||
std::cout << "\n"; | ||
|
||
// Select all "rated" with JSONPath | ||
std::cout << "(3)\n"; | ||
json result = jsonpath::json_query(j,"$..rated"); | ||
std::cout << pretty_print(result) << "\n\n"; | ||
|
||
// Serialize back to JSON | ||
std::cout << "(4)\n" << pretty_print(j) << "\n\n"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
cmake_minimum_required(VERSION 3.8) | ||
project(test_package) | ||
|
||
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) | ||
conan_basic_setup(TARGETS) | ||
|
||
find_package(jsoncons CONFIG REQUIRED) | ||
|
||
add_executable(${PROJECT_NAME} ../test_package/test_package.cpp) | ||
target_link_libraries(${PROJECT_NAME} PRIVATE jsoncons::jsoncons) | ||
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from conans import ConanFile, CMake | ||
from conan.tools.build import cross_building | ||
import os | ||
|
||
|
||
class TestPackageConan(ConanFile): | ||
settings = "os", "compiler", "build_type", "arch" | ||
generators = "cmake", "cmake_find_package_multi" | ||
|
||
def build(self): | ||
cmake = CMake(self) | ||
cmake.configure() | ||
cmake.build() | ||
|
||
def test(self): | ||
if not cross_building(self): | ||
bin_path = os.path.join("bin", "test_package") | ||
self.run(bin_path, run_environment=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
versions: | ||
"0.169.0": | ||
folder: "all" |