| 1 | #cxx . . $ `<file>/io/misc.cpp`/define CPP_UTILITIES_IOMISC_STRING_VIEWcxx . . $ `io/misc.cpp:1:9`! |
| 2 | |
| 3 | #include "./misc.h"cxx . . $ `<file>/io/misc.h`/ |
| 4 | #include "./nativefilestream.h"cxx . . $ `<file>/io/nativefilestream.h`/ |
| 5 | |
| 6 | #include <iterator> |
| 7 | |
| 8 | using namespace std; |
| 9 | |
| 10 | namespace CppUtilitiescxx . . $ CppUtilities/ { |
| 11 | |
| 12 | /*! |
| 13 | * \brief Reads all contents of the specified file in a single call. |
| 14 | * \throws Throws std::ios_base::failure when an error occurs or the specified \a maxSize |
| 15 | * would be exceeded. |
| 16 | */ |
| 17 | stdcxx . . $ std/::stringcxx . . $ std/string# readFilecxx . . $ CppUtilities/readFile(a65ccaa3e10e72de).(const stdcxx . . $ std/::stringcxx . . $ std/string# &path, stdcxx . . $ std/::stringcxx . . $ std/string#::size_typecxx . . $ std/__cxx11/basic_string#size_type# maxSize) |
| 18 | { |
| 19 | auto file = NativeFileStreamcxx . . $ CppUtilities/NativeFileStream#NativeFileStream(49f6e7a06ebc5aa8).(); |
| 20 | file.exceptionscxx . . $ std/basic_ios#exceptions(3e5fb2eb616d497d).(ios_basecxx . . $ std/ios_base#::failbitcxx . . $ std/ios_base#failbit. |cxx . . $ std/`operator|`(c5b5c7d100a244bc). ios_basecxx . . $ std/ios_base#::badbitcxx . . $ std/ios_base#badbit.); |
| 21 | file.opencxx . . $ CppUtilities/NativeFileStream#open(be6c264dafcf0985).(path, ios_basecxx . . $ std/ios_base#::incxx . . $ std/ios_base#in. |cxx . . $ std/`operator|`(2dd9eb40323da8bf). ios_basecxx . . $ std/ios_base#::binarycxx . . $ std/ios_base#binary.); |
| 22 | file.seekgcxx . . $ std/basic_istream#seekg(f79fad2892c4fe4).(0, ios_basecxx . . $ std/ios_base#::endcxx . . $ std/ios_base#end.); |
| 23 | stringcxx . . $ std/string# rescxx . . $ std/__cxx11/basic_string#basic_string(925dcc5e17f50391).; |
| 24 | const auto size = static_cast<stringcxx . . $ std/string#::size_typecxx . . $ std/__cxx11/basic_string#size_type#>(file.tellgcxx . . $ std/basic_istream#tellg(bf66e90edbd3e74a).()); |
| 25 | if (maxSize != stringcxx . . $ std/string#::nposcxx . . $ std/__cxx11/basic_string#npos. && size > maxSize) { |
| 26 | throw ios_basecxx . . $ std/ios_base#failure#failure(7e40758012d50676).::failurecxx . . $ std/ios_base#failure#("File exceeds max size"); |
| 27 | } |
| 28 | res.reservecxx . . $ std/__cxx11/basic_string#reserve(9dac5f4bebd06212).(size); |
| 29 | file.seekgcxx . . $ std/basic_istream#seekg(d37dee3798fd4fd).(ios_basecxx . . $ std/fpos#fpos(1624ee8275b10bda).::begcxx . . $ std/ios_base#beg.); |
| 30 | // ignore warning about null pointer dereference from GCC 12 for now (which is *likely* not correct) |
| 31 | #ifdef __GNUC__cxx . . $ `<built-in>:8:9`! |
| 32 | #pragma GCC diagnostic push |
| 33 | #pragma GCC diagnostic ignored "-Wnull-dereference" |
| 34 | #endif |
| 35 | res.assigncxx . . $ std/__cxx11/basic_string#assign(9f2ab35b291ae8b7).((istreambuf_iteratorcxx . . $ std/istreambuf_iterator#<char>(file)), istreambuf_iteratorcxx . . $ std/istreambuf_iterator#istreambuf_iterator(ced63f7c635d850d).<char>()); |
| 36 | #ifdef __GNUC__cxx . . $ `<built-in>:8:9`! |
| 37 | #pragma GCC diagnostic pop |
| 38 | #endif |
| 39 | return rescxx . . $ std/__cxx11/basic_string#basic_string(8f3aaafa33d05d0b).; |
| 40 | } |
| 41 | |
| 42 | /*! |
| 43 | * \brief Reads all contents of the specified file in a single call. |
| 44 | * \throws Throws std::ios_base::failure when an error occurs or the specified \a maxSize |
| 45 | * would be exceeded. |
| 46 | */ |
| 47 | stdcxx . . $ std/::stringcxx . . $ std/string# readFilecxx . . $ CppUtilities/readFile(ffea7fa1eac373d4).(stdcxx . . $ std/::string_viewcxx . . $ std/string_view# path, stdcxx . . $ std/::string_viewcxx . . $ std/string_view#::size_typecxx . . $ std/basic_string_view#size_type# maxSize) |
| 48 | { |
| 49 | return readFilecxx . . $ CppUtilities/readFile(a65ccaa3e10e72de).(stdcxx . . $ std/::stringcxx . . $ std/string#(path), maxSize); |
| 50 | } |
| 51 | |
| 52 | /*! |
| 53 | * \brief Writes all \a contents to the specified file in a single call. |
| 54 | * \throws Throws std::ios_base::failure when an error occurs. |
| 55 | * \remarks Closing the file manually to prevent flushing the file within the d'tor which |
| 56 | * would suppress an exception |
| 57 | */ |
| 58 | void writeFilecxx . . $ CppUtilities/writeFile(9ebb09e227cac344).(stdcxx . . $ std/::string_viewcxx . . $ std/string_view# path, stdcxx . . $ std/::string_viewcxx . . $ std/string_view# contents) |
| 59 | { |
| 60 | auto file = NativeFileStreamcxx . . $ CppUtilities/NativeFileStream#NativeFileStream(49f6e7a06ebc5aa8).(); |
| 61 | file.exceptionscxx . . $ std/basic_ios#exceptions(3e5fb2eb616d497d).(ios_basecxx . . $ std/ios_base#::failbitcxx . . $ std/ios_base#failbit. |cxx . . $ std/`operator|`(c5b5c7d100a244bc). ios_basecxx . . $ std/ios_base#::badbitcxx . . $ std/ios_base#badbit.); |
| 62 | file.opencxx . . $ CppUtilities/NativeFileStream#open(be6c264dafcf0985).(stdcxx . . $ std/::stringcxx . . $ std/string#(path), ios_basecxx . . $ std/ios_base#::outcxx . . $ std/ios_base#out. |cxx . . $ std/`operator|`(2dd9eb40323da8bf). ios_basecxx . . $ std/ios_base#::trunccxx . . $ std/ios_base#trunc. |cxx . . $ std/`operator|`(2dd9eb40323da8bf). ios_basecxx . . $ std/ios_base#::binarycxx . . $ std/ios_base#binary.); |
| 63 | file.writecxx . . $ std/basic_ostream#write(3c866fa06c201852).(contents.datacxx . . $ std/basic_string_view#data(8e614c7de0b1573e).(), static_cast<stdcxx . . $ std/::streamoffcxx . . $ std/streamoff#>(contents.sizecxx . . $ std/basic_string_view#size(c9b1e749b64d5edc).())); |
| 64 | file.closecxx . . $ CppUtilities/NativeFileStream#close(49f6e7a06ebc5aa8).(); |
| 65 | } |
| 66 | |
| 67 | } // namespace CppUtilities |