* @brief This class provides an interface for file operations. */
| 8 | class KittyIOFile |
| 9 | { |
| 10 | private: |
| 11 | int _fd; |
| 12 | std::string _filePath; |
| 13 | int _flags; |
| 14 | mode_t _mode; |
| 15 | int _error; |
| 16 | |
| 17 | public: |
| 18 | /** |
| 19 | * @brief Default constructor creating an uninitialized file object. |
| 20 | */ |
| 21 | KittyIOFile() : _fd(-1), _flags(0), _mode(0), _error(0) |
| 22 | { |
| 23 | } |
| 24 | |
| 25 | /** |
| 26 | * @brief Constructs a new KittyIOFile object with file path, flags, and optional mode. |
| 27 | * |
| 28 | * @param filePath The path to the file. |
| 29 | * @param flags The flags for opening the file. |
| 30 | * @param mode The mode/permissions for opening the file (default: 0). |
| 31 | */ |
| 32 | KittyIOFile(const std::string &filePath, int flags, mode_t mode = 0) |
| 33 | : _fd(-1), _filePath(filePath), _flags(flags), _mode(mode), _error(0) |
| 34 | { |
| 35 | } |
| 36 | |
| 37 | ~KittyIOFile() |
| 38 | { |
| 39 | if (_fd >= 0) |
| 40 | { |
| 41 | close(); |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | KittyIOFile(const KittyIOFile &) = delete; |
| 46 | KittyIOFile &operator=(const KittyIOFile &) = delete; |
| 47 | |
| 48 | /** |
| 49 | * @brief Move constructor. Transfers ownership of the file descriptor. |
| 50 | */ |
| 51 | KittyIOFile(KittyIOFile &&other) noexcept |
| 52 | : _fd(other._fd), _filePath(std::move(other._filePath)), _flags(other._flags), _mode(other._mode), |
| 53 | _error(other._error) |
| 54 | { |
| 55 | other._fd = -1; |
| 56 | other._error = 0; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * @brief Move assignment operator. Closes current file descriptor and transfers ownership. |
| 61 | */ |
| 62 | KittyIOFile &operator=(KittyIOFile &&other) noexcept |
| 63 | { |
| 64 | if (this != &other) |
| 65 | { |
| 66 | close(); |
| 67 |
nothing calls this directly
no outgoing calls
no test coverage detected