From 9ccb5e1a6b438d0bb8a0b4f18444bda3d389367a Mon Sep 17 00:00:00 2001 From: apio Date: Wed, 8 Jun 2022 20:19:01 +0200 Subject: [PATCH] docs for FileIO, a very enjoyable namespace --- src/FileIO.cpp | 2 +- src/FileIO.h | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/FileIO.cpp b/src/FileIO.cpp index 314931a..610e38c 100644 --- a/src/FileIO.cpp +++ b/src/FileIO.cpp @@ -8,6 +8,7 @@ std::string FileIO::read_all(const std::string& filename) { + if(std::filesystem::is_directory(std::filesystem::status(filename))) Error::throw_error_without_location("unable to open file "+ filename + ": Is a directory"); std::ifstream file; file.exceptions(std::ios::badbit | std::ios::failbit); try @@ -19,7 +20,6 @@ std::string FileIO::read_all(const std::string& filename) Error::throw_error_without_location("unable to open file "+ filename + ": " + strerror(errno)); return ""; } - if(std::filesystem::is_directory(std::filesystem::status(filename))) Error::throw_error_without_location("unable to open file "+ filename + ": Is a directory"); file.exceptions(std::ios::goodbit); std::vector file_chars; char fchar; diff --git a/src/FileIO.h b/src/FileIO.h index 57b205e..cbd2f2e 100644 --- a/src/FileIO.h +++ b/src/FileIO.h @@ -1,8 +1,11 @@ #pragma once #include +/* Namespace for simple file operations. */ namespace FileIO // namespaces are just so neat { + /* Helper function to read all of a file's contents. */ std::string read_all(const std::string& filename); + /* Helper function to write a string to a file. */ void write_all(const std::string& filename, const std::string& contents); }