Line data Source code
1 : // 2 : // Copyright 2024 OpenModelViewer Authors 3 : // 4 : // Licensed under the Apache License, Version 2.0 (the "License"); 5 : // you may not use this file except in compliance with the License. 6 : // You may obtain a copy of the License at 7 : // 8 : // http://www.apache.org/licenses/LICENSE-2.0 9 : // 10 : // Unless required by applicable law or agreed to in writing, software 11 : // distributed under the License is distributed on an "AS IS" BASIS, 12 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 : // See the License for the specific language governing permissions and 14 : // limitations under the License. 15 : // 16 : 17 : #pragma once 18 : 19 : #include <string_view> 20 : 21 : namespace openmodelviewer::core::io 22 : { 23 : /** 24 : * @brief Represents the outcome of a file input/output operation. 25 : */ 26 : enum class IOResult 27 : { 28 : Success, ///< Operation completed successfully. 29 : FileNotFound, ///< The specified file was not found. 30 : FileAlreadyExists, ///< The file already exists (and should not). 31 : PermissionDenied, ///< Operation failed due to insufficient permissions. 32 : WriteError, ///< An error occurred while writing to the file. 33 : ReadError, ///< An error occurred while reading from the file. 34 : EmptyPath, ///< The provided path is empty. 35 : FilePathExpected, ///< A file path was expected, but a directory was provided. 36 : DirectoryPathExpected, ///< A directory path was expected, but a file was provided. 37 : UnknownError ///< An unspecified or unknown error occurred. 38 : }; 39 : 40 : /** 41 : * @brief Converts an IOResult value into a human-readable string for logging or debugging purposes. 42 : * 43 : * @param result The IOResult value to convert. 44 : * @return A string view representing the specified IOResult. 45 : * The returned string is a static literal and does not require memory management. 46 : */ 47 1 : inline std::string_view to_string(IOResult result) noexcept 48 : { 49 1 : switch (result) 50 : { 51 0 : case IOResult::Success: return "Success"; 52 1 : case IOResult::FileNotFound: return "File not found"; 53 0 : case IOResult::FileAlreadyExists: return "File already exists"; 54 0 : case IOResult::PermissionDenied: return "Permission denied"; 55 0 : case IOResult::WriteError: return "Write error"; 56 0 : case IOResult::ReadError: return "Read error"; 57 0 : case IOResult::EmptyPath: return "Empty path"; 58 0 : case IOResult::FilePathExpected: return "File path expected"; 59 0 : case IOResult::DirectoryPathExpected: return "Directory path expected"; 60 0 : case IOResult::UnknownError: return "Unknown error"; 61 : } 62 : 63 0 : return "Invalid_IOResult"; 64 : } 65 : 66 : } // namespace openmodelviewer::core::io