diff --git a/include/nlohmann/detail/input/input_adapters.hpp b/include/nlohmann/detail/input/input_adapters.hpp index dced9bfffa..98fb29a99f 100644 --- a/include/nlohmann/detail/input/input_adapters.hpp +++ b/include/nlohmann/detail/input/input_adapters.hpp @@ -2,9 +2,7 @@ #include // array #include // size_t -#include //FILE * #include // strlen -#include // istream #include // begin, end, iterator_traits, random_access_iterator_tag, distance, next #include // shared_ptr, make_shared, addressof #include // accumulate @@ -12,6 +10,11 @@ #include // enable_if, is_base_of, is_pointer, is_integral, remove_pointer #include // pair, declval +#ifndef JSON_NO_IO + #include //FILE * + #include // istream +#endif // JSON_NO_IO + #include #include @@ -26,6 +29,7 @@ enum class input_format_t { json, cbor, msgpack, ubjson, bson }; // input adapters // //////////////////// +#ifndef JSON_NO_IO /*! Input adapter for stdio file access. This adapter read only 1 byte and do not use any buffer. This adapter is a very low level adapter. @@ -117,6 +121,7 @@ class input_stream_adapter std::istream* is = nullptr; std::streambuf* sb = nullptr; }; +#endif // JSON_NO_IO // General-purpose iterator-based adapter. It might not be as fast as // theoretically possible for some containers, but it is extremely versatile. @@ -403,6 +408,7 @@ typename container_input_adapter_factory_impl::container_input_adapter_factory::create(container); } +#ifndef JSON_NO_IO // Special cases with fast paths inline file_input_adapter input_adapter(std::FILE* file) { @@ -418,6 +424,7 @@ inline input_stream_adapter input_adapter(std::istream&& stream) { return input_stream_adapter(stream); } +#endif // JSON_NO_IO using contiguous_bytes_input_adapter = decltype(input_adapter(std::declval(), std::declval())); diff --git a/include/nlohmann/detail/output/output_adapters.hpp b/include/nlohmann/detail/output/output_adapters.hpp index 25886ad1ad..6f2462685e 100644 --- a/include/nlohmann/detail/output/output_adapters.hpp +++ b/include/nlohmann/detail/output/output_adapters.hpp @@ -2,12 +2,16 @@ #include // copy #include // size_t -#include // streamsize #include // back_inserter #include // shared_ptr, make_shared -#include // basic_ostream #include // basic_string #include // vector + +#ifndef JSON_NO_IO + #include // streamsize + #include // basic_ostream +#endif // JSON_NO_IO + #include namespace nlohmann @@ -56,6 +60,7 @@ class output_vector_adapter : public output_adapter_protocol std::vector& v; }; +#ifndef JSON_NO_IO /// output adapter for output streams template class output_stream_adapter : public output_adapter_protocol @@ -79,6 +84,7 @@ class output_stream_adapter : public output_adapter_protocol private: std::basic_ostream& stream; }; +#endif // JSON_NO_IO /// output adapter for basic_string template> @@ -111,8 +117,10 @@ class output_adapter output_adapter(std::vector& vec) : oa(std::make_shared>(vec)) {} +#ifndef JSON_NO_IO output_adapter(std::basic_ostream& s) : oa(std::make_shared>(s)) {} +#endif // JSON_NO_IO output_adapter(StringType& s) : oa(std::make_shared>(s)) {} diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index 0bbaa9503a..c55bdf54bd 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -38,7 +38,9 @@ SOFTWARE. #include // nullptr_t, ptrdiff_t, size_t #include // hash, less #include // initializer_list -#include // istream, ostream +#ifndef JSON_NO_IO + #include // istream, ostream +#endif // JSON_NO_IO #include // random_access_iterator_tag #include // unique_ptr #include // accumulate @@ -6659,7 +6661,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /// @name serialization /// @{ - +#ifndef JSON_NO_IO /*! @brief serialize to stream @@ -6719,7 +6721,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec { return o << j; } - +#endif // JSON_NO_IO /// @} @@ -6977,7 +6979,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec // NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg) : detail::binary_reader(std::move(ia)).sax_parse(format, sax, strict); } - +#ifndef JSON_NO_IO /*! @brief deserialize from stream @deprecated This stream operator is deprecated and will be removed in @@ -7022,7 +7024,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec parser(detail::input_adapter(i)).parse(false, j); return i; } - +#endif // JSON_NO_IO /// @} /////////////////////////// diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 2716e1e7b3..cbe69ef472 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -38,7 +38,9 @@ SOFTWARE. #include // nullptr_t, ptrdiff_t, size_t #include // hash, less #include // initializer_list -#include // istream, ostream +#ifndef JSON_NO_IO + #include // istream, ostream +#endif // JSON_NO_IO #include // random_access_iterator_tag #include // unique_ptr #include // accumulate @@ -5227,9 +5229,7 @@ std::size_t hash(const BasicJsonType& j) #include // array #include // size_t -#include //FILE * #include // strlen -#include // istream #include // begin, end, iterator_traits, random_access_iterator_tag, distance, next #include // shared_ptr, make_shared, addressof #include // accumulate @@ -5237,6 +5237,11 @@ std::size_t hash(const BasicJsonType& j) #include // enable_if, is_base_of, is_pointer, is_integral, remove_pointer #include // pair, declval +#ifndef JSON_NO_IO + #include //FILE * + #include // istream +#endif // JSON_NO_IO + // #include // #include @@ -5253,6 +5258,7 @@ enum class input_format_t { json, cbor, msgpack, ubjson, bson }; // input adapters // //////////////////// +#ifndef JSON_NO_IO /*! Input adapter for stdio file access. This adapter read only 1 byte and do not use any buffer. This adapter is a very low level adapter. @@ -5344,6 +5350,7 @@ class input_stream_adapter std::istream* is = nullptr; std::streambuf* sb = nullptr; }; +#endif // JSON_NO_IO // General-purpose iterator-based adapter. It might not be as fast as // theoretically possible for some containers, but it is extremely versatile. @@ -5630,6 +5637,7 @@ typename container_input_adapter_factory_impl::container_input_adapter_factory::create(container); } +#ifndef JSON_NO_IO // Special cases with fast paths inline file_input_adapter input_adapter(std::FILE* file) { @@ -5645,6 +5653,7 @@ inline input_stream_adapter input_adapter(std::istream&& stream) { return input_stream_adapter(stream); } +#endif // JSON_NO_IO using contiguous_bytes_input_adapter = decltype(input_adapter(std::declval(), std::declval())); @@ -13119,12 +13128,16 @@ class json_ref #include // copy #include // size_t -#include // streamsize #include // back_inserter #include // shared_ptr, make_shared -#include // basic_ostream #include // basic_string #include // vector + +#ifndef JSON_NO_IO + #include // streamsize + #include // basic_ostream +#endif // JSON_NO_IO + // #include @@ -13174,6 +13187,7 @@ class output_vector_adapter : public output_adapter_protocol std::vector& v; }; +#ifndef JSON_NO_IO /// output adapter for output streams template class output_stream_adapter : public output_adapter_protocol @@ -13197,6 +13211,7 @@ class output_stream_adapter : public output_adapter_protocol private: std::basic_ostream& stream; }; +#endif // JSON_NO_IO /// output adapter for basic_string template> @@ -13229,8 +13244,10 @@ class output_adapter output_adapter(std::vector& vec) : oa(std::make_shared>(vec)) {} +#ifndef JSON_NO_IO output_adapter(std::basic_ostream& s) : oa(std::make_shared>(s)) {} +#endif // JSON_NO_IO output_adapter(StringType& s) : oa(std::make_shared>(s)) {} @@ -23679,7 +23696,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /// @name serialization /// @{ - +#ifndef JSON_NO_IO /*! @brief serialize to stream @@ -23739,7 +23756,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec { return o << j; } - +#endif // JSON_NO_IO /// @} @@ -23997,7 +24014,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec // NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg) : detail::binary_reader(std::move(ia)).sax_parse(format, sax, strict); } - +#ifndef JSON_NO_IO /*! @brief deserialize from stream @deprecated This stream operator is deprecated and will be removed in @@ -24042,7 +24059,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec parser(detail::input_adapter(i)).parse(false, j); return i; } - +#endif // JSON_NO_IO /// @} ///////////////////////////