| 29 | |
| 30 | template <typename CharT,typename Sink=jsoncons::stream_sink<CharT>,typename Allocator=std::allocator<char>> |
| 31 | class basic_csv_encoder final : public basic_json_visitor<CharT> |
| 32 | { |
| 33 | public: |
| 34 | using char_type = CharT; |
| 35 | using typename basic_json_visitor<CharT>::string_view_type; |
| 36 | using sink_type = Sink; |
| 37 | using allocator_type = Allocator; |
| 38 | using char_allocator_type = typename std::allocator_traits<allocator_type>:: template rebind_alloc<CharT>; |
| 39 | using string_type = std::basic_string<CharT, std::char_traits<CharT>, char_allocator_type>; |
| 40 | using string_allocator_type = typename std::allocator_traits<allocator_type>:: template rebind_alloc<string_type>; |
| 41 | using string_string_allocator_type = typename std::allocator_traits<allocator_type>:: template rebind_alloc<std::pair<const string_type,string_type>>; |
| 42 | using string_vector_allocator_type = typename std::allocator_traits<allocator_type>:: template rebind_alloc<std::pair<const string_type, std::vector<string_type, string_allocator_type>>>; |
| 43 | using column_type = std::vector<string_type, string_allocator_type>; |
| 44 | using column_path_column_map_type = std::unordered_map<string_type, column_type, std::hash<string_type>,std::equal_to<string_type>,string_vector_allocator_type>; |
| 45 | private: |
| 46 | static jsoncons::basic_string_view<CharT> null_literal() |
| 47 | { |
| 48 | static jsoncons::basic_string_view<CharT> k = JSONCONS_STRING_VIEW_CONSTANT(CharT,"null"); |
| 49 | return k; |
| 50 | } |
| 51 | static jsoncons::basic_string_view<CharT> true_literal() |
| 52 | { |
| 53 | static jsoncons::basic_string_view<CharT> k = JSONCONS_STRING_VIEW_CONSTANT(CharT,"true"); |
| 54 | return k; |
| 55 | } |
| 56 | static jsoncons::basic_string_view<CharT> false_literal() |
| 57 | { |
| 58 | static jsoncons::basic_string_view<CharT> k = JSONCONS_STRING_VIEW_CONSTANT(CharT,"false"); |
| 59 | return k; |
| 60 | } |
| 61 | |
| 62 | enum class stack_item_kind |
| 63 | { |
| 64 | flat_row_mapping, |
| 65 | row_mapping, |
| 66 | flat_object, |
| 67 | flat_row, |
| 68 | stream_flat_row, |
| 69 | unmapped, |
| 70 | object, |
| 71 | row, |
| 72 | column_mapping, |
| 73 | column, |
| 74 | multivalued_field, |
| 75 | stream_multivalued_field, |
| 76 | column_multivalued_field |
| 77 | }; |
| 78 | |
| 79 | struct stack_item |
| 80 | { |
| 81 | stack_item_kind item_kind_; |
| 82 | std::size_t count_{0}; |
| 83 | string_type column_path_; |
| 84 | |
| 85 | stack_item(stack_item_kind item_kind) noexcept |
| 86 | : item_kind_(item_kind) |
| 87 | { |
| 88 | } |