From 6715854d1a43425521f80fed0a9ec516860573f3 Mon Sep 17 00:00:00 2001 From: liuzicheng1987 Date: Tue, 10 Oct 2023 23:17:11 +0200 Subject: [PATCH 1/3] Updated list of containers --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a291ed83..59fb3049 100644 --- a/README.md +++ b/README.md @@ -101,7 +101,9 @@ reflect-cpp supports the following containers from the C++ standard library: - `std::array` - `std::deque` - `std::forward_list` -- `std::map` +- `std::map` +- `std::multimap` +- `std::multiset` - `std::list` - `std::optional` - `std::pair` @@ -110,7 +112,9 @@ reflect-cpp supports the following containers from the C++ standard library: - `std::string` - `std::tuple` - `std::unique_ptr` -- `std::unordered_map` +- `std::unordered_map` +- `std::unordered_multimap` +- `std::unordered_multiset` - `std::unordered_set` - `std::variant` - `std::vector` From 88a010c4f1aba1f8a04474747d1b3f94bf68727e Mon Sep 17 00:00:00 2001 From: liuzicheng1987 Date: Wed, 11 Oct 2023 00:01:09 +0200 Subject: [PATCH 2/3] Create standard_containers.md --- docs/standard_containers.md | 41 +++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 docs/standard_containers.md diff --git a/docs/standard_containers.md b/docs/standard_containers.md new file mode 100644 index 00000000..bd8bb819 --- /dev/null +++ b/docs/standard_containers.md @@ -0,0 +1,41 @@ +# Support for standard containers + +The serialization and deserialization of containers is handled as follows: + +`std::map` and `std::unordered_map` are treated +as objects. + +Consider the following map: + +```cpp +std::map homer; +homer["firstName"] = "Homer"; +homer["lastName"] = "Simpson"; +``` + +This will be represented as follows: + +```json +{"firstName":"Homer","lastName":"Simpson"} +``` + +All other supported standard containers +(other than `std::variant`, `std::optional`, `std::unique_ptr` and `std::shared_ptr`) +will be represented as arrays. Containers for which the `value_type` +is a key-value-pair, will be represented as arrays of pairs. + +Consider the following map: + +```cpp +std::map children; +children[1] = Person{.first_name = "Bart", .last_name = "Simpson"}; +children[2] = Person{.first_name = "Lisa", .last_name = "Simpson"}; +children[3] = Person{.first_name = "Maggie", .last_name = "Simpson"}; +``` + +This will be represented as follows: + +```json +[[1,{"firstName":"Bart","lastName":"Simpson"}],[2,{"firstName":"Lisa","lastName":"Simpson"}],[3,{"firstName":"Maggie","lastName":"Simpson"}]] +``` + From 8909b6411318621f49efb1a612795afbcd4ba76b Mon Sep 17 00:00:00 2001 From: liuzicheng1987 Date: Wed, 11 Oct 2023 00:02:05 +0200 Subject: [PATCH 3/3] Update README.md --- docs/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/README.md b/docs/README.md index 649a67f6..5849f23d 100644 --- a/docs/README.md +++ b/docs/README.md @@ -18,6 +18,8 @@ 1.7) [rfl::Timestamp](https://github.com/getml/reflect-cpp/blob/main/docs/timestamps.md) - For serializing and deserializing timestamps. +1.8) [Standard containers](https://github.com/getml/reflect-cpp/blob/main/docs/standard_containers.md) - Describes how reflect-cpp treats containers in the standard library. + ## 2) Custom classes 2.1) [Custom classes](https://github.com/getml/reflect-cpp/blob/main/docs/custom_classes.md) - For custom classes with private fields.