From 67b0daf27ba7659add80662945793d26e7b4a2b1 Mon Sep 17 00:00:00 2001
From: Jonathan Dumaresq <jdumaresq@cimeq.qc.ca>
Date: Tue, 11 Dec 2018 09:33:30 -0500
Subject: [PATCH] Add the possibility of using FILE * from cstdio library to
 read a file. This enable the possibility of using low eand device with this
 library.

---
 single_include/nlohmann/json.hpp | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp
index 7038084d..36939b31 100644
--- a/single_include/nlohmann/json.hpp
+++ b/single_include/nlohmann/json.hpp
@@ -55,6 +55,7 @@ SOFTWARE.
 #include <memory> // allocator
 #include <string> // string
 #include <vector> // vector
+#include <cstdio>
 
 /*!
 @brief namespace for Niels Lohmann
@@ -2285,6 +2286,25 @@ struct wide_string_input_helper<WideStringType, 2>
     }
 };
 
+class file_input_adapter : public input_adapter_protocol
+{
+public:
+    explicit file_input_adapter(const FILE *file)  noexcept
+            : file(file)
+    {}
+
+    std::char_traits<char>::int_type get_character() noexcept override
+    {
+        auto res = fgetc(const_cast<FILE *>(file));
+        if(res == EOF)
+            return std::char_traits<char>::eof();
+        else
+            return static_cast<std::char_traits<char>::int_type>(res);
+    }
+private:
+    /// the file pointer to read from
+    const FILE * file;
+};
 template<typename WideStringType>
 class wide_string_input_adapter : public input_adapter_protocol
 {
@@ -2354,6 +2374,9 @@ class input_adapter
     input_adapter(const std::u32string& ws)
         : ia(std::make_shared<wide_string_input_adapter<std::u32string>>(ws)) {}
 
+    input_adapter(const FILE *file)
+        : ia(std::make_shared<file_input_adapter>(file)) {}
+
     /// input adapter for buffer
     template<typename CharT,
              typename std::enable_if<