xmake.lua 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package("jsoncons")
  2. set_kind("library", {headeronly = true})
  3. set_homepage("https://danielaparker.github.io/jsoncons/")
  4. set_description("A C++, header-only library for constructing JSON and JSON-like data formats, with JSON Pointer, JSON Patch, JSONPath, JMESPath, CSV, MessagePack, CBOR, BSON, UBJSON")
  5. set_urls("https://github.com/danielaparker/jsoncons/archive/$(version).zip",
  6. "https://github.com/danielaparker/jsoncons.git")
  7. add_versions("v0.176.0", "71a618219b62a2bbcc46efac98696574581e343cd98ef33e5e1bd8db182005d9")
  8. add_versions("v0.170.2", "81ac768eecb8cf2613a09a9d081294895d7afd294b841166b4e1378f0acfdd6e")
  9. add_versions("v0.158.0", "7ad7cc0e9c74df495dd16b818758ec2e2a5b7fef8f1852841087fd5e8bb6a6cb")
  10. on_install(function (package)
  11. os.cp("include", package:installdir())
  12. end)
  13. on_test(function (package)
  14. assert(package:check_cxxsnippets({test = [[
  15. #include <iostream>
  16. #include <string>
  17. using namespace jsoncons;
  18. std::string data = R"(
  19. {
  20. "application": "hiking",
  21. "reputons":
  22. [
  23. {
  24. "rater": "HikingAsylum",
  25. "assertion": "advanced",
  26. "rated": "Marilyn C",
  27. "rating": 0.90,
  28. "generated": 1514862245
  29. }
  30. ]
  31. }
  32. )";
  33. void test() {
  34. json j = json::parse(data);
  35. std::cout << "(1) " << std::boolalpha << j.contains("reputons") << "\n\n";
  36. const json &v = j["reputons"];
  37. for (const auto &item : v.array_range()) {
  38. // Access rated as string and rating as double
  39. std::cout << item["rated"].as<std::string>() << ", "
  40. << item["rating"].as<double>() << "\n";
  41. }
  42. std::cout << "\n";
  43. std::cout << "(3)\n";
  44. json result = jsonpath::json_query(j, "$..rated");
  45. std::cout << pretty_print(result) << "\n\n";
  46. std::cout << "(4)\n" << pretty_print(j) << "\n\n";
  47. }
  48. ]]}, {configs = {languages = "c++11"}, includes = {"jsoncons/json.hpp", "jsoncons_ext/jsonpath/jsonpath.hpp"}}))
  49. end)