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.

This commit is contained in:
Jonathan Dumaresq 2018-12-11 09:33:30 -05:00
parent f86090aafc
commit 67b0daf27b

View file

@ -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<