You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

150 lines
3.1 KiB

  1. #pragma once
  2. #include <string>
  3. #include <vector>
  4. #include "../misc.h"
  5. namespace cppfs
  6. {
  7. enum class path_status
  8. {
  9. none = 0,
  10. absoulte,
  11. relative,
  12. };
  13. struct path
  14. {
  15. public:
  16. using string_vector = std::vector<std::string>;
  17. public:
  18. /**
  19. * @brief Get the path of the current working directory.
  20. */
  21. static inline path current();
  22. private:
  23. path_status _status;
  24. mutable std::string _path;
  25. mutable string_vector _parts;
  26. public:
  27. /**
  28. * @brief Default construtor.
  29. */
  30. inline path();
  31. /**
  32. * @brief Value construtor.
  33. */
  34. inline path(const std::string& p_path);
  35. /**
  36. * @brief Value construtor.
  37. */
  38. inline path(
  39. string_vector&& p_parts,
  40. path_status p_status);
  41. /**
  42. * @brief Value construtor.
  43. */
  44. inline path(
  45. const string_vector& p_parts,
  46. path_status p_status = path_status::none);
  47. /**
  48. * @brief Value construtor.
  49. */
  50. inline path(
  51. const std::initializer_list<std::string>& p_parts,
  52. path_status p_status = path_status::none);
  53. /**
  54. * @brief Move constructor.
  55. */
  56. inline path(path&&) = default;
  57. /**
  58. * @brief Copy constructor.
  59. */
  60. inline path(const path&) = default;
  61. /**
  62. * @brief Move assignment constructor.
  63. */
  64. inline path& operator=(path&&) = default;
  65. /**
  66. * @brief Copy assignment constructor.
  67. */
  68. inline path& operator=(const path&) = default;
  69. public:
  70. /**
  71. * @brief Get the path status.
  72. */
  73. inline path_status status() const;
  74. /**
  75. * @brief Get the type of the path.
  76. */
  77. inline file_type type() const;
  78. /**
  79. * @brief Get the stored path as string.
  80. */
  81. inline const std::string& str() const;
  82. /**
  83. * @brief Get the parts of the path.
  84. */
  85. inline const string_vector& parts() const;
  86. /**
  87. * @brief Returns true if the path exists.
  88. */
  89. inline bool exsists() const;
  90. /**
  91. * @brief Returns true if the path is a normal file.
  92. */
  93. inline bool is_file() const;
  94. /**
  95. * @brief Returns true if the path is a normal directory.
  96. */
  97. inline bool is_directory() const;
  98. /**
  99. * @brief Returns the base path of the current stored path.
  100. */
  101. inline path base() const;
  102. /**
  103. * @brief Returns the normalized path.
  104. */
  105. inline path normalize() const;
  106. /**
  107. * @brief Returns file extension.
  108. */
  109. inline std::string extension() const;
  110. /**
  111. * @brief Combines two paths.
  112. */
  113. inline path join(const path& other) const;
  114. private:
  115. /**
  116. * @brief Create a path from the parts vector.
  117. */
  118. std::string make_path() const;
  119. };
  120. }