1 #ifndef _DEFILEPATH_HPP
2 #define _DEFILEPATH_HPP
3 /*-------------------------------------------------------------------------
4 * drawElements C++ Base Library
5 * -----------------------------
7 * Copyright 2014 The Android Open Source Project
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
23 * \brief Filesystem path class.
24 *//*--------------------------------------------------------------------*/
34 void FilePath_selfTest (void);
41 TYPE_UNKNOWN = 0, /*!< Non-existent or unknown object. */
42 TYPE_FILE, /*!< File. */
43 TYPE_DIRECTORY, /*!< Directory. */
48 static const std::string separator; /*!< Path separator. */
51 FilePath (const std::string& path);
52 FilePath (const char* path);
53 FilePath (const std::vector<std::string>& components);
56 bool exists (void) const;
57 Type getType (void) const;
59 const char* getPath (void) const;
60 std::string getBaseName (void) const;
61 std::string getDirName (void) const;
62 std::string getFileExtension (void) const;
64 static FilePath join (const FilePath& a, const FilePath& b);
65 FilePath& join (const FilePath& b);
67 static FilePath normalize (const FilePath& path);
68 FilePath& normalize (void);
70 void split (std::vector<std::string>& components) const;
71 static FilePath join (const std::vector<std::string>& components);
73 bool isAbsolutePath (void) const;
75 static bool isSeparator (char c);
78 bool isRootPath (void) const;
79 bool isWinNetPath (void) const;
80 bool beginsWithDrive (void) const;
85 // \todo [2012-09-05 pyry] Move to delibs?
86 void createDirectory (const char* path);
87 void createDirectoryAndParents (const char* path);
89 inline FilePath::FilePath (void)
93 inline FilePath::FilePath (const std::string& path)
98 inline FilePath::FilePath (const char* path)
103 inline FilePath::~FilePath ()
107 inline FilePath& FilePath::join (const FilePath& b)
112 m_path += separator + b.m_path;
116 inline FilePath FilePath::join (const FilePath& a, const FilePath& b)
118 return FilePath(a).join(b);
121 inline const char* FilePath::getPath (void) const
123 return m_path.c_str();
126 inline bool FilePath::isSeparator (char c)
128 return c == '/' || c == '\\';
131 inline bool FilePath::isRootPath (void) const
133 return m_path.length() >= 1 && isSeparator(m_path[0]);
136 inline bool FilePath::isWinNetPath (void) const
138 return m_path.length() >= 2 && isSeparator(m_path[0]) && isSeparator(m_path[1]);
143 #endif // _DEFILEPATH_HPP