diff --git a/include/tmp/file b/include/tmp/file index bb4a84a..e0de5e0 100644 --- a/include/tmp/file +++ b/include/tmp/file @@ -46,12 +46,30 @@ class TMP_EXPORT file : public entry { public: /// Creates a unique temporary file and opens it for reading and writing /// in binary mode - /// @param label A label to attach to the temporary file path - /// @param extension An extension of the temporary file path + /// @param[in] label A label to attach to the temporary file path + /// @param[in] extension An extension of the temporary file path /// @throws std::filesystem::filesystem_error if cannot create a file /// @throws std::invalid_argument if arguments are ill-formatted explicit file(std::string_view label = "", std::string_view extension = ""); + /// Creates a unique temporary file and opens it for reading and writing + /// in binary mode + /// @param[out] ec Parameter for error reporting + explicit file(std::error_code& ec); + + /// Creates a unique temporary file and opens it for reading and writing + /// in binary mode + /// @param[in] label A label to attach to the temporary file path + /// @param[out] ec Parameter for error reporting + file(std::string_view label, std::error_code& ec); + + /// Creates a unique temporary file and opens it for reading and writing + /// in binary mode + /// @param[in] label A label to attach to the temporary file path + /// @param[in] extension An extension of the temporary file path + /// @param[out] ec Parameter for error reporting + file(std::string_view label, std::string_view extension, std::error_code& ec); + /// Creates a unique temporary file and opens it for reading and writing /// in text mode /// @param label A label to attach to the temporary file path @@ -61,6 +79,25 @@ public: static file text(std::string_view label = "", std::string_view extension = ""); + /// Creates a unique temporary file and opens it for reading and writing + /// in text mode + /// @param[out] ec Parameter for error reporting + static file text(std::error_code& ec); + + /// Creates a unique temporary file and opens it for reading and writing + /// in text mode + /// @param[in] label A label to attach to the temporary file path + /// @param[out] ec Parameter for error reporting + static file text(std::string_view label, std::error_code& ec); + + /// Creates a unique temporary file and opens it for reading and writing + /// in text mode + /// @param[in] label A label to attach to the temporary file path + /// @param[in] extension An extension of the temporary file path + /// @param[out] ec Parameter for error reporting + static file text(std::string_view label, std::string_view extension, + std::error_code& ec); + /// Creates a unique temporary copy from the given path /// @param path A path to make a temporary copy from /// @param label A label to attach to the temporary file path diff --git a/src/file.cpp b/src/file.cpp index 150d063..5afaa6c 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -111,6 +111,19 @@ file::file(std::string_view label, std::string_view extension) : entry(create_file(label, extension)), binary(true) {} +file::file(std::error_code& ec) + : entry(create_file("", "", ec)), + binary(true) {} + +file::file(std::string_view label, std::error_code& ec) + : entry(create_file(label, "", ec)), + binary(true) {} + +file::file(std::string_view label, std::string_view extension, + std::error_code& ec) + : entry(create_file(label, extension, ec)), + binary(true) {} + file file::text(std::string_view label, std::string_view extension) { file result = file(label, extension); result.binary = false; @@ -118,6 +131,22 @@ file file::text(std::string_view label, std::string_view extension) { return result; } +file file::text(std::error_code& ec) { + return text("", ec); +} + +file file::text(std::string_view label, std::error_code& ec) { + return text(label, "", ec); +} + +file file::text(std::string_view label, std::string_view extension, + std::error_code& ec) { + file result = file(label, extension, ec); + result.binary = false; + + return result; +} + file file::copy(const fs::path& path, std::string_view label, std::string_view extension) { file tmpfile = file(label, extension);