tue_filesystem
path.cpp
Go to the documentation of this file.
1 
3 #include "tue/filesystem/path.h"
4 #include "boost/filesystem.hpp"
5 
6 namespace tue
7 {
8 namespace filesystem
9 {
10 
12 {
13 }
14 
15 Path::Path(const std::string& path) : path_(path)
16 {
17 }
18 
20 {
21 }
22 
24 {
25  return boost::filesystem::path(path_).extension().string();
26 }
27 
29 {
30  return boost::filesystem::path(path_).filename().string();
31 }
32 
34 {
35  std::string str = boost::filesystem::path(path_).parent_path().string();
36  if (str.empty())
37  str = ".";
38 
39  return Path(str);
40 }
41 
42 bool Path::exists() const
43 {
44  return boost::filesystem::exists(boost::filesystem::path(path_));
45 }
46 
47 bool Path::isRegularFile() const
48 {
49  return boost::filesystem::is_regular_file(boost::filesystem::path(path_));
50 }
51 
52 bool Path::isDirectory() const
53 {
54  return boost::filesystem::is_directory(boost::filesystem::path(path_));
55 }
56 
58 {
59  return boost::filesystem::last_write_time(boost::filesystem::path(path_));
60 }
61 
63 {
64  std::string ext = extension();
65 
66  if (!ext.empty())
67  path_ = path_.substr(0, path_.size() - ext.size());
68 
69  return *this;
70 }
71 
73 {
74  std::string ext = extension();
75 
76  Path p;
77  if (!ext.empty())
78  p.path_ = path_.substr(0, path_.size() - ext.size());
79  else
80  p = *this;
81 
82  return p;
83 }
84 
85 Path Path::join(const Path& sub_path) const
86 {
87  Path p(*this);
88 
89  if (!p.path_.empty() && p.path_[p.path_.size() - 1] != '/')
90  p.path_ += '/';
91 
92  p.path_ += sub_path.path_;
93  return p;
94 }
95 
96 } // end filesystem namespace
97 } // end tue namespace
path.h
std::string
tue::filesystem::Path::withoutExtension
Path withoutExtension() const
Definition: path.cpp:72
tue::filesystem::Path
Definition: path.h:18
std::string::size
T size(T... args)
tue::filesystem::Path::extension
std::string extension() const
Definition: path.cpp:23
tue::filesystem::Path::exists
bool exists() const
Definition: path.cpp:42
tue::filesystem::Path::isDirectory
bool isDirectory() const
Definition: path.cpp:52
tue::filesystem::Path::isRegularFile
bool isRegularFile() const
Definition: path.cpp:47
tue::filesystem::Path::filename
std::string filename() const
Definition: path.cpp:28
std::string::substr
T substr(T... args)
std::time_t
tue::filesystem::Path::~Path
virtual ~Path()
Definition: path.cpp:19
tue::filesystem::Path::path_
std::string path_
Text of the file system path.
Definition: path.h:124
std::string::empty
T empty(T... args)
tue::filesystem::Path::parentPath
Path parentPath() const
Definition: path.cpp:33
tue::filesystem::Path::removeExtension
Path & removeExtension()
Definition: path.cpp:62
tue::filesystem::Path::lastWriteTime
std::time_t lastWriteTime() const
Definition: path.cpp:57
tue
Definition: crawler.h:9
tue::filesystem::Path::Path
Path()
Definition: path.cpp:11
tue::filesystem::Path::join
Path join(const Path &path) const
Definition: path.cpp:85