iutest  1.17.99.14
iutest_filepath.hpp
[詳解]
1 //======================================================================
2 //-----------------------------------------------------------------------
13 //-----------------------------------------------------------------------
14 //======================================================================
15 #ifndef INCG_IRIS_IUTEST_FILEPATH_HPP_D69E7545_BF8A_4EDC_9493_9105C69F9378_
16 #define INCG_IRIS_IUTEST_FILEPATH_HPP_D69E7545_BF8A_4EDC_9493_9105C69F9378_
17 
18 #if !defined(IUTEST_USE_GTEST)
19 
20 //======================================================================
21 // include
22 #include "iutest_port.hpp"
23 
24 namespace iutest
25 {
26 
27 namespace detail
28 {
29 
30 //======================================================================
31 // class
35 class iuFilePath
36 {
37 public:
38  iuFilePath() : m_path("") {}
39  iuFilePath(const iuFilePath& rhs) : m_path(rhs.m_path) {}
40 
41  explicit iuFilePath(const char* path) : m_path(path)
42  {
43  Normalize();
44  }
45  explicit iuFilePath(const ::std::string& path) : m_path(path)
46  {
47  Normalize();
48  }
49 #if IUTEST_USE_CXX_FILESYSTEM
50  explicit iuFilePath(const ::std::filesystem::path& path) : m_path(path.string())
51  {
52  Normalize();
53  }
54 #endif
55 
56 public:
57  ::std::string ToString() const { return m_path; }
58  const ::std::string& string() const { return m_path; }
59  bool IsEmpty() const { return m_path.empty(); }
60  size_t length() const { return m_path.length(); }
61 
62 #if IUTEST_USE_CXX_FILESYSTEM
63  ::std::filesystem::path path() const { return ::std::filesystem::path(m_path); }
64  ::std::filesystem::file_status status() const { return ::std::filesystem::status(path()); }
65 #endif
66 
67 public:
68  iuFilePath& operator = (const iuFilePath& rhs) { m_path = rhs.m_path; return *this; }
69 
70  bool operator == (const iuFilePath& rhs) const
71  {
72  return IsStringCaseEqual(m_path, rhs.m_path);
73  }
74  bool operator == (const char* rhs) const
75  {
76  return IsStringCaseEqual(m_path, rhs);
77  }
78 
79 public:
83  bool IsDirectory() const;
84 
88  bool IsRootDirectory() const;
89 
93  bool IsAbsolutePath() const;
94 
98  iuFilePath RemoveTrailingPathSeparator() const;
99 
103  ::std::string GetExtension() const;
104 
108  iuFilePath RemoveExtension(const char* extension=NULL) const;
109 
113  iuFilePath RemoveDirectoryName() const;
114 
118  iuFilePath RemoveFileName() const;
119 
123  bool CreateFolder() const;
124 
128  bool CreateDirectoriesRecursively() const;
129 
133  bool FileOrDirectoryExists() const;
134 
138  bool DirectoryExists() const;
139 
140 public:
144  static iuFilePath GetCurrentDir();
145 
149  static iuFilePath GetRelativeCurrentDir();
150 
154  static iuFilePath GetExecFilePath();
155 
159  static iuFilePath ConcatPaths(const iuFilePath& directory, const iuFilePath& relative_path);
160 
161 private:
165  void Normalize();
166 
167 private:
168  ::std::string m_path;
169 };
170 
171 inline iu_ostream& operator << (iu_ostream& os, const iuFilePath& path)
172 {
173  return os << path.string();
174 }
175 
176 } // end of namespace detail
177 
178 namespace internal
179 {
180  // google test との互換性のため
181  typedef detail::iuFilePath FilePath;
182 }
183 
184 } // end of namespace iutest
185 
186 #if !IUTEST_HAS_LIB
187 # include "../impl/iutest_filepath.ipp" // IWYU pragma: export
188 #endif
189 
190 #endif
191 
192 #endif // INCG_IRIS_IUTEST_FILEPATH_HPP_D69E7545_BF8A_4EDC_9493_9105C69F9378_
iutest root namespace
Definition: iutest_charcode.hpp:33