📝 overwork example handling
This commit is contained in:
parent
be1eafa12c
commit
da38cca316
@ -81,7 +81,7 @@ int main()
|
|||||||
json j_list(c_list);
|
json j_list(c_list);
|
||||||
|
|
||||||
// create an array from std::forward_list
|
// create an array from std::forward_list
|
||||||
std::forward_list<int64_t> c_flist {12345678909876, 23456789098765, 34567890987654, 45678909876543};
|
std::forward_list<std::int64_t> c_flist {12345678909876, 23456789098765, 34567890987654, 45678909876543};
|
||||||
json j_flist(c_flist);
|
json j_flist(c_flist);
|
||||||
|
|
||||||
// create an array from std::array
|
// create an array from std::array
|
||||||
|
|||||||
@ -7,11 +7,11 @@ using json = nlohmann::json;
|
|||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
// create byte vector
|
// create byte vector
|
||||||
std::vector<uint8_t> v = {0x1b, 0x00, 0x00, 0x00, 0x08, 0x63, 0x6f, 0x6d,
|
std::vector<std::uint8_t> v = {0x1b, 0x00, 0x00, 0x00, 0x08, 0x63, 0x6f, 0x6d,
|
||||||
0x70, 0x61, 0x63, 0x74, 0x00, 0x01, 0x10, 0x73,
|
0x70, 0x61, 0x63, 0x74, 0x00, 0x01, 0x10, 0x73,
|
||||||
0x63, 0x68, 0x65, 0x6d, 0x61, 0x00, 0x00, 0x00,
|
0x63, 0x68, 0x65, 0x6d, 0x61, 0x00, 0x00, 0x00,
|
||||||
0x00, 0x00, 0x00
|
0x00, 0x00, 0x00
|
||||||
};
|
};
|
||||||
|
|
||||||
// deserialize it with BSON
|
// deserialize it with BSON
|
||||||
json j = json::from_bson(v);
|
json j = json::from_bson(v);
|
||||||
|
|||||||
@ -7,10 +7,10 @@ using json = nlohmann::json;
|
|||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
// create byte vector
|
// create byte vector
|
||||||
std::vector<uint8_t> v = {0xa2, 0x67, 0x63, 0x6f, 0x6d, 0x70, 0x61, 0x63,
|
std::vector<std::uint8_t> v = {0xa2, 0x67, 0x63, 0x6f, 0x6d, 0x70, 0x61, 0x63,
|
||||||
0x74, 0xf5, 0x66, 0x73, 0x63, 0x68, 0x65, 0x6d,
|
0x74, 0xf5, 0x66, 0x73, 0x63, 0x68, 0x65, 0x6d,
|
||||||
0x61, 0x00
|
0x61, 0x00
|
||||||
};
|
};
|
||||||
|
|
||||||
// deserialize it with CBOR
|
// deserialize it with CBOR
|
||||||
json j = json::from_cbor(v);
|
json j = json::from_cbor(v);
|
||||||
|
|||||||
@ -7,10 +7,10 @@ using json = nlohmann::json;
|
|||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
// create byte vector
|
// create byte vector
|
||||||
std::vector<uint8_t> v = {0x82, 0xa7, 0x63, 0x6f, 0x6d, 0x70, 0x61, 0x63,
|
std::vector<std::uint8_t> v = {0x82, 0xa7, 0x63, 0x6f, 0x6d, 0x70, 0x61, 0x63,
|
||||||
0x74, 0xc3, 0xa6, 0x73, 0x63, 0x68, 0x65, 0x6d,
|
0x74, 0xc3, 0xa6, 0x73, 0x63, 0x68, 0x65, 0x6d,
|
||||||
0x61, 0x00
|
0x61, 0x00
|
||||||
};
|
};
|
||||||
|
|
||||||
// deserialize it with MessagePack
|
// deserialize it with MessagePack
|
||||||
json j = json::from_msgpack(v);
|
json j = json::from_msgpack(v);
|
||||||
|
|||||||
@ -7,10 +7,10 @@ using json = nlohmann::json;
|
|||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
// create byte vector
|
// create byte vector
|
||||||
std::vector<uint8_t> v = {0x7B, 0x69, 0x07, 0x63, 0x6F, 0x6D, 0x70, 0x61,
|
std::vector<std::uint8_t> v = {0x7B, 0x69, 0x07, 0x63, 0x6F, 0x6D, 0x70, 0x61,
|
||||||
0x63, 0x74, 0x54, 0x69, 0x06, 0x73, 0x63, 0x68,
|
0x63, 0x74, 0x54, 0x69, 0x06, 0x73, 0x63, 0x68,
|
||||||
0x65, 0x6D, 0x61, 0x69, 0x00, 0x7D
|
0x65, 0x6D, 0x61, 0x69, 0x00, 0x7D
|
||||||
};
|
};
|
||||||
|
|
||||||
// deserialize it with UBJSON
|
// deserialize it with UBJSON
|
||||||
json j = json::from_ubjson(v);
|
json j = json::from_ubjson(v);
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
"compiler": {
|
"compiler": {
|
||||||
"c++": "201103",
|
"c++": "201103",
|
||||||
"family": "clang",
|
"family": "clang",
|
||||||
"version": "13.0.0 (clang-1300.0.29.3)"
|
"version": "13.0.0 (clang-1300.0.29.30)"
|
||||||
},
|
},
|
||||||
"copyright": "(C) 2013-2021 Niels Lohmann",
|
"copyright": "(C) 2013-2021 Niels Lohmann",
|
||||||
"name": "JSON for Modern C++",
|
"name": "JSON for Modern C++",
|
||||||
|
|||||||
@ -7,7 +7,7 @@ using json = nlohmann::json;
|
|||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
// a JSON text given as std::vector
|
// a JSON text given as std::vector
|
||||||
std::vector<uint8_t> text = {'[', '1', ',', '2', ',', '3', ']', '\0'};
|
std::vector<std::uint8_t> text = {'[', '1', ',', '2', ',', '3', ']', '\0'};
|
||||||
|
|
||||||
// parse and serialize JSON
|
// parse and serialize JSON
|
||||||
json j_complete = json::parse(text);
|
json j_complete = json::parse(text);
|
||||||
|
|||||||
@ -1,15 +0,0 @@
|
|||||||
#include <iostream>
|
|
||||||
#include <iomanip>
|
|
||||||
#include <nlohmann/json.hpp>
|
|
||||||
|
|
||||||
using json = nlohmann::json;
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
// a JSON text given as std::vector
|
|
||||||
std::vector<uint8_t> text = {'[', '1', ',', '2', ',', '3', ']', '\0'};
|
|
||||||
|
|
||||||
// parse and serialize JSON
|
|
||||||
json j_complete = json::parse(text.begin(), text.end());
|
|
||||||
std::cout << std::setw(4) << j_complete << "\n\n";
|
|
||||||
}
|
|
||||||
@ -1,6 +0,0 @@
|
|||||||
[
|
|
||||||
1,
|
|
||||||
2,
|
|
||||||
3
|
|
||||||
]
|
|
||||||
|
|
||||||
@ -10,7 +10,7 @@ int main()
|
|||||||
json j = R"({"compact": true, "schema": 0})"_json;
|
json j = R"({"compact": true, "schema": 0})"_json;
|
||||||
|
|
||||||
// serialize it to BSON
|
// serialize it to BSON
|
||||||
std::vector<uint8_t> v = json::to_bson(j);
|
std::vector<std::uint8_t> v = json::to_bson(j);
|
||||||
|
|
||||||
// print the vector content
|
// print the vector content
|
||||||
for (auto& byte : v)
|
for (auto& byte : v)
|
||||||
|
|||||||
@ -10,7 +10,7 @@ int main()
|
|||||||
json j = R"({"compact": true, "schema": 0})"_json;
|
json j = R"({"compact": true, "schema": 0})"_json;
|
||||||
|
|
||||||
// serialize it to CBOR
|
// serialize it to CBOR
|
||||||
std::vector<uint8_t> v = json::to_cbor(j);
|
std::vector<std::uint8_t> v = json::to_cbor(j);
|
||||||
|
|
||||||
// print the vector content
|
// print the vector content
|
||||||
for (auto& byte : v)
|
for (auto& byte : v)
|
||||||
|
|||||||
@ -10,7 +10,7 @@ int main()
|
|||||||
json j = R"({"compact": true, "schema": 0})"_json;
|
json j = R"({"compact": true, "schema": 0})"_json;
|
||||||
|
|
||||||
// serialize it to MessagePack
|
// serialize it to MessagePack
|
||||||
std::vector<uint8_t> v = json::to_msgpack(j);
|
std::vector<std::uint8_t> v = json::to_msgpack(j);
|
||||||
|
|
||||||
// print the vector content
|
// print the vector content
|
||||||
for (auto& byte : v)
|
for (auto& byte : v)
|
||||||
|
|||||||
@ -23,7 +23,7 @@ int main()
|
|||||||
json j = R"({"compact": true, "schema": false})"_json;
|
json j = R"({"compact": true, "schema": false})"_json;
|
||||||
|
|
||||||
// serialize it to UBJSON
|
// serialize it to UBJSON
|
||||||
std::vector<uint8_t> v = json::to_ubjson(j);
|
std::vector<std::uint8_t> v = json::to_ubjson(j);
|
||||||
|
|
||||||
// print the vector content
|
// print the vector content
|
||||||
for (auto& byte : v)
|
for (auto& byte : v)
|
||||||
@ -36,11 +36,11 @@ int main()
|
|||||||
json array = {1, 2, 3, 4, 5, 6, 7, 8};
|
json array = {1, 2, 3, 4, 5, 6, 7, 8};
|
||||||
|
|
||||||
// serialize it to UBJSON using default representation
|
// serialize it to UBJSON using default representation
|
||||||
std::vector<uint8_t> v_array = json::to_ubjson(array);
|
std::vector<std::uint8_t> v_array = json::to_ubjson(array);
|
||||||
// serialize it to UBJSON using size optimization
|
// serialize it to UBJSON using size optimization
|
||||||
std::vector<uint8_t> v_array_size = json::to_ubjson(array, true);
|
std::vector<std::uint8_t> v_array_size = json::to_ubjson(array, true);
|
||||||
// serialize it to UBJSON using type optimization
|
// serialize it to UBJSON using type optimization
|
||||||
std::vector<uint8_t> v_array_size_and_type = json::to_ubjson(array, true, true);
|
std::vector<std::uint8_t> v_array_size_and_type = json::to_ubjson(array, true, true);
|
||||||
|
|
||||||
// print the vector contents
|
// print the vector contents
|
||||||
for (auto& byte : v_array)
|
for (auto& byte : v_array)
|
||||||
|
|||||||
@ -101,6 +101,20 @@ Linear.
|
|||||||
--8<-- "examples/operator__equal.output"
|
--8<-- "examples/operator__equal.output"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
??? example
|
||||||
|
|
||||||
|
The example demonstrates comparing several JSON types against the null pointer (JSON `#!json null`).
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
--8<-- "examples/operator__equal__nullptr_t.cpp"
|
||||||
|
```
|
||||||
|
|
||||||
|
Output:
|
||||||
|
|
||||||
|
```json
|
||||||
|
--8<-- "examples/operator__equal__nullptr_t.output"
|
||||||
|
```
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
- Added in version 1.0.0.
|
- Added in version 1.0.0.
|
||||||
|
|||||||
@ -39,18 +39,33 @@ Linear.
|
|||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
The example demonstrates comparing several JSON
|
??? example
|
||||||
types.
|
|
||||||
|
The example demonstrates comparing several JSON types.
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
--8<-- "examples/operator__notequal.cpp"
|
||||||
|
```
|
||||||
|
|
||||||
```cpp
|
Output:
|
||||||
--8<-- "examples/operator__notequal.cpp"
|
|
||||||
```
|
```json
|
||||||
|
--8<-- "examples/operator__notequal.output"
|
||||||
|
```
|
||||||
|
|
||||||
Output:
|
??? example
|
||||||
|
|
||||||
```json
|
The example demonstrates comparing several JSON types against the null pointer (JSON `#!json null`).
|
||||||
--8<-- "examples/operator__notequal.output"
|
|
||||||
```
|
```cpp
|
||||||
|
--8<-- "examples/operator__notequal__nullptr_t.cpp"
|
||||||
|
```
|
||||||
|
|
||||||
|
Output:
|
||||||
|
|
||||||
|
```json
|
||||||
|
--8<-- "examples/operator__notequal__nullptr_t.output"
|
||||||
|
```
|
||||||
|
|
||||||
## Version history
|
## Version history
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
import glob
|
import glob
|
||||||
|
import os.path
|
||||||
|
|
||||||
|
|
||||||
def check_structure():
|
def check_structure():
|
||||||
@ -95,7 +96,26 @@ def check_structure():
|
|||||||
if required_header not in existing_headers:
|
if required_header not in existing_headers:
|
||||||
print(f'{file}:{lineno+1}: Error: required header "{required_header}" was not found!')
|
print(f'{file}:{lineno+1}: Error: required header "{required_header}" was not found!')
|
||||||
|
|
||||||
print(f'\nchecked {len(files)} files')
|
|
||||||
|
def check_examples():
|
||||||
|
example_files = sorted(glob.glob('../../examples/*.cpp'))
|
||||||
|
markdown_files = sorted(glob.glob('**/*.md', recursive=True))
|
||||||
|
|
||||||
|
# check if every example file is used in at least one markdown file
|
||||||
|
for example_file in example_files:
|
||||||
|
example_file = os.path.join('examples', os.path.basename(example_file))
|
||||||
|
|
||||||
|
found = False
|
||||||
|
for markdown_file in markdown_files:
|
||||||
|
content = ' '.join(open(markdown_file).readlines())
|
||||||
|
if example_file in content:
|
||||||
|
found = True
|
||||||
|
break
|
||||||
|
|
||||||
|
if not found:
|
||||||
|
print(f'{example_file}: Error: example file is not used in any documentation file!')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
check_structure()
|
check_structure()
|
||||||
|
check_examples()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user