2 * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * @author Tomasz Iwanek (t.iwanek@samsung.com)
33 #include <dpl/exception.h>
34 #include <dpl/string.h>
42 std::ostream & operator<<(std::ostream & str, const DPL::Utils::Path & path);
47 * @brief The Path class path abstraction
49 * Class for expressing paths not limited not existing ones.
50 * It's possible to check if path exists, remove it or iterate it if it's directory
55 DECLARE_EXCEPTION_TYPE(DPL::Exception, BaseException)
56 DECLARE_EXCEPTION_TYPE(BaseException, AlreadyExists)
57 DECLARE_EXCEPTION_TYPE(BaseException, NotExists)
58 DECLARE_EXCEPTION_TYPE(BaseException, NotDirectory)
59 DECLARE_EXCEPTION_TYPE(BaseException, OperationFailed)
60 DECLARE_EXCEPTION_TYPE(BaseException, EmptyPath)
61 DECLARE_EXCEPTION_TYPE(BaseException, InternalError)
63 class Iterator : public std::iterator<std::input_iterator_tag, Path>
67 Iterator(const char *);
68 Iterator& operator++();
69 Iterator operator++(int);
70 bool operator==(const Iterator& rhs) const;
71 bool operator!=(const Iterator& rhs) const;
72 const Path & operator*();
73 const Path * operator->();
77 std::shared_ptr<DIR> m_dir;
78 std::shared_ptr<Path> m_path;
79 std::shared_ptr<Path> m_root;
82 explicit Path(const DPL::String & str);
83 explicit Path(const std::string & str);
84 explicit Path(const char * str);
87 * @brief DirectoryName shell's dirname equivalent
88 * @return directory name of given path
90 std::string DirectoryName() const;
92 * @brief Basename shell's basename equivalent
93 * @return base name of given path
95 std::string Basename() const;
97 * @brief Fullpath fullpath based on current working diretory
100 std::string Fullpath() const;
105 bool IsSymlink() const;
107 bool operator==(const Path & other) const;
108 bool operator!=(const Path & other) const;
111 Path operator/(const DPL::String& part) const;
112 Path operator/(const std::string& part) const;
113 Path operator/(const char * part) const;
115 Path & operator/=(const DPL::String& part);
116 Path & operator/=(const std::string& part);
117 Path & operator/=(const char * part);
120 Iterator begin() const;
121 Iterator end() const;
126 void Append(const std::string& part);
127 void Construct(const std::string & src);
129 std::vector<std::string> m_parts;
131 friend std::ostream & ::operator<<(std::ostream & str, const DPL::Utils::Path & path);
135 * @brief MkDir creates 'current path' as directory
139 void MakeDir(const Path & path, mode_t mode = 0755);
142 * @brief MkFile creates 'current path' as empty file
145 void MakeEmptyFile(const Path & path);
148 * @brief Remove removes 'current path'
149 * @param path path to remove
151 void Remove(const Path & path);
154 * @brief Rename renames(moves) current path
156 * If you uses this method string to path is internally change
157 * and this object will store new path not only anymore
158 * @param from source path
159 * @param to target path
161 void Rename(const Path & from, const Path & to);
164 * @brief Exists Checks if given path exists
166 * @return true if path exists
168 bool Exists(const Path & path);
174 //TODO: uncomment when user defiend literals are supported
175 ///Path operator"" p(const char * str);