/** * @brief The type of file. * */ enumfiletype { /** undefined */ unknown = 0x00, /** directory */ directory = 0x01, /** regular file */ file = 0x02, /** symbolic link */ symlink = 0x04, /** character device, only for unix */ char_special = 0x08, /** block device, only for unix */ block_special = 0x10, /** named pipe, only for unix */ pipefifo = 0x20, /** socket file, only for unix */ socket = 0x40, /** type mask, includes all types */ all = 0xFF, };
/** * @brief The class for file path operations. * */ classfilepath { public: /** * @brief Construct a new filepath object * * @param path file path string */ filepath(const std::string &path);
/** * @brief Construct a new filepath object by copy * * @param other other filepath object */ filepath(const filepath &other);
/** * @brief Assign operator, assign a new filepath object by copy * * @param other other filepath object * @return filepath& the reference of the current filepath object */ filepath &operator=(const filepath &other);
public: /** * @brief Get the file type of the filepath. * * @return file type */ filetype type()const;
/** * @brief Check if the filepath is a regular file. * * @return true mena regular file, false means not regular file. */ boolisfile()const;
/** * @brief Check if the filepath is a directory. * * @return true means directory, false means not directory. */ boolisdir()const; private: std::string filepath_; };
/** * @brief Define the output stream operator for filepath object. * * @param os the std::ostream object * @param fp the filepath object to be output * @return std::ostream& the reference of the std::ostream object after outputing the filepath object. */ std::ostream &operator<<(std::ostream &os, const filepath &fp);
/** * @brief Create a filepath object from a string. * * @param path file path string * @return filepath object */ filepath path(const std::string &path);
--------------------------------------------TestFileType-------------------------------------------- path1: ./fileutil_test/dir1, type: 1, d path2: ./fileutil_test/file3.txt, type: 2, - path3: ./fileutil_test/file4.data, type: 2, - path4: C:/Users/Public/Desktop/CMake-gui.lnk, type: [2024-06-26 12:25:45.877][E]]0x7ff85b8d5fc0](cutl) [filesystem_unix.cpp:298:get_file_type] stat error. filepath:C:/Users/Public/Desktop/CMake-gui.lnk, error:No such file or directory 0, [2024-06-26 12:25:45.877][E]]0x7ff85b8d5fc0](cutl) [filesystem_unix.cpp:298:get_file_type] stat error. filepath:C:/Users/Public/Desktop/CMake-gui.lnk, error:No such file or directory u path5: C:/Users/vboxuser/Desktop/VisualStudio2015, type: [2024-06-26 12:25:45.877][E]]0x7ff85b8d5fc0](cutl) [filesystem_unix.cpp:298:get_file_type] stat error. filepath:C:/Users/vboxuser/Desktop/VisualStudio2015, error:No such file or directory 0, [2024-06-26 12:25:45.877][E]]0x7ff85b8d5fc0](cutl) [filesystem_unix.cpp:298:get_file_type] stat error. filepath:C:/Users/vboxuser/Desktop/VisualStudio2015, error:No such file or directory u path6: C:/Users/Public/Desktop/VisualStudio2015.lnk, type: [2024-06-26 12:25:45.877][E]]0x7ff85b8d5fc0](cutl) [filesystem_unix.cpp:298:get_file_type] stat error. filepath:C:/Users/Public/Desktop/VisualStudio2015.lnk, error:No such file or directory 0, [2024-06-26 12:25:45.877][E]]0x7ff85b8d5fc0](cutl) [filesystem_unix.cpp:298:get_file_type] stat error. filepath:C:/Users/Public/Desktop/VisualStudio2015.lnk, error:No such file or directory u path7: C:/Users/vboxuser/Desktop/VisualStudio2015.lnk, type: [2024-06-26 12:25:45.877][E]]0x7ff85b8d5fc0](cutl) [filesystem_unix.cpp:298:get_file_type] stat error. filepath:C:/Users/Public/Desktop/VisualStudio2015.lnk, error:No such file or directory 0, [2024-06-26 12:25:45.877][E]]0x7ff85b8d5fc0](cutl) [filesystem_unix.cpp:298:get_file_type] stat error. filepath:C:/Users/vboxuser/Desktop/VisualStudio2015.lnk, error:No such file or directory u