|
| 1 | +#ifndef JSS_UNORDERED_MAP_H_INCLUDED |
| 2 | +#define JSS_UNORDERED_MAP_H_INCLUDED |
| 3 | + |
| 4 | +#include "jss_core.h" |
| 5 | +#include "jss_optional.h" |
| 6 | +#include "map_commons.h" |
| 7 | +#include <unordered_map> |
| 8 | + |
| 9 | +namespace JSON |
| 10 | +{ |
| 11 | + template <typename ValueT, typename HashT = std::hash <std::string>, class PredT = std::equal_to <std::string>, |
| 12 | + typename AllocT = std::allocator <std::pair <const std::string, ValueT>>, |
| 13 | + typename = typename std::enable_if <Internal::can_stringify<ValueT>::value>::type > |
| 14 | + std::ostream& stringify(std::ostream& stream, std::string const& name, std::unordered_map<std::string, ValueT, HashT, PredT, AllocT> const& values, StringificationOptions options) |
| 15 | + { |
| 16 | + using namespace Internal; |
| 17 | + |
| 18 | + WRITE_OBJECT_START(stream); |
| 19 | + options.in_object = true; |
| 20 | + |
| 21 | + bool first = true; |
| 22 | + for (auto const& i : values) |
| 23 | + { |
| 24 | + if (is_optional_set(i.second)) |
| 25 | + { |
| 26 | + if (!first) |
| 27 | + stream << options.delimiter; |
| 28 | + stringify_map_pair(stream, i, options); |
| 29 | + first = false; |
| 30 | + } |
| 31 | + } |
| 32 | + WRITE_OBJECT_END(stream); |
| 33 | + return stream; |
| 34 | + } |
| 35 | + |
| 36 | + template <typename KeyT, |
| 37 | + typename ValueT, typename HashT = std::hash <std::string>, class PredT = std::equal_to <std::string>, |
| 38 | + typename AllocT = std::allocator <std::pair <const std::string, ValueT>>, |
| 39 | + typename = typename std::enable_if <Internal::can_stringify<ValueT>::value>::type > |
| 40 | + std::ostream& stringify(std::ostream& stream, std::string const& name, std::unordered_multimap<KeyT, ValueT, HashT, PredT, AllocT> const& values, StringificationOptions options) |
| 41 | + { |
| 42 | + using namespace Internal; |
| 43 | + |
| 44 | + WRITE_ARRAY_START(stream); |
| 45 | + options.ignore_name = true; |
| 46 | + |
| 47 | + bool first = true; |
| 48 | + for (auto const& i : values) |
| 49 | + { |
| 50 | + if (is_optional_set(i.second)) |
| 51 | + { |
| 52 | + if (!first) |
| 53 | + stream << options.delimiter; |
| 54 | + WRITE_ARRAY_START(stream); |
| 55 | + stringify_map_pair_2(stream, i, options); |
| 56 | + WRITE_ARRAY_END(stream); |
| 57 | + first = false; |
| 58 | + } |
| 59 | + } |
| 60 | + WRITE_ARRAY_END(stream); |
| 61 | + return stream; |
| 62 | + } |
| 63 | +} |
| 64 | + |
| 65 | +#endif // JSS_UNORDERED_MAP_H_INCLUDED |
0 commit comments