File.hpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-08-15
  6. * Changed: 2020-08-17
  7. *
  8. * */
  9. #ifndef FILE_HPP
  10. #define FILE_HPP
  11. #include "../base/Class.hpp"
  12. #include <string>
  13. #include <vector>
  14. #include <list>
  15. #include <ctime>
  16. namespace ls_std {
  17. class File : public Class {
  18. public:
  19. explicit File(std::string _absoluteFilePath);
  20. ~File() = default;
  21. // comparison operators
  22. bool operator==(File& _file);
  23. bool operator!=(File& _file);
  24. // additional functionality
  25. bool canExecute();
  26. void createNewFile();
  27. bool exists();
  28. std::string getAbsoluteFilePath();
  29. std::string getName();
  30. std::string getParent();
  31. long getSize();
  32. bool isDirectory();
  33. bool isFile();
  34. time_t lastModified();
  35. std::list<std::string> list();
  36. void makeDirectory();
  37. void makeDirectories();
  38. void remove();
  39. private:
  40. std::string absoluteFilePath {};
  41. static bool _exists(const std::string& _path);
  42. static std::string _getParent(const std::string& _path);
  43. static bool _isDirectory(const std::string& _path);
  44. static bool _isFile(const std::string& _path);
  45. static time_t _lastModified(const std::string& _path);
  46. static std::list<std::string> _list(const std::string& _path);
  47. #if defined(unix) || defined(__APPLE__)
  48. static std::list<std::string> _listUnix(const std::string& _path);
  49. #endif
  50. #ifdef _WIN32
  51. static std::list<std::string> _listWindows(const std::string& _path);
  52. #endif
  53. static int _mkdir(const std::string& _path);
  54. static std::string _normalizePath(std::string _path);
  55. static std::vector<std::string> _splitIntoSubDirectoryNames(const std::string& _path);
  56. };
  57. }
  58. #endif