2 // Copyright (c) 2010-2017 Intel Corporation
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.
25 bool Path::isDir() const
27 struct stat s = { 0 };
29 if (stat(path.c_str(), &s)) {
33 return s.st_mode & S_IFDIR;
36 bool Path::isFile() const
38 struct stat s = { 0 };
40 if (stat(path.c_str(), &s)) {
44 return s.st_mode & S_IFREG;
47 Path Path::add(const string& str) const
53 return Path(ss.str());
56 Path Path::add(int number) const
62 return Path(ss.str());
65 Path &Path::concat(const string &add)
75 int Path::mkdir() const
78 return ::mkdir(path.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
82 std::ostream& operator<<(std::ofstream &stream, const Path &p)
84 stream << p.path.c_str();
89 string Path::getFileName() const
91 for (size_t i = path.size() - 1; i >= 0; --i) {
93 return path.substr(i + 1);