Browse Source
Merge branch 'jani_support' into jani_gspn_support
Merge branch 'jani_support' into jani_gspn_support
Former-commit-id:main777b367b27
[formerly4d40c008e2
] Former-commit-id:37bcfc8722
549 changed files with 6383 additions and 106391 deletions
-
12CMakeLists.txt
-
4resources/3rdparty/modernjson/CMakeLists.txt
-
59resources/3rdparty/modernjson/ChangeLog.md
-
35resources/3rdparty/modernjson/Makefile
-
178resources/3rdparty/modernjson/README.md
-
3resources/3rdparty/modernjson/appveyor.yml
-
77resources/3rdparty/modernjson/benchmarks/benchmarks.cpp
-
401resources/3rdparty/modernjson/benchmarks/benchpress.hpp
-
1312resources/3rdparty/modernjson/benchmarks/cxxopts.hpp
-
1resources/3rdparty/modernjson/benchmarks/files/jeopardy/jeopardy.json.REMOVED.git-id
-
9resources/3rdparty/modernjson/benchmarks/files/nativejson-benchmark/canada.json
-
50469resources/3rdparty/modernjson/benchmarks/files/nativejson-benchmark/citm_catalog.json
-
15482resources/3rdparty/modernjson/benchmarks/files/nativejson-benchmark/twitter.json
-
317resources/3rdparty/modernjson/doc/Doxyfile
-
82resources/3rdparty/modernjson/doc/Makefile
-
26resources/3rdparty/modernjson/doc/css/mylayout.css
-
27resources/3rdparty/modernjson/doc/css/mylayout_docset.css
-
36resources/3rdparty/modernjson/doc/examples/README.cpp
-
1resources/3rdparty/modernjson/doc/examples/README.link
-
27resources/3rdparty/modernjson/doc/examples/README.output
-
18resources/3rdparty/modernjson/doc/examples/array.cpp
-
1resources/3rdparty/modernjson/doc/examples/array.link
-
4resources/3rdparty/modernjson/doc/examples/array.output
-
33resources/3rdparty/modernjson/doc/examples/at__object_t_key_type.cpp
-
1resources/3rdparty/modernjson/doc/examples/at__object_t_key_type.link
-
3resources/3rdparty/modernjson/doc/examples/at__object_t_key_type.output
-
27resources/3rdparty/modernjson/doc/examples/at__object_t_key_type_const.cpp
-
1resources/3rdparty/modernjson/doc/examples/at__object_t_key_type_const.link
-
2resources/3rdparty/modernjson/doc/examples/at__object_t_key_type_const.output
-
28resources/3rdparty/modernjson/doc/examples/at__size_type.cpp
-
1resources/3rdparty/modernjson/doc/examples/at__size_type.link
-
3resources/3rdparty/modernjson/doc/examples/at__size_type.output
-
22resources/3rdparty/modernjson/doc/examples/at__size_type_const.cpp
-
1resources/3rdparty/modernjson/doc/examples/at__size_type_const.link
-
2resources/3rdparty/modernjson/doc/examples/at__size_type_const.output
-
35resources/3rdparty/modernjson/doc/examples/at_json_pointer.cpp
-
1resources/3rdparty/modernjson/doc/examples/at_json_pointer.link
-
6resources/3rdparty/modernjson/doc/examples/at_json_pointer.output
-
23resources/3rdparty/modernjson/doc/examples/at_json_pointer_const.cpp
-
1resources/3rdparty/modernjson/doc/examples/at_json_pointer_const.link
-
4resources/3rdparty/modernjson/doc/examples/at_json_pointer_const.output
-
28resources/3rdparty/modernjson/doc/examples/back.cpp
-
1resources/3rdparty/modernjson/doc/examples/back.link
-
6resources/3rdparty/modernjson/doc/examples/back.output
-
12resources/3rdparty/modernjson/doc/examples/basic_json.cpp
-
1resources/3rdparty/modernjson/doc/examples/basic_json.link
-
1resources/3rdparty/modernjson/doc/examples/basic_json.output
-
58resources/3rdparty/modernjson/doc/examples/basic_json__CompatibleArrayType.cpp
-
1resources/3rdparty/modernjson/doc/examples/basic_json__CompatibleArrayType.link
-
9resources/3rdparty/modernjson/doc/examples/basic_json__CompatibleArrayType.output
-
27resources/3rdparty/modernjson/doc/examples/basic_json__CompatibleIntegerNumberType.cpp
-
1resources/3rdparty/modernjson/doc/examples/basic_json__CompatibleIntegerNumberType.link
-
5resources/3rdparty/modernjson/doc/examples/basic_json__CompatibleIntegerNumberType.output
-
21resources/3rdparty/modernjson/doc/examples/basic_json__CompatibleNumberFloatType.cpp
-
1resources/3rdparty/modernjson/doc/examples/basic_json__CompatibleNumberFloatType.link
-
3resources/3rdparty/modernjson/doc/examples/basic_json__CompatibleNumberFloatType.output
-
41resources/3rdparty/modernjson/doc/examples/basic_json__CompatibleObjectType.cpp
-
1resources/3rdparty/modernjson/doc/examples/basic_json__CompatibleObjectType.link
-
4resources/3rdparty/modernjson/doc/examples/basic_json__CompatibleObjectType.output
-
15resources/3rdparty/modernjson/doc/examples/basic_json__CompatibleStringType.cpp
-
1resources/3rdparty/modernjson/doc/examples/basic_json__CompatibleStringType.link
-
1resources/3rdparty/modernjson/doc/examples/basic_json__CompatibleStringType.output
-
21resources/3rdparty/modernjson/doc/examples/basic_json__InputIt_InputIt.cpp
-
1resources/3rdparty/modernjson/doc/examples/basic_json__InputIt_InputIt.link
-
3resources/3rdparty/modernjson/doc/examples/basic_json__InputIt_InputIt.output
-
15resources/3rdparty/modernjson/doc/examples/basic_json__array_t.cpp
-
1resources/3rdparty/modernjson/doc/examples/basic_json__array_t.link
-
1resources/3rdparty/modernjson/doc/examples/basic_json__array_t.output
-
16resources/3rdparty/modernjson/doc/examples/basic_json__basic_json.cpp
-
1resources/3rdparty/modernjson/doc/examples/basic_json__basic_json.link
-
2resources/3rdparty/modernjson/doc/examples/basic_json__basic_json.output
-
14resources/3rdparty/modernjson/doc/examples/basic_json__boolean_t.cpp
-
1resources/3rdparty/modernjson/doc/examples/basic_json__boolean_t.link
-
2resources/3rdparty/modernjson/doc/examples/basic_json__boolean_t.output
-
15resources/3rdparty/modernjson/doc/examples/basic_json__const_int.cpp
-
1resources/3rdparty/modernjson/doc/examples/basic_json__const_int.link
-
1resources/3rdparty/modernjson/doc/examples/basic_json__const_int.output
-
17resources/3rdparty/modernjson/doc/examples/basic_json__copyassignment.cpp
-
1resources/3rdparty/modernjson/doc/examples/basic_json__copyassignment.link
-
2resources/3rdparty/modernjson/doc/examples/basic_json__copyassignment.output
-
55resources/3rdparty/modernjson/doc/examples/basic_json__istream.cpp
-
1resources/3rdparty/modernjson/doc/examples/basic_json__istream.link
-
34resources/3rdparty/modernjson/doc/examples/basic_json__istream.output
-
20resources/3rdparty/modernjson/doc/examples/basic_json__list_init_t.cpp
-
1resources/3rdparty/modernjson/doc/examples/basic_json__list_init_t.link
-
5resources/3rdparty/modernjson/doc/examples/basic_json__list_init_t.output
-
16resources/3rdparty/modernjson/doc/examples/basic_json__moveconstructor.cpp
-
1resources/3rdparty/modernjson/doc/examples/basic_json__moveconstructor.link
-
2resources/3rdparty/modernjson/doc/examples/basic_json__moveconstructor.output
-
12resources/3rdparty/modernjson/doc/examples/basic_json__nullptr_t.cpp
-
1resources/3rdparty/modernjson/doc/examples/basic_json__nullptr_t.link
-
1resources/3rdparty/modernjson/doc/examples/basic_json__nullptr_t.output
-
21resources/3rdparty/modernjson/doc/examples/basic_json__number_float_t.cpp
-
1resources/3rdparty/modernjson/doc/examples/basic_json__number_float_t.link
-
3resources/3rdparty/modernjson/doc/examples/basic_json__number_float_t.output
-
14resources/3rdparty/modernjson/doc/examples/basic_json__number_integer_t.cpp
-
1resources/3rdparty/modernjson/doc/examples/basic_json__number_integer_t.link
-
1resources/3rdparty/modernjson/doc/examples/basic_json__number_integer_t.output
-
15resources/3rdparty/modernjson/doc/examples/basic_json__object_t.cpp
-
1resources/3rdparty/modernjson/doc/examples/basic_json__object_t.link
@ -1,77 +0,0 @@ |
|||||
#define BENCHPRESS_CONFIG_MAIN
|
|
||||
|
|
||||
#include <fstream>
|
|
||||
#include <benchpress.hpp>
|
|
||||
#include <json.hpp>
|
|
||||
|
|
||||
BENCHMARK("parse jeopardy.json", [](benchpress::context* ctx) |
|
||||
{ |
|
||||
for (size_t i = 0; i < ctx->num_iterations(); ++i) |
|
||||
{ |
|
||||
std::ifstream input_file("benchmarks/files/jeopardy/jeopardy.json"); |
|
||||
nlohmann::json j; |
|
||||
j << input_file; |
|
||||
} |
|
||||
}) |
|
||||
|
|
||||
BENCHMARK("parse canada.json", [](benchpress::context* ctx) |
|
||||
{ |
|
||||
for (size_t i = 0; i < ctx->num_iterations(); ++i) |
|
||||
{ |
|
||||
std::ifstream input_file("benchmarks/files/nativejson-benchmark/canada.json"); |
|
||||
nlohmann::json j; |
|
||||
j << input_file; |
|
||||
} |
|
||||
}) |
|
||||
|
|
||||
BENCHMARK("parse citm_catalog.json", [](benchpress::context* ctx) |
|
||||
{ |
|
||||
for (size_t i = 0; i < ctx->num_iterations(); ++i) |
|
||||
{ |
|
||||
std::ifstream input_file("benchmarks/files/nativejson-benchmark/citm_catalog.json"); |
|
||||
nlohmann::json j; |
|
||||
j << input_file; |
|
||||
} |
|
||||
}) |
|
||||
|
|
||||
BENCHMARK("parse twitter.json", [](benchpress::context* ctx) |
|
||||
{ |
|
||||
for (size_t i = 0; i < ctx->num_iterations(); ++i) |
|
||||
{ |
|
||||
std::ifstream input_file("benchmarks/files/nativejson-benchmark/twitter.json"); |
|
||||
nlohmann::json j; |
|
||||
j << input_file; |
|
||||
} |
|
||||
}) |
|
||||
|
|
||||
BENCHMARK("dump jeopardy.json", [](benchpress::context* ctx) |
|
||||
{ |
|
||||
std::ifstream input_file("benchmarks/files/jeopardy/jeopardy.json"); |
|
||||
nlohmann::json j; |
|
||||
j << input_file; |
|
||||
std::ofstream output_file("jeopardy.dump.json"); |
|
||||
|
|
||||
ctx->reset_timer(); |
|
||||
for (size_t i = 0; i < ctx->num_iterations(); ++i) |
|
||||
{ |
|
||||
output_file << j; |
|
||||
} |
|
||||
|
|
||||
std::remove("jeopardy.dump.json"); |
|
||||
}) |
|
||||
|
|
||||
BENCHMARK("dump jeopardy.json with indent", [](benchpress::context* ctx) |
|
||||
{ |
|
||||
std::ifstream input_file("benchmarks/files/jeopardy/jeopardy.json"); |
|
||||
nlohmann::json j; |
|
||||
j << input_file; |
|
||||
std::ofstream output_file("jeopardy.dump.json"); |
|
||||
|
|
||||
ctx->reset_timer(); |
|
||||
for (size_t i = 0; i < ctx->num_iterations(); ++i) |
|
||||
{ |
|
||||
output_file << std::setw(4) << j; |
|
||||
} |
|
||||
|
|
||||
std::remove("jeopardy.dump.json"); |
|
||||
}) |
|
@ -1,401 +0,0 @@ |
|||||
/*
|
|
||||
* Copyright (C) 2015 Christopher Gilbert. |
|
||||
* |
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|
||||
* of this software and associated documentation files (the "Software"), to deal |
|
||||
* in the Software without restriction, including without limitation the rights |
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
||||
* copies of the Software, and to permit persons to whom the Software is |
|
||||
* furnished to do so, subject to the following conditions: |
|
||||
* |
|
||||
* The above copyright notice and this permission notice shall be included in all |
|
||||
* copies or substantial portions of the Software. |
|
||||
* |
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
|
||||
* SOFTWARE. |
|
||||
*/ |
|
||||
#ifndef BENCHPRESS_HPP
|
|
||||
#define BENCHPRESS_HPP
|
|
||||
|
|
||||
#include <algorithm> // max, min
|
|
||||
#include <atomic> // atomic_intmax_t
|
|
||||
#include <chrono> // high_resolution_timer, duration
|
|
||||
#include <functional> // function
|
|
||||
#include <iomanip> // setw
|
|
||||
#include <iostream> // cout
|
|
||||
#include <regex> // regex, regex_match
|
|
||||
#include <sstream> // stringstream
|
|
||||
#include <string> // string
|
|
||||
#include <thread> // thread
|
|
||||
#include <vector> // vector
|
|
||||
|
|
||||
namespace benchpress { |
|
||||
|
|
||||
/*
|
|
||||
* The options class encapsulates all options for running benchmarks. |
|
||||
* |
|
||||
* When including benchpress, a main function can be emitted which includes a command-line parser for building an |
|
||||
* options object. However from time-to-time it may be necessary for the developer to have to build their own main |
|
||||
* stub and construct the options object manually. |
|
||||
* |
|
||||
* options opts; |
|
||||
* opts |
|
||||
* .bench(".*") |
|
||||
* .benchtime(1) |
|
||||
* .cpu(4); |
|
||||
*/ |
|
||||
class options { |
|
||||
std::string d_bench; |
|
||||
size_t d_benchtime; |
|
||||
size_t d_cpu; |
|
||||
public: |
|
||||
options() |
|
||||
: d_bench(".*") |
|
||||
, d_benchtime(1) |
|
||||
, d_cpu(std::thread::hardware_concurrency()) |
|
||||
{} |
|
||||
options& bench(const std::string& bench) { |
|
||||
d_bench = bench; |
|
||||
return *this; |
|
||||
} |
|
||||
options& benchtime(size_t benchtime) { |
|
||||
d_benchtime = benchtime; |
|
||||
return *this; |
|
||||
} |
|
||||
options& cpu(size_t cpu) { |
|
||||
d_cpu = cpu; |
|
||||
return *this; |
|
||||
} |
|
||||
std::string get_bench() const { |
|
||||
return d_bench; |
|
||||
} |
|
||||
size_t get_benchtime() const { |
|
||||
return d_benchtime; |
|
||||
} |
|
||||
size_t get_cpu() const { |
|
||||
return d_cpu; |
|
||||
} |
|
||||
}; |
|
||||
|
|
||||
class context; |
|
||||
|
|
||||
/*
|
|
||||
* The benchmark_info class is used to store a function name / pointer pair. |
|
||||
* |
|
||||
* benchmark_info bi("example", [](benchpress::context* b) { |
|
||||
* // benchmark function
|
|
||||
* }); |
|
||||
*/ |
|
||||
class benchmark_info { |
|
||||
std::string d_name; |
|
||||
std::function<void(context*)> d_func; |
|
||||
|
|
||||
public: |
|
||||
benchmark_info(std::string name, std::function<void(context*)> func) |
|
||||
: d_name(name) |
|
||||
, d_func(func) |
|
||||
{} |
|
||||
|
|
||||
std::string get_name() const { return d_name; } |
|
||||
std::function<void(context*)> get_func() const { return d_func; } |
|
||||
}; |
|
||||
|
|
||||
/*
|
|
||||
* The registration class is responsible for providing a single global point of reference for registering |
|
||||
* benchmark functions. |
|
||||
* |
|
||||
* registration::get_ptr()->register_benchmark(info); |
|
||||
*/ |
|
||||
class registration { |
|
||||
static registration* d_this; |
|
||||
std::vector<benchmark_info> d_benchmarks; |
|
||||
|
|
||||
public: |
|
||||
static registration* get_ptr() { |
|
||||
if (nullptr == d_this) { |
|
||||
d_this = new registration(); |
|
||||
} |
|
||||
return d_this; |
|
||||
} |
|
||||
|
|
||||
void register_benchmark(benchmark_info& info) { |
|
||||
d_benchmarks.push_back(info); |
|
||||
} |
|
||||
|
|
||||
std::vector<benchmark_info> get_benchmarks() { return d_benchmarks; } |
|
||||
}; |
|
||||
|
|
||||
/*
|
|
||||
* The auto_register class is a helper used to register benchmarks. |
|
||||
*/ |
|
||||
class auto_register { |
|
||||
public: |
|
||||
auto_register(const std::string& name, std::function<void(context*)> func) { |
|
||||
benchmark_info info(name, func); |
|
||||
registration::get_ptr()->register_benchmark(info); |
|
||||
} |
|
||||
}; |
|
||||
|
|
||||
#define CONCAT(x, y) x ## y
|
|
||||
#define CONCAT2(x, y) CONCAT(x, y)
|
|
||||
|
|
||||
// The BENCHMARK macro is a helper for creating benchmark functions and automatically registering them with the
|
|
||||
// registration class.
|
|
||||
#define BENCHMARK(x, f) benchpress::auto_register CONCAT2(register_, __LINE__)((x), (f));
|
|
||||
|
|
||||
// This macro will prevent the compiler from removing a redundant code path which has no side-effects.
|
|
||||
#define DISABLE_REDUNDANT_CODE_OPT() { asm(""); }
|
|
||||
|
|
||||
/*
|
|
||||
* The result class is responsible for producing a printable string representation of a benchmark run. |
|
||||
*/ |
|
||||
class result { |
|
||||
size_t d_num_iterations; |
|
||||
std::chrono::nanoseconds d_duration; |
|
||||
size_t d_num_bytes; |
|
||||
|
|
||||
public: |
|
||||
result(size_t num_iterations, std::chrono::nanoseconds duration, size_t num_bytes) |
|
||||
: d_num_iterations(num_iterations) |
|
||||
, d_duration(duration) |
|
||||
, d_num_bytes(num_bytes) |
|
||||
{} |
|
||||
|
|
||||
size_t get_ns_per_op() const { |
|
||||
if (d_num_iterations <= 0) { |
|
||||
return 0; |
|
||||
} |
|
||||
return d_duration.count() / d_num_iterations; |
|
||||
} |
|
||||
|
|
||||
double get_mb_per_s() const { |
|
||||
if (d_num_iterations <= 0 || d_duration.count() <= 0 || d_num_bytes <= 0) { |
|
||||
return 0; |
|
||||
} |
|
||||
return ((double(d_num_bytes) * double(d_num_iterations) / double(1e6)) / |
|
||||
double(std::chrono::duration_cast<std::chrono::seconds>(d_duration).count())); |
|
||||
} |
|
||||
|
|
||||
std::string to_string() const { |
|
||||
std::stringstream tmp; |
|
||||
tmp << std::setw(12) << std::right << d_num_iterations; |
|
||||
size_t npo = get_ns_per_op(); |
|
||||
tmp << std::setw(12) << std::right << npo << std::setw(0) << " ns/op"; |
|
||||
double mbs = get_mb_per_s(); |
|
||||
if (mbs > 0.0) { |
|
||||
tmp << std::setw(12) << std::right << mbs << std::setw(0) << " MB/s"; |
|
||||
} |
|
||||
return std::string(tmp.str()); |
|
||||
} |
|
||||
}; |
|
||||
|
|
||||
/*
|
|
||||
* The parallel_context class is responsible for providing a thread-safe context for parallel benchmark code. |
|
||||
*/ |
|
||||
class parallel_context { |
|
||||
std::atomic_intmax_t d_num_iterations; |
|
||||
public: |
|
||||
parallel_context(size_t num_iterations) |
|
||||
: d_num_iterations(num_iterations) |
|
||||
{} |
|
||||
|
|
||||
bool next() { |
|
||||
return (d_num_iterations.fetch_sub(1) > 0); |
|
||||
} |
|
||||
}; |
|
||||
|
|
||||
/*
|
|
||||
* The context class is responsible for providing an interface for capturing benchmark metrics to benchmark functions. |
|
||||
*/ |
|
||||
class context { |
|
||||
bool d_timer_on; |
|
||||
std::chrono::high_resolution_clock::time_point d_start; |
|
||||
std::chrono::nanoseconds d_duration; |
|
||||
std::chrono::seconds d_benchtime; |
|
||||
size_t d_num_iterations; |
|
||||
size_t d_num_threads; |
|
||||
size_t d_num_bytes; |
|
||||
benchmark_info d_benchmark; |
|
||||
|
|
||||
public: |
|
||||
context(const benchmark_info& info, const options& opts) |
|
||||
: d_timer_on(false) |
|
||||
, d_start() |
|
||||
, d_duration() |
|
||||
, d_benchtime(std::chrono::seconds(opts.get_benchtime())) |
|
||||
, d_num_iterations(1) |
|
||||
, d_num_threads(opts.get_cpu()) |
|
||||
, d_num_bytes(0) |
|
||||
, d_benchmark(info) |
|
||||
{} |
|
||||
|
|
||||
size_t num_iterations() const { return d_num_iterations; } |
|
||||
|
|
||||
void set_num_threads(size_t n) { d_num_threads = n; } |
|
||||
size_t num_threads() const { return d_num_threads; } |
|
||||
|
|
||||
void start_timer() { |
|
||||
if (!d_timer_on) { |
|
||||
d_start = std::chrono::high_resolution_clock::now(); |
|
||||
d_timer_on = true; |
|
||||
} |
|
||||
} |
|
||||
void stop_timer() { |
|
||||
if (d_timer_on) { |
|
||||
d_duration += std::chrono::high_resolution_clock::now() - d_start; |
|
||||
d_timer_on = false; |
|
||||
} |
|
||||
} |
|
||||
void reset_timer() { |
|
||||
if (d_timer_on) { |
|
||||
d_start = std::chrono::high_resolution_clock::now(); |
|
||||
} |
|
||||
d_duration = std::chrono::nanoseconds::zero(); |
|
||||
} |
|
||||
|
|
||||
void set_bytes(int64_t bytes) { d_num_bytes = bytes; } |
|
||||
|
|
||||
size_t get_ns_per_op() { |
|
||||
if (d_num_iterations <= 0) { |
|
||||
return 0; |
|
||||
} |
|
||||
return d_duration.count() / d_num_iterations; |
|
||||
} |
|
||||
|
|
||||
void run_n(size_t n) { |
|
||||
d_num_iterations = n; |
|
||||
reset_timer(); |
|
||||
start_timer(); |
|
||||
d_benchmark.get_func()(this); |
|
||||
stop_timer(); |
|
||||
} |
|
||||
|
|
||||
void run_parallel(std::function<void(parallel_context*)> f) { |
|
||||
parallel_context pc(d_num_iterations); |
|
||||
std::vector<std::thread> threads; |
|
||||
for (size_t i = 0; i < d_num_threads; ++i) { |
|
||||
threads.push_back(std::thread([&pc,&f]() -> void { |
|
||||
f(&pc); |
|
||||
})); |
|
||||
} |
|
||||
for(auto& thread : threads){ |
|
||||
thread.join(); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
result run() { |
|
||||
size_t n = 1; |
|
||||
run_n(n); |
|
||||
while (d_duration < d_benchtime && n < 1e9) { |
|
||||
size_t last = n; |
|
||||
if (get_ns_per_op() == 0) { |
|
||||
n = 1e9; |
|
||||
} else { |
|
||||
n = d_duration.count() / get_ns_per_op(); |
|
||||
} |
|
||||
n = std::max(std::min(n+n/2, 100*last), last+1); |
|
||||
n = round_up(n); |
|
||||
run_n(n); |
|
||||
} |
|
||||
return result(n, d_duration, d_num_bytes); |
|
||||
} |
|
||||
|
|
||||
private: |
|
||||
template<typename T> |
|
||||
T round_down_10(T n) { |
|
||||
int tens = 0; |
|
||||
while (n > 10) { |
|
||||
n /= 10; |
|
||||
tens++; |
|
||||
} |
|
||||
int result = 1; |
|
||||
for (int i = 0; i < tens; ++i) { |
|
||||
result *= 10; |
|
||||
} |
|
||||
return result; |
|
||||
} |
|
||||
|
|
||||
template<typename T> |
|
||||
T round_up(T n) { |
|
||||
T base = round_down_10(n); |
|
||||
if (n < (2 * base)) { |
|
||||
return 2 * base; |
|
||||
} |
|
||||
if (n < (5 * base)) { |
|
||||
return 5 * base; |
|
||||
} |
|
||||
return 10 * base; |
|
||||
} |
|
||||
}; |
|
||||
|
|
||||
/*
|
|
||||
* The run_benchmarks function will run the registered benchmarks. |
|
||||
*/ |
|
||||
void run_benchmarks(const options& opts) { |
|
||||
std::regex match_r(opts.get_bench()); |
|
||||
auto benchmarks = registration::get_ptr()->get_benchmarks(); |
|
||||
for (auto& info : benchmarks) { |
|
||||
if (std::regex_match(info.get_name(), match_r)) { |
|
||||
context c(info, opts); |
|
||||
auto r = c.run(); |
|
||||
std::cout << std::setw(35) << std::left << info.get_name() << r.to_string() << std::endl; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
} // namespace benchpress
|
|
||||
|
|
||||
/*
|
|
||||
* If BENCHPRESS_CONFIG_MAIN is defined when the file is included then a main function will be emitted which provides a |
|
||||
* command-line parser and then executes run_benchmarks. |
|
||||
*/ |
|
||||
#ifdef BENCHPRESS_CONFIG_MAIN
|
|
||||
#include "cxxopts.hpp"
|
|
||||
benchpress::registration* benchpress::registration::d_this; |
|
||||
int main(int argc, char** argv) { |
|
||||
std::chrono::high_resolution_clock::time_point bp_start = std::chrono::high_resolution_clock::now(); |
|
||||
benchpress::options bench_opts; |
|
||||
try { |
|
||||
cxxopts::Options cmd_opts(argv[0], " - command line options"); |
|
||||
cmd_opts.add_options() |
|
||||
("bench", "run benchmarks matching the regular expression", cxxopts::value<std::string>() |
|
||||
->default_value(".*")) |
|
||||
("benchtime", "run enough iterations of each benchmark to take t seconds", cxxopts::value<size_t>() |
|
||||
->default_value("1")) |
|
||||
("cpu", "specify the number of threads to use for parallel benchmarks", cxxopts::value<size_t>() |
|
||||
->default_value(std::to_string(std::thread::hardware_concurrency()))) |
|
||||
("help", "print help") |
|
||||
; |
|
||||
cmd_opts.parse(argc, argv); |
|
||||
if (cmd_opts.count("help")) { |
|
||||
std::cout << cmd_opts.help({""}) << std::endl; |
|
||||
exit(0); |
|
||||
} |
|
||||
if (cmd_opts.count("bench")) { |
|
||||
bench_opts.bench(cmd_opts["bench"].as<std::string>()); |
|
||||
} |
|
||||
if (cmd_opts.count("benchtime")) { |
|
||||
bench_opts.benchtime(cmd_opts["benchtime"].as<size_t>()); |
|
||||
} |
|
||||
if (cmd_opts.count("cpu")) { |
|
||||
bench_opts.cpu(cmd_opts["cpu"].as<size_t>()); |
|
||||
} |
|
||||
} catch (const cxxopts::OptionException& e) { |
|
||||
std::cout << "error parsing options: " << e.what() << std::endl; |
|
||||
exit(1); |
|
||||
} |
|
||||
benchpress::run_benchmarks(bench_opts); |
|
||||
float duration = std::chrono::duration_cast<std::chrono::milliseconds>( |
|
||||
std::chrono::high_resolution_clock::now() - bp_start |
|
||||
).count() / 1000.f; |
|
||||
std::cout << argv[0] << " " << duration << "s" << std::endl; |
|
||||
return 0; |
|
||||
} |
|
||||
#endif
|
|
||||
|
|
||||
#endif // BENCHPRESS_HPP
|
|
1312
resources/3rdparty/modernjson/benchmarks/cxxopts.hpp
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -1 +0,0 @@ |
|||||
a533fde78ce50a11f6189907f9e0392095222fe2 |
|
9
resources/3rdparty/modernjson/benchmarks/files/nativejson-benchmark/canada.json
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
50469
resources/3rdparty/modernjson/benchmarks/files/nativejson-benchmark/citm_catalog.json
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
15482
resources/3rdparty/modernjson/benchmarks/files/nativejson-benchmark/twitter.json
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -1,317 +0,0 @@ |
|||||
# Doxyfile 1.8.9.1 |
|
||||
|
|
||||
#--------------------------------------------------------------------------- |
|
||||
# Project related configuration options |
|
||||
#--------------------------------------------------------------------------- |
|
||||
DOXYFILE_ENCODING = UTF-8 |
|
||||
PROJECT_NAME = "JSON for Modern C++" |
|
||||
PROJECT_NUMBER = 2.0.0 |
|
||||
PROJECT_BRIEF = |
|
||||
PROJECT_LOGO = |
|
||||
OUTPUT_DIRECTORY = . |
|
||||
CREATE_SUBDIRS = NO |
|
||||
ALLOW_UNICODE_NAMES = NO |
|
||||
OUTPUT_LANGUAGE = English |
|
||||
BRIEF_MEMBER_DESC = YES |
|
||||
REPEAT_BRIEF = NO |
|
||||
ABBREVIATE_BRIEF = |
|
||||
ALWAYS_DETAILED_SEC = YES |
|
||||
INLINE_INHERITED_MEMB = NO |
|
||||
FULL_PATH_NAMES = YES |
|
||||
STRIP_FROM_PATH = |
|
||||
STRIP_FROM_INC_PATH = |
|
||||
SHORT_NAMES = NO |
|
||||
JAVADOC_AUTOBRIEF = NO |
|
||||
QT_AUTOBRIEF = NO |
|
||||
MULTILINE_CPP_IS_BRIEF = NO |
|
||||
INHERIT_DOCS = YES |
|
||||
SEPARATE_MEMBER_PAGES = YES |
|
||||
TAB_SIZE = 4 |
|
||||
ALIASES = "complexity=@par Complexity\n" |
|
||||
ALIASES += liveexample{2}="@par Example\n \1 \n @includelineno \2.cpp \n Output (play with this example @htmlinclude \2.link):\n @verbinclude \2.output \n The example code above can be translated with @verbatim g++ -std=c++11 -Isrc doc/examples/\2.cpp -o \2 @endverbatim" |
|
||||
ALIASES += requirement="@par Requirements\n" |
|
||||
ALIASES += exceptionsafety="@par Exception safety\n" |
|
||||
TCL_SUBST = |
|
||||
OPTIMIZE_OUTPUT_FOR_C = NO |
|
||||
OPTIMIZE_OUTPUT_JAVA = NO |
|
||||
OPTIMIZE_FOR_FORTRAN = NO |
|
||||
OPTIMIZE_OUTPUT_VHDL = NO |
|
||||
EXTENSION_MAPPING = |
|
||||
MARKDOWN_SUPPORT = YES |
|
||||
AUTOLINK_SUPPORT = NO |
|
||||
BUILTIN_STL_SUPPORT = YES |
|
||||
CPP_CLI_SUPPORT = NO |
|
||||
SIP_SUPPORT = NO |
|
||||
IDL_PROPERTY_SUPPORT = YES |
|
||||
DISTRIBUTE_GROUP_DOC = NO |
|
||||
SUBGROUPING = YES |
|
||||
INLINE_GROUPED_CLASSES = NO |
|
||||
INLINE_SIMPLE_STRUCTS = NO |
|
||||
TYPEDEF_HIDES_STRUCT = NO |
|
||||
LOOKUP_CACHE_SIZE = 0 |
|
||||
#--------------------------------------------------------------------------- |
|
||||
# Build related configuration options |
|
||||
#--------------------------------------------------------------------------- |
|
||||
EXTRACT_ALL = YES |
|
||||
EXTRACT_PRIVATE = NO |
|
||||
EXTRACT_PACKAGE = YES |
|
||||
EXTRACT_STATIC = YES |
|
||||
EXTRACT_LOCAL_CLASSES = YES |
|
||||
EXTRACT_LOCAL_METHODS = YES |
|
||||
EXTRACT_ANON_NSPACES = YES |
|
||||
HIDE_UNDOC_MEMBERS = NO |
|
||||
HIDE_UNDOC_CLASSES = NO |
|
||||
HIDE_FRIEND_COMPOUNDS = NO |
|
||||
HIDE_IN_BODY_DOCS = NO |
|
||||
INTERNAL_DOCS = NO |
|
||||
CASE_SENSE_NAMES = NO |
|
||||
HIDE_SCOPE_NAMES = NO |
|
||||
HIDE_COMPOUND_REFERENCE= NO |
|
||||
SHOW_INCLUDE_FILES = YES |
|
||||
SHOW_GROUPED_MEMB_INC = NO |
|
||||
FORCE_LOCAL_INCLUDES = NO |
|
||||
INLINE_INFO = YES |
|
||||
SORT_MEMBER_DOCS = YES |
|
||||
SORT_BRIEF_DOCS = YES |
|
||||
SORT_MEMBERS_CTORS_1ST = YES |
|
||||
SORT_GROUP_NAMES = NO |
|
||||
SORT_BY_SCOPE_NAME = NO |
|
||||
STRICT_PROTO_MATCHING = NO |
|
||||
GENERATE_TODOLIST = YES |
|
||||
GENERATE_TESTLIST = YES |
|
||||
GENERATE_BUGLIST = YES |
|
||||
GENERATE_DEPRECATEDLIST= YES |
|
||||
ENABLED_SECTIONS = |
|
||||
MAX_INITIALIZER_LINES = 30 |
|
||||
SHOW_USED_FILES = NO |
|
||||
SHOW_FILES = NO |
|
||||
SHOW_NAMESPACES = NO |
|
||||
FILE_VERSION_FILTER = |
|
||||
LAYOUT_FILE = |
|
||||
CITE_BIB_FILES = |
|
||||
#--------------------------------------------------------------------------- |
|
||||
# Configuration options related to warning and progress messages |
|
||||
#--------------------------------------------------------------------------- |
|
||||
QUIET = YES |
|
||||
WARNINGS = YES |
|
||||
WARN_IF_UNDOCUMENTED = YES |
|
||||
WARN_IF_DOC_ERROR = YES |
|
||||
WARN_NO_PARAMDOC = YES |
|
||||
WARN_FORMAT = "$file:$line: $text" |
|
||||
WARN_LOGFILE = |
|
||||
#--------------------------------------------------------------------------- |
|
||||
# Configuration options related to the input files |
|
||||
#--------------------------------------------------------------------------- |
|
||||
INPUT = ../src/json.hpp index.md |
|
||||
INPUT_ENCODING = UTF-8 |
|
||||
FILE_PATTERNS = |
|
||||
RECURSIVE = NO |
|
||||
EXCLUDE = |
|
||||
EXCLUDE_SYMLINKS = NO |
|
||||
EXCLUDE_PATTERNS = |
|
||||
EXCLUDE_SYMBOLS = nlohmann::anonymous_namespace |
|
||||
EXAMPLE_PATH = examples |
|
||||
EXAMPLE_PATTERNS = |
|
||||
EXAMPLE_RECURSIVE = NO |
|
||||
IMAGE_PATH = images |
|
||||
INPUT_FILTER = |
|
||||
FILTER_PATTERNS = |
|
||||
FILTER_SOURCE_FILES = NO |
|
||||
FILTER_SOURCE_PATTERNS = |
|
||||
USE_MDFILE_AS_MAINPAGE = index.md |
|
||||
#--------------------------------------------------------------------------- |
|
||||
# Configuration options related to source browsing |
|
||||
#--------------------------------------------------------------------------- |
|
||||
SOURCE_BROWSER = YES |
|
||||
INLINE_SOURCES = NO |
|
||||
STRIP_CODE_COMMENTS = YES |
|
||||
REFERENCED_BY_RELATION = NO |
|
||||
REFERENCES_RELATION = NO |
|
||||
REFERENCES_LINK_SOURCE = NO |
|
||||
SOURCE_TOOLTIPS = YES |
|
||||
USE_HTAGS = NO |
|
||||
VERBATIM_HEADERS = NO |
|
||||
#--------------------------------------------------------------------------- |
|
||||
# Configuration options related to the alphabetical class index |
|
||||
#--------------------------------------------------------------------------- |
|
||||
ALPHABETICAL_INDEX = YES |
|
||||
COLS_IN_ALPHA_INDEX = 5 |
|
||||
IGNORE_PREFIX = |
|
||||
#--------------------------------------------------------------------------- |
|
||||
# Configuration options related to the HTML output |
|
||||
#--------------------------------------------------------------------------- |
|
||||
GENERATE_HTML = YES |
|
||||
HTML_OUTPUT = html |
|
||||
HTML_FILE_EXTENSION = .html |
|
||||
HTML_HEADER = |
|
||||
HTML_FOOTER = |
|
||||
HTML_STYLESHEET = |
|
||||
HTML_EXTRA_STYLESHEET = css/mylayout.css |
|
||||
HTML_EXTRA_FILES = |
|
||||
HTML_COLORSTYLE_HUE = 220 |
|
||||
HTML_COLORSTYLE_SAT = 100 |
|
||||
HTML_COLORSTYLE_GAMMA = 80 |
|
||||
HTML_TIMESTAMP = YES |
|
||||
HTML_DYNAMIC_SECTIONS = YES |
|
||||
HTML_INDEX_NUM_ENTRIES = 100 |
|
||||
GENERATE_DOCSET = YES |
|
||||
DOCSET_FEEDNAME = "Doxygen generated docs" |
|
||||
DOCSET_BUNDLE_ID = me.nlohmann.json |
|
||||
DOCSET_PUBLISHER_ID = me.nlohmann |
|
||||
DOCSET_PUBLISHER_NAME = Niels Lohmann |
|
||||
GENERATE_HTMLHELP = NO |
|
||||
CHM_FILE = |
|
||||
HHC_LOCATION = |
|
||||
GENERATE_CHI = NO |
|
||||
CHM_INDEX_ENCODING = |
|
||||
BINARY_TOC = NO |
|
||||
TOC_EXPAND = NO |
|
||||
GENERATE_QHP = NO |
|
||||
QCH_FILE = |
|
||||
QHP_NAMESPACE = org.doxygen.Project |
|
||||
QHP_VIRTUAL_FOLDER = doc |
|
||||
QHP_CUST_FILTER_NAME = |
|
||||
QHP_CUST_FILTER_ATTRS = |
|
||||
QHP_SECT_FILTER_ATTRS = |
|
||||
QHG_LOCATION = |
|
||||
GENERATE_ECLIPSEHELP = NO |
|
||||
ECLIPSE_DOC_ID = org.doxygen.Project |
|
||||
DISABLE_INDEX = NO |
|
||||
GENERATE_TREEVIEW = NO |
|
||||
ENUM_VALUES_PER_LINE = 4 |
|
||||
TREEVIEW_WIDTH = 250 |
|
||||
EXT_LINKS_IN_WINDOW = NO |
|
||||
FORMULA_FONTSIZE = 10 |
|
||||
FORMULA_TRANSPARENT = YES |
|
||||
USE_MATHJAX = NO |
|
||||
MATHJAX_FORMAT = HTML-CSS |
|
||||
MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest |
|
||||
MATHJAX_EXTENSIONS = |
|
||||
MATHJAX_CODEFILE = |
|
||||
SEARCHENGINE = YES |
|
||||
SERVER_BASED_SEARCH = NO |
|
||||
EXTERNAL_SEARCH = NO |
|
||||
SEARCHENGINE_URL = |
|
||||
SEARCHDATA_FILE = searchdata.xml |
|
||||
EXTERNAL_SEARCH_ID = |
|
||||
EXTRA_SEARCH_MAPPINGS = |
|
||||
#--------------------------------------------------------------------------- |
|
||||
# Configuration options related to the LaTeX output |
|
||||
#--------------------------------------------------------------------------- |
|
||||
GENERATE_LATEX = NO |
|
||||
LATEX_OUTPUT = latex |
|
||||
LATEX_CMD_NAME = latex |
|
||||
MAKEINDEX_CMD_NAME = makeindex |
|
||||
COMPACT_LATEX = NO |
|
||||
PAPER_TYPE = a4 |
|
||||
EXTRA_PACKAGES = |
|
||||
LATEX_HEADER = |
|
||||
LATEX_FOOTER = |
|
||||
LATEX_EXTRA_STYLESHEET = |
|
||||
LATEX_EXTRA_FILES = |
|
||||
PDF_HYPERLINKS = YES |
|
||||
USE_PDFLATEX = YES |
|
||||
LATEX_BATCHMODE = NO |
|
||||
LATEX_HIDE_INDICES = NO |
|
||||
LATEX_SOURCE_CODE = NO |
|
||||
LATEX_BIB_STYLE = plain |
|
||||
#--------------------------------------------------------------------------- |
|
||||
# Configuration options related to the RTF output |
|
||||
#--------------------------------------------------------------------------- |
|
||||
GENERATE_RTF = NO |
|
||||
RTF_OUTPUT = rtf |
|
||||
COMPACT_RTF = NO |
|
||||
RTF_HYPERLINKS = NO |
|
||||
RTF_STYLESHEET_FILE = |
|
||||
RTF_EXTENSIONS_FILE = |
|
||||
RTF_SOURCE_CODE = NO |
|
||||
#--------------------------------------------------------------------------- |
|
||||
# Configuration options related to the man page output |
|
||||
#--------------------------------------------------------------------------- |
|
||||
GENERATE_MAN = NO |
|
||||
MAN_OUTPUT = man |
|
||||
MAN_EXTENSION = .3 |
|
||||
MAN_SUBDIR = |
|
||||
MAN_LINKS = NO |
|
||||
#--------------------------------------------------------------------------- |
|
||||
# Configuration options related to the XML output |
|
||||
#--------------------------------------------------------------------------- |
|
||||
GENERATE_XML = NO |
|
||||
XML_OUTPUT = xml |
|
||||
XML_PROGRAMLISTING = YES |
|
||||
#--------------------------------------------------------------------------- |
|
||||
# Configuration options related to the DOCBOOK output |
|
||||
#--------------------------------------------------------------------------- |
|
||||
GENERATE_DOCBOOK = NO |
|
||||
DOCBOOK_OUTPUT = docbook |
|
||||
DOCBOOK_PROGRAMLISTING = NO |
|
||||
#--------------------------------------------------------------------------- |
|
||||
# Configuration options for the AutoGen Definitions output |
|
||||
#--------------------------------------------------------------------------- |
|
||||
GENERATE_AUTOGEN_DEF = NO |
|
||||
#--------------------------------------------------------------------------- |
|
||||
# Configuration options related to the Perl module output |
|
||||
#--------------------------------------------------------------------------- |
|
||||
GENERATE_PERLMOD = NO |
|
||||
PERLMOD_LATEX = NO |
|
||||
PERLMOD_PRETTY = YES |
|
||||
PERLMOD_MAKEVAR_PREFIX = |
|
||||
#--------------------------------------------------------------------------- |
|
||||
# Configuration options related to the preprocessor |
|
||||
#--------------------------------------------------------------------------- |
|
||||
ENABLE_PREPROCESSING = YES |
|
||||
MACRO_EXPANSION = NO |
|
||||
EXPAND_ONLY_PREDEF = NO |
|
||||
SEARCH_INCLUDES = YES |
|
||||
INCLUDE_PATH = |
|
||||
INCLUDE_FILE_PATTERNS = |
|
||||
PREDEFINED = |
|
||||
EXPAND_AS_DEFINED = |
|
||||
SKIP_FUNCTION_MACROS = YES |
|
||||
#--------------------------------------------------------------------------- |
|
||||
# Configuration options related to external references |
|
||||
#--------------------------------------------------------------------------- |
|
||||
TAGFILES = |
|
||||
GENERATE_TAGFILE = |
|
||||
ALLEXTERNALS = NO |
|
||||
EXTERNAL_GROUPS = YES |
|
||||
EXTERNAL_PAGES = YES |
|
||||
PERL_PATH = /usr/bin/perl |
|
||||
#--------------------------------------------------------------------------- |
|
||||
# Configuration options related to the dot tool |
|
||||
#--------------------------------------------------------------------------- |
|
||||
CLASS_DIAGRAMS = NO |
|
||||
MSCGEN_PATH = |
|
||||
DIA_PATH = |
|
||||
HIDE_UNDOC_RELATIONS = YES |
|
||||
HAVE_DOT = YES |
|
||||
DOT_NUM_THREADS = 0 |
|
||||
DOT_FONTNAME = Helvetica |
|
||||
DOT_FONTSIZE = 10 |
|
||||
DOT_FONTPATH = |
|
||||
CLASS_GRAPH = NO |
|
||||
COLLABORATION_GRAPH = NO |
|
||||
GROUP_GRAPHS = YES |
|
||||
UML_LOOK = YES |
|
||||
UML_LIMIT_NUM_FIELDS = 10 |
|
||||
TEMPLATE_RELATIONS = NO |
|
||||
INCLUDE_GRAPH = NO |
|
||||
INCLUDED_BY_GRAPH = NO |
|
||||
CALL_GRAPH = NO |
|
||||
CALLER_GRAPH = NO |
|
||||
GRAPHICAL_HIERARCHY = NO |
|
||||
DIRECTORY_GRAPH = NO |
|
||||
DOT_IMAGE_FORMAT = svg |
|
||||
INTERACTIVE_SVG = YES |
|
||||
DOT_PATH = |
|
||||
DOTFILE_DIRS = |
|
||||
MSCFILE_DIRS = |
|
||||
DIAFILE_DIRS = |
|
||||
PLANTUML_JAR_PATH = |
|
||||
PLANTUML_INCLUDE_PATH = |
|
||||
DOT_GRAPH_MAX_NODES = 50 |
|
||||
MAX_DOT_GRAPH_DEPTH = 0 |
|
||||
DOT_TRANSPARENT = NO |
|
||||
DOT_MULTI_TARGETS = NO |
|
||||
GENERATE_LEGEND = YES |
|
||||
DOT_CLEANUP = YES |
|
@ -1,82 +0,0 @@ |
|||||
SRCDIR = ../src |
|
||||
|
|
||||
all: doxygen |
|
||||
|
|
||||
clean: |
|
||||
rm -fr me.nlohmann.json.docset html |
|
||||
|
|
||||
|
|
||||
##########################################################################
|
|
||||
# example files
|
|
||||
##########################################################################
|
|
||||
|
|
||||
# where are the example cpp files
|
|
||||
EXAMPLES = $(wildcard examples/*.cpp) |
|
||||
|
|
||||
# create output from a stand-alone example file
|
|
||||
%.output: %.cpp |
|
||||
make $(<:.cpp=) CPPFLAGS="-I $(SRCDIR)" CXXFLAGS="-std=c++11" |
|
||||
./$(<:.cpp=) > $@ |
|
||||
rm $(<:.cpp=) |
|
||||
|
|
||||
# compare created output with current output of the example files
|
|
||||
%.test: %.cpp |
|
||||
make $(<:.cpp=) CPPFLAGS="-I $(SRCDIR)" CXXFLAGS="-std=c++11" |
|
||||
./$(<:.cpp=) > $@ |
|
||||
diff $@ $(<:.cpp=.output) |
|
||||
rm $(<:.cpp=) $@ |
|
||||
|
|
||||
# create links to try the code online
|
|
||||
%.link: %.cpp |
|
||||
rm -fr tmp |
|
||||
mkdir tmp |
|
||||
cp $(SRCDIR)/json.hpp tmp |
|
||||
scripts/send_to_wandbox.py tmp $< > $@.tmp |
|
||||
/bin/echo -n "<a target=\"_blank\" href=\"`cat $@.tmp`\"><b>online</b></a>" > $@ |
|
||||
rm -fr tmp $@.tmp |
|
||||
|
|
||||
# create output from all stand-alone example files
|
|
||||
create_output: $(EXAMPLES:.cpp=.output) |
|
||||
|
|
||||
create_links: $(EXAMPLES:.cpp=.link) |
|
||||
|
|
||||
# check output of all stand-alone example files
|
|
||||
check_output: $(EXAMPLES:.cpp=.test) |
|
||||
|
|
||||
|
|
||||
##########################################################################
|
|
||||
# Doxygen HTML documentation
|
|
||||
##########################################################################
|
|
||||
|
|
||||
# create Doxygen documentation
|
|
||||
doxygen: create_output create_links |
|
||||
doxygen |
|
||||
gsed -i 's@< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType >@@g' html/*.html |
|
||||
gsed -i 's@< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType >@@g' html/*.html |
|
||||
gsed -i 's@< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >@@g' html/*.html |
|
||||
gsed -i 's@< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType >@@g' html/*.html |
|
||||
|
|
||||
upload: clean doxygen check_output |
|
||||
cd html ; ../scripts/git-update-ghpages nlohmann/json |
|
||||
rm -fr html |
|
||||
open http://nlohmann.github.io/json/ |
|
||||
|
|
||||
|
|
||||
##########################################################################
|
|
||||
# docset
|
|
||||
##########################################################################
|
|
||||
|
|
||||
# create docset for Dash
|
|
||||
docset: create_output |
|
||||
cp Doxyfile Doxyfile_docset |
|
||||
gsed -i 's/DISABLE_INDEX = NO/DISABLE_INDEX = YES/' Doxyfile_docset |
|
||||
gsed -i 's/SEARCHENGINE = YES/SEARCHENGINE = NO/' Doxyfile_docset |
|
||||
gsed -i 's@HTML_EXTRA_STYLESHEET = css/mylayout.css@HTML_EXTRA_STYLESHEET = css/mylayout_docset.css@' Doxyfile_docset |
|
||||
rm -fr html *.docset |
|
||||
doxygen Doxyfile_docset |
|
||||
gsed -i 's@< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType >@@g' html/*.html |
|
||||
gsed -i 's@< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType >@@g' html/*.html |
|
||||
make -C html |
|
||||
mv html/*.docset . |
|
||||
gsed -i 's@<string>doxygen</string>@<string>json</string>@' me.nlohmann.json.docset/Contents/Info.plist |
|
||||
rm -fr Doxyfile_docset html |
|
@ -1,26 +0,0 @@ |
|||||
/* hide lengthy template information */ |
|
||||
.memtemplate, .memTemplParams { |
|
||||
display: none; |
|
||||
} |
|
||||
|
|
||||
/* allow compiler information to wrap */ |
|
||||
/* https://css-tricks.com/snippets/css/make-pre-text-wrap/ */ |
|
||||
pre.fragment { |
|
||||
white-space: pre-wrap; /* css-3 */ |
|
||||
white-space: -moz-pre-wrap; /* Mozilla, since 1999 */ |
|
||||
white-space: -pre-wrap; /* Opera 4-6 */ |
|
||||
white-space: -o-pre-wrap; /* Opera 7 */ |
|
||||
word-wrap: break-word; /* Internet Explorer 5.5+ */ |
|
||||
} |
|
||||
|
|
||||
td.paramname { |
|
||||
vertical-align: top; |
|
||||
} |
|
||||
|
|
||||
.ok_green { |
|
||||
background-color: #89C35C; |
|
||||
} |
|
||||
|
|
||||
.nok_throws { |
|
||||
background-color: #ffa500; |
|
||||
} |
|
@ -1,27 +0,0 @@ |
|||||
.memtemplate { |
|
||||
display: none; |
|
||||
} |
|
||||
|
|
||||
.memTemplParams { |
|
||||
display: none; |
|
||||
} |
|
||||
|
|
||||
.navtab { |
|
||||
display: none; |
|
||||
} |
|
||||
|
|
||||
#top, .footer { |
|
||||
display: none; |
|
||||
} |
|
||||
|
|
||||
td.paramname { |
|
||||
vertical-align: top; |
|
||||
} |
|
||||
|
|
||||
.ok_green { |
|
||||
background-color: #89C35C; |
|
||||
} |
|
||||
|
|
||||
.nok_throws { |
|
||||
background-color: #ffa500; |
|
||||
} |
|
@ -1,36 +0,0 @@ |
|||||
#include <json.hpp>
|
|
||||
|
|
||||
using json = nlohmann::json; |
|
||||
|
|
||||
int main() |
|
||||
{ |
|
||||
// create a JSON object
|
|
||||
json j = |
|
||||
{ |
|
||||
{"pi", 3.141}, |
|
||||
{"happy", true}, |
|
||||
{"name", "Niels"}, |
|
||||
{"nothing", nullptr}, |
|
||||
{ |
|
||||
"answer", { |
|
||||
{"everything", 42} |
|
||||
} |
|
||||
}, |
|
||||
{"list", {1, 0, 2}}, |
|
||||
{ |
|
||||
"object", { |
|
||||
{"currency", "USD"}, |
|
||||
{"value", 42.99} |
|
||||
} |
|
||||
} |
|
||||
}; |
|
||||
|
|
||||
// add new values
|
|
||||
j["new"]["key"]["value"] = {"another", "list"}; |
|
||||
|
|
||||
// count elements
|
|
||||
j["size"] = j.size(); |
|
||||
|
|
||||
// pretty print with indent of 4 spaces
|
|
||||
std::cout << std::setw(4) << j << '\n'; |
|
||||
} |
|
@ -1 +0,0 @@ |
|||||
<a target="_blank" href="http://melpon.org/wandbox/permlink/fYyscqrsQFtgUePA"><b>online</b></a> |
|
@ -1,27 +0,0 @@ |
|||||
{ |
|
||||
"answer": { |
|
||||
"everything": 42 |
|
||||
}, |
|
||||
"happy": true, |
|
||||
"list": [ |
|
||||
1, |
|
||||
0, |
|
||||
2 |
|
||||
], |
|
||||
"name": "Niels", |
|
||||
"new": { |
|
||||
"key": { |
|
||||
"value": [ |
|
||||
"another", |
|
||||
"list" |
|
||||
] |
|
||||
} |
|
||||
}, |
|
||||
"nothing": null, |
|
||||
"object": { |
|
||||
"currency": "USD", |
|
||||
"value": 42.99 |
|
||||
}, |
|
||||
"pi": 3.141, |
|
||||
"size": 9 |
|
||||
} |
|
@ -1,18 +0,0 @@ |
|||||
#include <json.hpp>
|
|
||||
|
|
||||
using json = nlohmann::json; |
|
||||
|
|
||||
int main() |
|
||||
{ |
|
||||
// create JSON arrays
|
|
||||
json j_no_init_list = json::array(); |
|
||||
json j_empty_init_list = json::array({}); |
|
||||
json j_nonempty_init_list = json::array({1, 2, 3, 4}); |
|
||||
json j_list_of_pairs = json::array({ {"one", 1}, {"two", 2} }); |
|
||||
|
|
||||
// serialize the JSON arrays
|
|
||||
std::cout << j_no_init_list << '\n'; |
|
||||
std::cout << j_empty_init_list << '\n'; |
|
||||
std::cout << j_nonempty_init_list << '\n'; |
|
||||
std::cout << j_list_of_pairs << '\n'; |
|
||||
} |
|
@ -1 +0,0 @@ |
|||||
<a target="_blank" href="http://melpon.org/wandbox/permlink/TTykAqoDgbLzKxt3"><b>online</b></a> |
|
@ -1,4 +0,0 @@ |
|||||
[] |
|
||||
[] |
|
||||
[1,2,3,4] |
|
||||
[["one",1],["two",2]] |
|
@ -1,33 +0,0 @@ |
|||||
#include <json.hpp>
|
|
||||
|
|
||||
using json = nlohmann::json; |
|
||||
|
|
||||
int main() |
|
||||
{ |
|
||||
// create JSON object
|
|
||||
json object = |
|
||||
{ |
|
||||
{"the good", "il buono"}, |
|
||||
{"the bad", "il cativo"}, |
|
||||
{"the ugly", "il brutto"} |
|
||||
}; |
|
||||
|
|
||||
// output element with key "the ugly"
|
|
||||
std::cout << object.at("the ugly") << '\n'; |
|
||||
|
|
||||
// change element with key "the bad"
|
|
||||
object.at("the bad") = "il cattivo"; |
|
||||
|
|
||||
// output changed array
|
|
||||
std::cout << object << '\n'; |
|
||||
|
|
||||
// try to write at a nonexisting key
|
|
||||
try |
|
||||
{ |
|
||||
object.at("the fast") = "il rapido"; |
|
||||
} |
|
||||
catch (std::out_of_range& e) |
|
||||
{ |
|
||||
std::cout << "out of range: " << e.what() << '\n'; |
|
||||
} |
|
||||
} |
|
@ -1 +0,0 @@ |
|||||
<a target="_blank" href="http://melpon.org/wandbox/permlink/wjOUJUwo2SO7q5u8"><b>online</b></a> |
|
@ -1,3 +0,0 @@ |
|||||
"il brutto" |
|
||||
{"the bad":"il cattivo","the good":"il buono","the ugly":"il brutto"} |
|
||||
out of range: key 'the fast' not found |
|
@ -1,27 +0,0 @@ |
|||||
#include <json.hpp>
|
|
||||
|
|
||||
using json = nlohmann::json; |
|
||||
|
|
||||
int main() |
|
||||
{ |
|
||||
// create JSON object
|
|
||||
json object = |
|
||||
{ |
|
||||
{"the good", "il buono"}, |
|
||||
{"the bad", "il cativo"}, |
|
||||
{"the ugly", "il brutto"} |
|
||||
}; |
|
||||
|
|
||||
// output element with key "the ugly"
|
|
||||
std::cout << object.at("the ugly") << '\n'; |
|
||||
|
|
||||
// try to read from a nonexisting key
|
|
||||
try |
|
||||
{ |
|
||||
std::cout << object.at("the fast") << '\n'; |
|
||||
} |
|
||||
catch (std::out_of_range) |
|
||||
{ |
|
||||
std::cout << "out of range" << '\n'; |
|
||||
} |
|
||||
} |
|
@ -1 +0,0 @@ |
|||||
<a target="_blank" href="http://melpon.org/wandbox/permlink/7gGtalpuoF4xE7VN"><b>online</b></a> |
|
@ -1,2 +0,0 @@ |
|||||
"il brutto" |
|
||||
out of range |
|
@ -1,28 +0,0 @@ |
|||||
#include <json.hpp>
|
|
||||
|
|
||||
using json = nlohmann::json; |
|
||||
|
|
||||
int main() |
|
||||
{ |
|
||||
// create JSON array
|
|
||||
json array = {"first", "2nd", "third", "fourth"}; |
|
||||
|
|
||||
// output element at index 2 (third element)
|
|
||||
std::cout << array.at(2) << '\n'; |
|
||||
|
|
||||
// change element at index 1 (second element) to "second"
|
|
||||
array.at(1) = "second"; |
|
||||
|
|
||||
// output changed array
|
|
||||
std::cout << array << '\n'; |
|
||||
|
|
||||
// try to write beyond the array limit
|
|
||||
try |
|
||||
{ |
|
||||
array.at(5) = "sixth"; |
|
||||
} |
|
||||
catch (std::out_of_range& e) |
|
||||
{ |
|
||||
std::cout << "out of range: " << e.what() << '\n'; |
|
||||
} |
|
||||
} |
|
@ -1 +0,0 @@ |
|||||
<a target="_blank" href="http://melpon.org/wandbox/permlink/Sa6XYQS7TJ5sGG8a"><b>online</b></a> |
|
@ -1,3 +0,0 @@ |
|||||
"third" |
|
||||
["first","second","third","fourth"] |
|
||||
out of range: array index 5 is out of range |
|
@ -1,22 +0,0 @@ |
|||||
#include <json.hpp>
|
|
||||
|
|
||||
using json = nlohmann::json; |
|
||||
|
|
||||
int main() |
|
||||
{ |
|
||||
// create JSON array
|
|
||||
json array = {"first", "2nd", "third", "fourth"}; |
|
||||
|
|
||||
// output element at index 2 (third element)
|
|
||||
std::cout << array.at(2) << '\n'; |
|
||||
|
|
||||
// try to read beyond the array limit
|
|
||||
try |
|
||||
{ |
|
||||
std::cout << array.at(5) << '\n'; |
|
||||
} |
|
||||
catch (std::out_of_range) |
|
||||
{ |
|
||||
std::cout << "out of range" << '\n'; |
|
||||
} |
|
||||
} |
|
@ -1 +0,0 @@ |
|||||
<a target="_blank" href="http://melpon.org/wandbox/permlink/PGQOjyIV7s5YnsQM"><b>online</b></a> |
|
@ -1,2 +0,0 @@ |
|||||
"third" |
|
||||
out of range |
|
@ -1,35 +0,0 @@ |
|||||
#include <json.hpp>
|
|
||||
|
|
||||
using json = nlohmann::json; |
|
||||
|
|
||||
int main() |
|
||||
{ |
|
||||
// create a JSON value
|
|
||||
json j = |
|
||||
{ |
|
||||
{"number", 1}, {"string", "foo"}, {"array", {1, 2}} |
|
||||
}; |
|
||||
|
|
||||
// read-only access
|
|
||||
|
|
||||
// output element with JSON pointer "/number"
|
|
||||
std::cout << j.at("/number"_json_pointer) << '\n'; |
|
||||
// output element with JSON pointer "/string"
|
|
||||
std::cout << j.at("/string"_json_pointer) << '\n'; |
|
||||
// output element with JSON pointer "/array"
|
|
||||
std::cout << j.at("/array"_json_pointer) << '\n'; |
|
||||
// output element with JSON pointer "/array/1"
|
|
||||
std::cout << j.at("/array/1"_json_pointer) << '\n'; |
|
||||
|
|
||||
// writing access
|
|
||||
|
|
||||
// change the string
|
|
||||
j.at("/string"_json_pointer) = "bar"; |
|
||||
// output the changed string
|
|
||||
std::cout << j["string"] << '\n'; |
|
||||
|
|
||||
// change an array element
|
|
||||
j.at("/array/1"_json_pointer) = 21; |
|
||||
// output the changed array
|
|
||||
std::cout << j["array"] << '\n'; |
|
||||
} |
|
@ -1 +0,0 @@ |
|||||
<a target="_blank" href="http://melpon.org/wandbox/permlink/NDSjglHZIjIZ0Uxg"><b>online</b></a> |
|
@ -1,6 +0,0 @@ |
|||||
1 |
|
||||
"foo" |
|
||||
[1,2] |
|
||||
2 |
|
||||
"bar" |
|
||||
[1,21] |
|
@ -1,23 +0,0 @@ |
|||||
#include <json.hpp>
|
|
||||
|
|
||||
using json = nlohmann::json; |
|
||||
|
|
||||
int main() |
|
||||
{ |
|
||||
// create a JSON value
|
|
||||
json j = |
|
||||
{ |
|
||||
{"number", 1}, {"string", "foo"}, {"array", {1, 2}} |
|
||||
}; |
|
||||
|
|
||||
// read-only access
|
|
||||
|
|
||||
// output element with JSON pointer "/number"
|
|
||||
std::cout << j.at("/number"_json_pointer) << '\n'; |
|
||||
// output element with JSON pointer "/string"
|
|
||||
std::cout << j.at("/string"_json_pointer) << '\n'; |
|
||||
// output element with JSON pointer "/array"
|
|
||||
std::cout << j.at("/array"_json_pointer) << '\n'; |
|
||||
// output element with JSON pointer "/array/1"
|
|
||||
std::cout << j.at("/array/1"_json_pointer) << '\n'; |
|
||||
} |
|
@ -1 +0,0 @@ |
|||||
<a target="_blank" href="http://melpon.org/wandbox/permlink/OuLYiMJ3pgyOHupb"><b>online</b></a> |
|
@ -1,4 +0,0 @@ |
|||||
1 |
|
||||
"foo" |
|
||||
[1,2] |
|
||||
2 |
|
@ -1,28 +0,0 @@ |
|||||
#include <json.hpp>
|
|
||||
|
|
||||
using json = nlohmann::json; |
|
||||
|
|
||||
int main() |
|
||||
{ |
|
||||
// create JSON values
|
|
||||
json j_null; |
|
||||
json j_boolean = true; |
|
||||
json j_number_integer = 17; |
|
||||
json j_number_float = 23.42; |
|
||||
json j_object = {{"one", 1}, {"two", 2}}; |
|
||||
json j_object_empty(json::value_t::object); |
|
||||
json j_array = {1, 2, 4, 8, 16}; |
|
||||
json j_array_empty(json::value_t::array); |
|
||||
json j_string = "Hello, world"; |
|
||||
|
|
||||
// call back()
|
|
||||
//std::cout << j_null.back() << '\n'; // would throw
|
|
||||
std::cout << j_boolean.back() << '\n'; |
|
||||
std::cout << j_number_integer.back() << '\n'; |
|
||||
std::cout << j_number_float.back() << '\n'; |
|
||||
std::cout << j_object.back() << '\n'; |
|
||||
//std::cout << j_object_empty.back() << '\n'; // undefined behavior
|
|
||||
std::cout << j_array.back() << '\n'; |
|
||||
//std::cout << j_array_empty.back() << '\n'; // undefined behavior
|
|
||||
std::cout << j_string.back() << '\n'; |
|
||||
} |
|
@ -1 +0,0 @@ |
|||||
<a target="_blank" href="http://melpon.org/wandbox/permlink/V7lUsd6LyndZDGoM"><b>online</b></a> |
|
@ -1,6 +0,0 @@ |
|||||
true |
|
||||
17 |
|
||||
23.42 |
|
||||
2 |
|
||||
16 |
|
||||
"Hello, world" |
|
@ -1,12 +0,0 @@ |
|||||
#include <json.hpp>
|
|
||||
|
|
||||
using json = nlohmann::json; |
|
||||
|
|
||||
int main() |
|
||||
{ |
|
||||
// create a JSON value with default null value
|
|
||||
json j; |
|
||||
|
|
||||
// serialize the JSON null value
|
|
||||
std::cout << j << '\n'; |
|
||||
} |
|
@ -1 +0,0 @@ |
|||||
<a target="_blank" href="http://melpon.org/wandbox/permlink/mSAAr3GATT6ciVjV"><b>online</b></a> |
|
@ -1 +0,0 @@ |
|||||
null |
|
@ -1,58 +0,0 @@ |
|||||
#include <json.hpp>
|
|
||||
#include <deque>
|
|
||||
#include <list>
|
|
||||
#include <forward_list>
|
|
||||
#include <set>
|
|
||||
#include <unordered_set>
|
|
||||
|
|
||||
using json = nlohmann::json; |
|
||||
|
|
||||
int main() |
|
||||
{ |
|
||||
// create an array from std::vector
|
|
||||
std::vector<int> c_vector {1, 2, 3, 4}; |
|
||||
json j_vec(c_vector); |
|
||||
|
|
||||
// create an array from std::deque
|
|
||||
std::deque<double> c_deque {1.2, 2.3, 3.4, 5.6}; |
|
||||
json j_deque(c_deque); |
|
||||
|
|
||||
// create an array from std::list
|
|
||||
std::list<bool> c_list {true, true, false, true}; |
|
||||
json j_list(c_list); |
|
||||
|
|
||||
// create an array from std::forward_list
|
|
||||
std::forward_list<int64_t> c_flist {12345678909876, 23456789098765, 34567890987654, 45678909876543}; |
|
||||
json j_flist(c_flist); |
|
||||
|
|
||||
// create an array from std::array
|
|
||||
std::array<unsigned long, 4> c_array {{1, 2, 3, 4}}; |
|
||||
json j_array(c_array); |
|
||||
|
|
||||
// create an array from std::set
|
|
||||
std::set<std::string> c_set {"one", "two", "three", "four", "one"}; |
|
||||
json j_set(c_set); // only one entry for "one" is used
|
|
||||
|
|
||||
// create an array from std::unordered_set
|
|
||||
std::unordered_set<std::string> c_uset {"one", "two", "three", "four", "one"}; |
|
||||
json j_uset(c_uset); // only one entry for "one" is used
|
|
||||
|
|
||||
// create an array from std::multiset
|
|
||||
std::multiset<std::string> c_mset {"one", "two", "one", "four"}; |
|
||||
json j_mset(c_mset); // only one entry for "one" is used
|
|
||||
|
|
||||
// create an array from std::unordered_multiset
|
|
||||
std::unordered_multiset<std::string> c_umset {"one", "two", "one", "four"}; |
|
||||
json j_umset(c_umset); // both entries for "one" are used
|
|
||||
|
|
||||
// serialize the JSON arrays
|
|
||||
std::cout << j_vec << '\n'; |
|
||||
std::cout << j_deque << '\n'; |
|
||||
std::cout << j_list << '\n'; |
|
||||
std::cout << j_flist << '\n'; |
|
||||
std::cout << j_array << '\n'; |
|
||||
std::cout << j_set << '\n'; |
|
||||
std::cout << j_uset << '\n'; |
|
||||
std::cout << j_mset << '\n'; |
|
||||
std::cout << j_umset << '\n'; |
|
||||
} |
|
@ -1 +0,0 @@ |
|||||
<a target="_blank" href="http://melpon.org/wandbox/permlink/InYach9gNBDvA8QR"><b>online</b></a> |
|
@ -1,9 +0,0 @@ |
|||||
[1,2,3,4] |
|
||||
[1.2,2.3,3.4,5.6] |
|
||||
[true,true,false,true] |
|
||||
[12345678909876,23456789098765,34567890987654,45678909876543] |
|
||||
[1,2,3,4] |
|
||||
["four","one","three","two"] |
|
||||
["four","three","two","one"] |
|
||||
["four","one","one","two"] |
|
||||
["four","two","one","one"] |
|
@ -1,27 +0,0 @@ |
|||||
#include <json.hpp>
|
|
||||
|
|
||||
using json = nlohmann::json; |
|
||||
|
|
||||
int main() |
|
||||
{ |
|
||||
// create values of different integer types
|
|
||||
short n42 = 42; |
|
||||
int n23 = 23; |
|
||||
long n1024 = 1024; |
|
||||
int_least32_t n17 = 17; |
|
||||
uint8_t n8 = 8; |
|
||||
|
|
||||
// create JSON numbers
|
|
||||
json j42(n42); |
|
||||
json j23(n23); |
|
||||
json j1024(n1024); |
|
||||
json j17(n17); |
|
||||
json j8(n8); |
|
||||
|
|
||||
// serialize the JSON numbers
|
|
||||
std::cout << j42 << '\n'; |
|
||||
std::cout << j23 << '\n'; |
|
||||
std::cout << j1024 << '\n'; |
|
||||
std::cout << j17 << '\n'; |
|
||||
std::cout << j8 << '\n'; |
|
||||
} |
|
@ -1 +0,0 @@ |
|||||
<a target="_blank" href="http://melpon.org/wandbox/permlink/VDu3HkQPf0Rv5dzH"><b>online</b></a> |
|
@ -1,5 +0,0 @@ |
|||||
42 |
|
||||
23 |
|
||||
1024 |
|
||||
17 |
|
||||
8 |
|
@ -1,21 +0,0 @@ |
|||||
#include <json.hpp>
|
|
||||
|
|
||||
using json = nlohmann::json; |
|
||||
|
|
||||
int main() |
|
||||
{ |
|
||||
// create values of different floating-point types
|
|
||||
float f42 = 42.23; |
|
||||
float f_nan = 1.0f / 0.0f; |
|
||||
double f23 = 23.42; |
|
||||
|
|
||||
// create JSON numbers
|
|
||||
json j42(f42); |
|
||||
json j_nan(f_nan); |
|
||||
json j23(f23); |
|
||||
|
|
||||
// serialize the JSON numbers
|
|
||||
std::cout << j42 << '\n'; |
|
||||
std::cout << j_nan << '\n'; |
|
||||
std::cout << j23 << '\n'; |
|
||||
} |
|
@ -1 +0,0 @@ |
|||||
<a target="_blank" href="http://melpon.org/wandbox/permlink/BjDrTHvJMwFC3iLr"><b>online</b></a> |
|
@ -1,3 +0,0 @@ |
|||||
42.2299995422363 |
|
||||
null |
|
||||
23.42 |
|
@ -1,41 +0,0 @@ |
|||||
#include <json.hpp>
|
|
||||
#include <unordered_map>
|
|
||||
|
|
||||
using json = nlohmann::json; |
|
||||
|
|
||||
int main() |
|
||||
{ |
|
||||
// create an object from std::map
|
|
||||
std::map<std::string, int> c_map |
|
||||
{ |
|
||||
{"one", 1}, {"two", 2}, {"three", 3} |
|
||||
}; |
|
||||
json j_map(c_map); |
|
||||
|
|
||||
// create an object from std::unordered_map
|
|
||||
std::unordered_map<const char*, double> c_umap |
|
||||
{ |
|
||||
{"one", 1.2}, {"two", 2.3}, {"three", 3.4} |
|
||||
}; |
|
||||
json j_umap(c_umap); |
|
||||
|
|
||||
// create an object from std::multimap
|
|
||||
std::multimap<std::string, bool> c_mmap |
|
||||
{ |
|
||||
{"one", true}, {"two", true}, {"three", false}, {"three", true} |
|
||||
}; |
|
||||
json j_mmap(c_mmap); // only one entry for key "three" is used
|
|
||||
|
|
||||
// create an object from std::unordered_multimap
|
|
||||
std::unordered_multimap<std::string, bool> c_ummap |
|
||||
{ |
|
||||
{"one", true}, {"two", true}, {"three", false}, {"three", true} |
|
||||
}; |
|
||||
json j_ummap(c_ummap); // only one entry for key "three" is used
|
|
||||
|
|
||||
// serialize the JSON objects
|
|
||||
std::cout << j_map << '\n'; |
|
||||
std::cout << j_umap << '\n'; |
|
||||
std::cout << j_mmap << '\n'; |
|
||||
std::cout << j_ummap << '\n'; |
|
||||
} |
|
@ -1 +0,0 @@ |
|||||
<a target="_blank" href="http://melpon.org/wandbox/permlink/ZJz4SFD4Iuy8OS4T"><b>online</b></a> |
|
@ -1,4 +0,0 @@ |
|||||
{"one":1,"three":3,"two":2} |
|
||||
{"one":1.2,"three":3.4,"two":2.3} |
|
||||
{"one":true,"three":false,"two":true} |
|
||||
{"one":true,"three":false,"two":true} |
|
@ -1,15 +0,0 @@ |
|||||
#include <json.hpp>
|
|
||||
|
|
||||
using json = nlohmann::json; |
|
||||
|
|
||||
int main() |
|
||||
{ |
|
||||
// create a string value
|
|
||||
std::string s = "The quick brown fox jumps over the lazy dog."; |
|
||||
|
|
||||
// create a JSON string value
|
|
||||
json j = s; |
|
||||
|
|
||||
// serialize the JSON string
|
|
||||
std::cout << j << '\n'; |
|
||||
} |
|
@ -1 +0,0 @@ |
|||||
<a target="_blank" href="http://melpon.org/wandbox/permlink/Fe1WNG7eJRaWYMM4"><b>online</b></a> |
|
@ -1 +0,0 @@ |
|||||
"The quick brown fox jumps over the lazy dog." |
|
@ -1,21 +0,0 @@ |
|||||
#include <json.hpp>
|
|
||||
|
|
||||
using json = nlohmann::json; |
|
||||
|
|
||||
int main() |
|
||||
{ |
|
||||
// create JSON values
|
|
||||
json j_array = {"alpha", "bravo", "charly", "delta", "easy"}; |
|
||||
json j_number = 42; |
|
||||
json j_object = {{"one", "eins"}, {"two", "zwei"}}; |
|
||||
|
|
||||
// create copies using iterators
|
|
||||
json j_array_range(j_array.begin() + 1, j_array.end() - 2); |
|
||||
json j_number_range(j_number.begin(), j_number.end()); |
|
||||
json j_object_range(j_object.begin(), j_object.find("two")); |
|
||||
|
|
||||
// serialize the values
|
|
||||
std::cout << j_array_range << '\n'; |
|
||||
std::cout << j_number_range << '\n'; |
|
||||
std::cout << j_object_range << '\n'; |
|
||||
} |
|
@ -1 +0,0 @@ |
|||||
<a target="_blank" href="http://melpon.org/wandbox/permlink/Ulv0RYN6QoJ6ECVR"><b>online</b></a> |
|
@ -1,3 +0,0 @@ |
|||||
["bravo","charly"] |
|
||||
42 |
|
||||
{"one":"eins"} |
|
@ -1,15 +0,0 @@ |
|||||
#include <json.hpp>
|
|
||||
|
|
||||
using json = nlohmann::json; |
|
||||
|
|
||||
int main() |
|
||||
{ |
|
||||
// create an array_t value
|
|
||||
json::array_t value = {"one", "two", 3, 4.5, false}; |
|
||||
|
|
||||
// create a JSON array from the value
|
|
||||
json j(value); |
|
||||
|
|
||||
// serialize the JSON array
|
|
||||
std::cout << j << '\n'; |
|
||||
} |
|
@ -1 +0,0 @@ |
|||||
<a target="_blank" href="http://melpon.org/wandbox/permlink/T5FlYwVpQ1oXBuBH"><b>online</b></a> |
|
@ -1 +0,0 @@ |
|||||
["one","two",3,4.5,false] |
|
@ -1,16 +0,0 @@ |
|||||
#include <json.hpp>
|
|
||||
|
|
||||
using json = nlohmann::json; |
|
||||
|
|
||||
int main() |
|
||||
{ |
|
||||
// create a JSON array
|
|
||||
json j1 = {"one", "two", 3, 4.5, false}; |
|
||||
|
|
||||
// create a copy
|
|
||||
json j2(j1); |
|
||||
|
|
||||
// serialize the JSON array
|
|
||||
std::cout << j1 << " = " << j2 << '\n'; |
|
||||
std::cout << std::boolalpha << (j1 == j2) << '\n'; |
|
||||
} |
|
@ -1 +0,0 @@ |
|||||
<a target="_blank" href="http://melpon.org/wandbox/permlink/vPBv5smAPKUko4Qo"><b>online</b></a> |
|
@ -1,2 +0,0 @@ |
|||||
["one","two",3,4.5,false] = ["one","two",3,4.5,false] |
|
||||
true |
|
@ -1,14 +0,0 @@ |
|||||
#include <json.hpp>
|
|
||||
|
|
||||
using json = nlohmann::json; |
|
||||
|
|
||||
int main() |
|
||||
{ |
|
||||
// create boolean values
|
|
||||
json j_truth = true; |
|
||||
json j_falsity = false; |
|
||||
|
|
||||
// serialize the JSON booleans
|
|
||||
std::cout << j_truth << '\n'; |
|
||||
std::cout << j_falsity << '\n'; |
|
||||
} |
|
@ -1 +0,0 @@ |
|||||
<a target="_blank" href="http://melpon.org/wandbox/permlink/saCwetmQZaB8tQ24"><b>online</b></a> |
|
@ -1,2 +0,0 @@ |
|||||
true |
|
||||
false |
|
@ -1,15 +0,0 @@ |
|||||
#include <json.hpp>
|
|
||||
|
|
||||
using json = nlohmann::json; |
|
||||
|
|
||||
int main() |
|
||||
{ |
|
||||
// an anonymous enum
|
|
||||
enum { t = 17 }; |
|
||||
|
|
||||
// create a JSON number from the enum
|
|
||||
json j(t); |
|
||||
|
|
||||
// serialize the JSON numbers
|
|
||||
std::cout << j << '\n'; |
|
||||
} |
|
@ -1 +0,0 @@ |
|||||
<a target="_blank" href="http://melpon.org/wandbox/permlink/BzGFT02b2KTR6z2B"><b>online</b></a> |
|
@ -1 +0,0 @@ |
|||||
17 |
|
@ -1,17 +0,0 @@ |
|||||
#include <json.hpp>
|
|
||||
|
|
||||
using json = nlohmann::json; |
|
||||
|
|
||||
int main() |
|
||||
{ |
|
||||
// create JSON values
|
|
||||
json a = 23; |
|
||||
json b = 42; |
|
||||
|
|
||||
// copy-assign a to b
|
|
||||
b = a; |
|
||||
|
|
||||
// serialize the JSON arrays
|
|
||||
std::cout << a << '\n'; |
|
||||
std::cout << b << '\n'; |
|
||||
} |
|
@ -1 +0,0 @@ |
|||||
<a target="_blank" href="http://melpon.org/wandbox/permlink/Ib1A0jrFXwYhf0eA"><b>online</b></a> |
|
@ -1,2 +0,0 @@ |
|||||
23 |
|
||||
23 |
|
@ -1,55 +0,0 @@ |
|||||
#include <json.hpp>
|
|
||||
|
|
||||
using json = nlohmann::json; |
|
||||
|
|
||||
int main() |
|
||||
{ |
|
||||
// a JSON text
|
|
||||
auto text = R"( |
|
||||
{ |
|
||||
"Image": { |
|
||||
"Width": 800, |
|
||||
"Height": 600, |
|
||||
"Title": "View from 15th Floor", |
|
||||
"Thumbnail": { |
|
||||
"Url": "http://www.example.com/image/481989943", |
|
||||
"Height": 125, |
|
||||
"Width": 100 |
|
||||
}, |
|
||||
"Animated" : false, |
|
||||
"IDs": [116, 943, 234, 38793] |
|
||||
} |
|
||||
} |
|
||||
)"; |
|
||||
|
|
||||
// fill a stream with JSON text
|
|
||||
std::stringstream ss; |
|
||||
ss << text; |
|
||||
|
|
||||
// create JSON from stream
|
|
||||
json j_complete(ss); |
|
||||
std::cout << std::setw(4) << j_complete << "\n\n"; |
|
||||
|
|
||||
|
|
||||
// define parser callback
|
|
||||
json::parser_callback_t cb = [](int depth, json::parse_event_t event, json & parsed) |
|
||||
{ |
|
||||
// skip object elements with key "Thumbnail"
|
|
||||
if (event == json::parse_event_t::key and parsed == json("Thumbnail")) |
|
||||
{ |
|
||||
return false; |
|
||||
} |
|
||||
else |
|
||||
{ |
|
||||
return true; |
|
||||
} |
|
||||
}; |
|
||||
|
|
||||
// fill a stream with JSON text
|
|
||||
ss.clear(); |
|
||||
ss << text; |
|
||||
|
|
||||
// create JSON from stream (with callback)
|
|
||||
json j_filtered(ss, cb); |
|
||||
std::cout << std::setw(4) << j_filtered << '\n'; |
|
||||
} |
|
@ -1 +0,0 @@ |
|||||
<a target="_blank" href="http://melpon.org/wandbox/permlink/VzSqLszbnoWE92dD"><b>online</b></a> |
|
@ -1,34 +0,0 @@ |
|||||
{ |
|
||||
"Image": { |
|
||||
"Animated": false, |
|
||||
"Height": 600, |
|
||||
"IDs": [ |
|
||||
116, |
|
||||
943, |
|
||||
234, |
|
||||
38793 |
|
||||
], |
|
||||
"Thumbnail": { |
|
||||
"Height": 125, |
|
||||
"Url": "http://www.example.com/image/481989943", |
|
||||
"Width": 100 |
|
||||
}, |
|
||||
"Title": "View from 15th Floor", |
|
||||
"Width": 800 |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
{ |
|
||||
"Image": { |
|
||||
"Animated": false, |
|
||||
"Height": 600, |
|
||||
"IDs": [ |
|
||||
116, |
|
||||
943, |
|
||||
234, |
|
||||
38793 |
|
||||
], |
|
||||
"Title": "View from 15th Floor", |
|
||||
"Width": 800 |
|
||||
} |
|
||||
} |
|
@ -1,20 +0,0 @@ |
|||||
#include <json.hpp>
|
|
||||
|
|
||||
using json = nlohmann::json; |
|
||||
|
|
||||
int main() |
|
||||
{ |
|
||||
// create JSON values
|
|
||||
json j_empty_init_list = json({}); |
|
||||
json j_object = { {"one", 1}, {"two", 2} }; |
|
||||
json j_array = {1, 2, 3, 4}; |
|
||||
json j_nested_object = { {"one", {1}}, {"two", {1, 2}} }; |
|
||||
json j_nested_array = { {{1}, "one"}, {{1, 2}, "two"} }; |
|
||||
|
|
||||
// serialize the JSON value
|
|
||||
std::cout << j_empty_init_list << '\n'; |
|
||||
std::cout << j_object << '\n'; |
|
||||
std::cout << j_array << '\n'; |
|
||||
std::cout << j_nested_object << '\n'; |
|
||||
std::cout << j_nested_array << '\n'; |
|
||||
} |
|
@ -1 +0,0 @@ |
|||||
<a target="_blank" href="http://melpon.org/wandbox/permlink/r7SIosyJCePZZvqh"><b>online</b></a> |
|
@ -1,5 +0,0 @@ |
|||||
{} |
|
||||
{"one":1,"two":2} |
|
||||
[1,2,3,4] |
|
||||
{"one":[1],"two":[1,2]} |
|
||||
[[[1],"one"],[[1,2],"two"]] |
|
@ -1,16 +0,0 @@ |
|||||
#include <json.hpp>
|
|
||||
|
|
||||
using json = nlohmann::json; |
|
||||
|
|
||||
int main() |
|
||||
{ |
|
||||
// create a JSON value
|
|
||||
json a = 23; |
|
||||
|
|
||||
// move contents of a to b
|
|
||||
json b(std::move(a)); |
|
||||
|
|
||||
// serialize the JSON arrays
|
|
||||
std::cout << a << '\n'; |
|
||||
std::cout << b << '\n'; |
|
||||
} |
|
@ -1 +0,0 @@ |
|||||
<a target="_blank" href="http://melpon.org/wandbox/permlink/y7ngrkT74SN0fFWG"><b>online</b></a> |
|
@ -1,2 +0,0 @@ |
|||||
null |
|
||||
23 |
|
@ -1,12 +0,0 @@ |
|||||
#include <json.hpp>
|
|
||||
|
|
||||
using json = nlohmann::json; |
|
||||
|
|
||||
int main() |
|
||||
{ |
|
||||
// create a JSON null value
|
|
||||
json j(nullptr); |
|
||||
|
|
||||
// serialize the JSON null value
|
|
||||
std::cout << j << '\n'; |
|
||||
} |
|
@ -1 +0,0 @@ |
|||||
<a target="_blank" href="http://melpon.org/wandbox/permlink/Y7B27Mtrcp64PI9l"><b>online</b></a> |
|
@ -1 +0,0 @@ |
|||||
null |
|
@ -1,21 +0,0 @@ |
|||||
#include <json.hpp>
|
|
||||
|
|
||||
using json = nlohmann::json; |
|
||||
|
|
||||
int main() |
|
||||
{ |
|
||||
// create values of different floating-point types
|
|
||||
json::number_float_t v_ok = 3.141592653589793; |
|
||||
json::number_float_t v_nan = NAN; |
|
||||
json::number_float_t v_infinity = INFINITY; |
|
||||
|
|
||||
// create JSON numbers
|
|
||||
json j_ok(v_ok); |
|
||||
json j_nan(v_nan); |
|
||||
json j_infinity(v_infinity); |
|
||||
|
|
||||
// serialize the JSON numbers
|
|
||||
std::cout << j_ok << '\n'; |
|
||||
std::cout << j_nan << '\n'; |
|
||||
std::cout << j_infinity << '\n'; |
|
||||
} |
|
@ -1 +0,0 @@ |
|||||
<a target="_blank" href="http://melpon.org/wandbox/permlink/rsIsQEvaeJEaJx9c"><b>online</b></a> |
|
@ -1,3 +0,0 @@ |
|||||
3.14159265358979 |
|
||||
null |
|
||||
null |
|
@ -1,14 +0,0 @@ |
|||||
#include <json.hpp>
|
|
||||
|
|
||||
using json = nlohmann::json; |
|
||||
|
|
||||
int main() |
|
||||
{ |
|
||||
// create a JSON number from number_integer_t
|
|
||||
json::number_integer_t value = 42; |
|
||||
|
|
||||
json j(value); |
|
||||
|
|
||||
// serialize the JSON numbers
|
|
||||
std::cout << j << '\n'; |
|
||||
} |
|
@ -1 +0,0 @@ |
|||||
<a target="_blank" href="http://melpon.org/wandbox/permlink/3aV9OONj8OfHPXBV"><b>online</b></a> |
|
@ -1 +0,0 @@ |
|||||
42 |
|
@ -1,15 +0,0 @@ |
|||||
#include <json.hpp>
|
|
||||
|
|
||||
using json = nlohmann::json; |
|
||||
|
|
||||
int main() |
|
||||
{ |
|
||||
// create an object_t value
|
|
||||
json::object_t value = { {"one", 1}, {"two", 2} }; |
|
||||
|
|
||||
// create a JSON object from the value
|
|
||||
json j(value); |
|
||||
|
|
||||
// serialize the JSON object
|
|
||||
std::cout << j << '\n'; |
|
||||
} |
|
@ -1 +0,0 @@ |
|||||
<a target="_blank" href="http://melpon.org/wandbox/permlink/YhDZ1WhldMdwBthI"><b>online</b></a> |
|
Some files were not shown because too many files changed in this diff
Write
Preview
Loading…
Cancel
Save
Reference in new issue