File.hpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. #if defined(unix) || defined(__APPLE__)
  17. #include <dirent.h>
  18. #endif
  19. #ifdef _WIN32
  20. #include <windows.h>
  21. #endif
  22. namespace ls_std {
  23. class File : public Class {
  24. public:
  25. explicit File(std::string _absoluteFilePath);
  26. ~File() = default;
  27. // comparison operators
  28. bool operator==(File& _file);
  29. bool operator!=(File& _file);
  30. // additional functionality
  31. bool canExecute();
  32. void createNewFile();
  33. bool exists();
  34. std::string getAbsoluteFilePath();
  35. std::string getName();
  36. std::string getParent();
  37. long getSize();
  38. bool isDirectory();
  39. bool isFile();
  40. time_t lastModified();
  41. std::list<std::string> list();
  42. std::list<std::string> listFiles();
  43. void makeDirectory();
  44. void makeDirectories();
  45. void remove();
  46. private:
  47. std::string absoluteFilePath {};
  48. #ifdef _WIN32
  49. static void _addToFileListWindows(const std::string& _path, bool _withDirectories, WIN32_FIND_DATA _data, std::list<std::string>& _list);
  50. #endif
  51. #if defined(unix) || defined(__APPLE__)
  52. static void _addToFileListUnix(const std::string& _path, bool _withDirectories, dirent* directoryEntity, std::list<std::string>& _list);
  53. #endif
  54. static bool _exists(const std::string& _path);
  55. static std::string _getParent(const std::string& _path);
  56. static bool _isDirectory(const std::string& _path);
  57. static bool _isFile(const std::string& _path);
  58. static time_t _lastModified(const std::string& _path);
  59. static std::list<std::string> _list(const std::string& _path);
  60. static std::list<std::string> _listFiles(const std::string& _path);
  61. #if defined(unix) || defined(__APPLE__)
  62. static std::list<std::string> _listUnix(const std::string& _path, bool withDirectories);
  63. #endif
  64. #ifdef _WIN32
  65. static std::list<std::string> _listWindows(const std::string& _path, bool withDirectories);
  66. #endif
  67. static int _mkdir(const std::string& _path);
  68. static std::string _normalizePath(std::string _path);
  69. static std::vector<std::string> _splitIntoSubDirectoryNames(const std::string& _path);
  70. };
  71. }
  72. #endif