From 540e1e366bebf5967de43b573c1b47bed251f94d Mon Sep 17 00:00:00 2001 From: tokox Date: Wed, 20 Mar 2024 16:44:24 +0100 Subject: [PATCH] Update README --- README.md | 47 +++++++++++++++++++++++------------------------ cpp-json.spec | 5 ++++- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 83121e7..49fa08e 100644 --- a/README.md +++ b/README.md @@ -11,24 +11,23 @@ Test program called `test.cpp` is just reading and writing same one JSON object. ### Classes, constants and variables -- Class `object` represents **JSON object**. It is made on top of `std::variant` -- `object::variant` is `std::variant` used by `object` -- `object::value_type` is *an enum* representing **JSON objects types** +- Class `object` represents **JSON object**. It is made on top of `std::any` +- `value_type` is *an enum* representing **JSON objects types** - Types are represented as following: - | JSON type | C++ type | `object::value_type` name | `object::value_type` value (`object::variant` index) | - | :---------- | :------------------------------------ | :------------------------ | :--------------------------------------------------- | - | `Null` | `std::monostate` | `Null` | `0` | - | `Boolean` | `bool` | `Bool` | `1` | - | `Number` | `long long int` and `long double` | `Int` and `Float` | `2` and `3` | - | `String` | `std::string` | `String` | `4` | - | `Array` | `std::vector` | `Vector` | `5` | - | `Object` | `std::map` | `Map` | `6` | + | JSON type | C++ type | `value_type` | + | :---------- | :------------------------------------ | :----------------------- | + | `Null` | **\[None]** (std::any has no value) | `Null` | + | `Boolean` | `bool` | `Bool` | + | `Number` | `long long int` and `long double` | `Int` or `Float` | + | `String` | `std::string` | `String` | + | `Array` | `std::vector` | `Vector` | + | `Object` | `std::map` | `Map` | - `import_error` is **an exception class** thrown by **import functions** (export functions don't throw (see below)) - `ERR_???` are **error messages** -- `float_prec` is `size_t` for **float precision** +- `float_prec` is **float precision** ### Functions for import: @@ -36,24 +35,24 @@ Test program called `test.cpp` is just reading and writing same one JSON object. | :--------------------------------------------------------------------------- | :----------------------------------------------------------------------------- | | `object from(iterator& input_iterator, iterator input_end)` | Main function for import. Detects what type of object it is and calls corresponding `TYPE_from` function. Takes iterator to current input character and input end (it may be iterator to `std::*stream`, `std::string`, `std::vector`, c-string - basically whatever you want). `iterator` is a template parameter. Returns `object` with imported JSON | | `object TYPE_from(iterator& input_iterator, iterator input_end)` | Imports specific type TYPE (for every JSON type). They are called by `from` after type detection. They import specific type - if it isn't correct they throw `import_error` | -| `object from(std::string& input_string)` | Returns `from(input_string->iterator)` (first) | -| `object& from(object& obj, std::string& input_string)` | Calls `from(input_string)` (above), saves result to `obj` and returns it | -| `object from(std::istream& input_stream)` | Returns `from(input_stream->iterator)` (first) | -| `object& from(object& obj, std::istream& input_stream)` | Calls `from(input_stream)` (above), saves result to `obj` and returns it | -| `std::istream& operator>>(std::istream& input_stream, object& obj)` | Calls `from(obj, input_stream)` (above) and returns `input_stream` | +| `object from(std::string& input_string)` | Returns `from(input_string->iterator)` (first) | +| `object& from(object& obj, std::string& input_string)` | Calls `from(input_string)` (above), saves result to `obj` and returns it | +| `object from(std::istream& input_stream)` | Returns `from(input_stream->iterator)` (first) | +| `object& from(object& obj, std::istream& input_stream)` | Calls `from(input_stream)` (above), saves result to `obj` and returns it | +| `std::istream& operator>>(std::istream& input_stream, object& obj)` | Calls `from(obj, input_stream)` (above) and returns `input_stream` | #### :bangbang: Important: `number_from` is returning `object` containing `Int` (`long long int`) or `Float` (`long double`). It chooses **the better option**. Here is how it works: -| Condition for number | `Int` (`long long int`) or `Float` (`long double`) | -| :------------------------------------------------------------------------------------------------------- | :------------------------------------------------- | -| doesn't fit in `long long int` (less than one or more than `std::numeric_limits::max()`) | `Float` (`long double`) | -| fits in `long long int` and is an integer | `Int` (`long long int`) | -| fits in `long long int` and `long double` loses precision (is less precise than rounded `long long int`) | `Int` (`long long int`) | -| Well, `long long int` isn't any better than `long double` there! (Other) | `Float` (`long double`) | +| Condition for number | `value_type` (C++ type) | +| :------------------------------------------------------------------------------------------------------- | :---------------------- | +| doesn't fit in `long long int` (less than one or more than `std::numeric_limits::max()`) | `Float` (`long double`) | +| fits in `long long int` and is an integer | `Int` (`long long int`) | +| fits in `long long int` and `long double` loses precision (is less precise than rounded `long long int`) | `Int` (`long long int`) | +| Well, `long long int` isn't any better than `long double` there! (Other) | `Float` (`long double`) | -You can always **cast it** to the other one **after import**. +You can always **cast it** to another **after import**. ### Functions for export: diff --git a/cpp-json.spec b/cpp-json.spec index 7e8992d..cc7c396 100644 --- a/cpp-json.spec +++ b/cpp-json.spec @@ -1,6 +1,6 @@ Name: tokox-cpp-json Version: 1.2 -Release: 1%{?dist} +Release: 2%{?dist} Summary: C++ JSON object import/export library License: MIT @@ -36,6 +36,9 @@ cp -a LICENSE.md README.md %{buildroot}/usr/share/doc/tokox/cpp-json %doc /usr/share/doc/tokox/cpp-json/README.md %changelog +* Wed Mar 20 2024 Tomasz Kośnikowski (tokox) - 1.2-2 + - Updated README + * Tue Mar 19 2024 Tomasz Kośnikowski (tokox) - 1.2-1 - Replaced std::variant with std::any - improved object class