1
0
mirror of https://github.com/nlohmann/json.git synced 2025-07-29 23:01:16 +03:00

📝 add more API documentation

This commit is contained in:
Niels Lohmann
2020-08-15 15:18:07 +02:00
parent 1ce0ed5a52
commit d8ed98a7af
12 changed files with 396 additions and 26 deletions

View File

@ -10,6 +10,13 @@ ValueType get() const noexcept(
// (2)
template<typename BasicJsonType>
BasicJsonType get() const;
// (3)
template<typename PointerType>
PointerType get_ptr();
template<typename PointerType>
constexpr const PointerType get_ptr() const noexcept;
```
1. Explicit type conversion between the JSON value and a compatible value which is
@ -52,7 +59,9 @@ BasicJsonType get() const;
2. Overload for `basic_json` specializations. The function is equivalent to executing
```cpp
return *this;
```
```
3. Explicit pointer access to the internally stored JSON value. No copies are made.
## Template parameters
@ -62,15 +71,28 @@ BasicJsonType get() const;
`BasicJsonType`
: a specialization of `basic_json`
`PointerType`
: pointer type; must be a pointer to [`array_t`](array_t.md), [`object_t`](object_t.md), [`string_t`](string_t.md),
[`boolean_t`](boolean_t.md), [`number_integer_t`](number_integer_t.md), or [`number_unsigned`](number_unsigned.md),
[`number_float_t`](number_float_t.md), or [`binary_t`](binary_t.md). Other types will not compile.
## Return value
1. copy of the JSON value, converted to `ValueType`
2. a copy of `#!cpp *this`, converted into `BasicJsonType`
3. pointer to the internally stored JSON value if the requested pointer type fits to the JSON value; `#!cpp nullptr`
otherwise
## Exceptions
Depends on what `json_serializer<ValueType>` `from_json()` method throws
## Notes
!!! warning
Writing data to the pointee (overload 3) of the result yields an undefined state.
## Example
??? example
@ -91,7 +113,23 @@ Depends on what `json_serializer<ValueType>` `from_json()` method throws
--8<-- "examples/get__ValueType_const.output"
```
??? example
The example below shows how pointers to internal values of a JSON value can be requested. Note that no type
conversions are made and a `#cpp nullptr` is returned if the value and the requested pointer type does not match.
```cpp
--8<-- "examples/get__PointerType.cpp"
```
Output:
```json
--8<-- "examples/get__PointerType.output"
```
## Version history
1. Since version 2.1.0.
2. Since version 2.1.0. Extended to work with other specializations of `basic_json` in version 3.2.0.
3. Since version 1.0.0.