iutest  1.17.1.0
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  iuFilePath& operator == (const iuFilePath& rhs)
71  {
72  m_path = rhs.m_path;
73  return *this;
74  }
75  bool operator == (const iuFilePath& rhs) const
76  {
77  return IsStringCaseEqual(m_path, rhs.m_path);
78  }
79  bool operator == (const char* rhs) const
80  {
81  return IsStringCaseEqual(m_path, rhs);
82  }
83 
84 public:
88  bool IsDirectory() const;
89 
93  bool IsRootDirectory() const;
94 
98  bool IsAbsolutePath() const;
99 
103  iuFilePath RemoveTrailingPathSeparator() const;
104 
108  ::std::string GetExtension() const;
109 
113  iuFilePath RemoveExtension(const char* extension=NULL) const;
114 
118  iuFilePath RemoveDirectoryName() const;
119 
123  iuFilePath RemoveFileName() const;
124 
128  bool CreateFolder() const;
129 
133  bool CreateDirectoriesRecursively() const;
134 
138  bool FileOrDirectoryExists() const;
139 
143  bool DirectoryExists() const;
144 
145 public:
149  static iuFilePath GetCurrentDir();
150 
154  static iuFilePath GetRelativeCurrentDir();
155 
159  static iuFilePath GetExecFilePath();
160 
164  static iuFilePath ConcatPaths(const iuFilePath& directory, const iuFilePath& relative_path);
165 
166 private:
170  void Normalize();
171 
172 private:
173  ::std::string m_path;
174 };
175 
176 inline iu_ostream& operator << (iu_ostream& os, const iuFilePath& path)
177 {
178  return os << path.string();
179 }
180 
181 } // end of namespace detail
182 
183 namespace internal
184 {
185  // google test との互換性のため
186  typedef detail::iuFilePath FilePath;
187 }
188 
189 } // end of namespace iutest
190 
191 #if !IUTEST_HAS_LIB
192 # include "../impl/iutest_filepath.ipp"
193 #endif
194 
195 #endif
196 
197 #endif // INCG_IRIS_IUTEST_FILEPATH_HPP_D69E7545_BF8A_4EDC_9493_9105C69F9378_
iutest_config.hpp
iris unit test config
iutest
iutest root namespace
Definition: iutest_charcode.hpp:31
iutest_port.hpp
portable