libfoedus-core
FOEDUS Core Library
foedus::fs::Path Class Reference

Analogue of boost::filesystem::path. More...

Detailed Description

Analogue of boost::filesystem::path.

Unlike boost::filesystem::path, this always brings a full path. As soon as this object is instantiated, we convert it to an absolute path with absolute().

Todo:
Support Windows. MUCH later.

Definition at line 37 of file path.hpp.

#include <path.hpp>

Public Member Functions

 Path ()
 
 Path (const Path &p)
 
 Path (const std::string &s)
 This one resolves ~ at beginning. More...
 
Pathoperator= (const Path &p)
 
Pathoperator= (const std::string &s)
 
Pathoperator+= (const Path &p)
 
Pathoperator+= (const std::string &s)
 
void append_separator_if_needed ()
 
Pathoperator/= (const Path &p)
 
Pathoperator/= (const std::string &s)
 
const std::string & native () const
 
const char * c_str () const
 
const std::string & string () const
 
int compare (const Path &p) const noexcept
 
int compare (const std::string &s) const
 
Path parent_path () const
 
std::vector< Pathchild_paths () const
 
Path filename () const
 
bool root () const
 
bool empty () const
 
bool has_parent_path () const
 
bool has_filename () const
 

Static Public Attributes

static const char kPreferredSeparator = '/'
 

Friends

std::ostream & operator<< (std::ostream &o, const Path &v)
 

Constructor & Destructor Documentation

foedus::fs::Path::Path ( )
inline

Definition at line 41 of file path.hpp.

Referenced by compare(), filename(), and parent_path().

41 {}

Here is the caller graph for this function:

foedus::fs::Path::Path ( const Path p)
inline

Definition at line 42 of file path.hpp.

42 : pathname_(p.pathname_) {}
foedus::fs::Path::Path ( const std::string &  s)
explicit

This one resolves ~ at beginning.

Definition at line 29 of file path.cpp.

References foedus::fs::current_path(), foedus::fs::home_path(), kPreferredSeparator, and string().

29  {
30  if (s.size() > 0 && s.at(0) == '~'
31  && (s.size() == 1 || s.at(1) == '/')) {
32  // starts with ~/ or ~ alone: resolve it as home folder
33  pathname_ = home_path().pathname_;
34  pathname_.append(s.substr(1));
35  } else {
36  if (s.empty() || s.at(0) == kPreferredSeparator) {
37  pathname_ = s;
38  } else {
39  Path tmp = current_path();
40  tmp /= s;
41  pathname_ = tmp.string();
42  }
43  }
44 }
Path home_path()
Returns the absolute path of the home directory of the user running this process. ...
Definition: filesystem.cpp:80
Path current_path()
Returns the current working directory.
Definition: filesystem.cpp:66
static const char kPreferredSeparator
Definition: path.hpp:39

Here is the call graph for this function:

Member Function Documentation

void foedus::fs::Path::append_separator_if_needed ( )
inline

Definition at line 51 of file path.hpp.

References kPreferredSeparator.

Referenced by operator/=().

51  {
52  if (!pathname_.empty() && pathname_.at(pathname_.size() - 1) != kPreferredSeparator) {
53  pathname_ += kPreferredSeparator;
54  }
55  }
static const char kPreferredSeparator
Definition: path.hpp:39

Here is the caller graph for this function:

const char* foedus::fs::Path::c_str ( ) const
inline
std::vector< Path > foedus::fs::Path::child_paths ( ) const

Definition at line 64 of file path.cpp.

References c_str(), and foedus::fs::is_directory().

Referenced by foedus::fs::remove_all().

64  {
65  std::vector< Path > children;
66  if (is_directory(*this)) {
67  DIR *d = ::opendir(c_str());
68  if (d) {
69  for (dirent *e = ::readdir(d); e != nullptr; e = ::readdir(d)) {
70  if (e->d_name == std::string(".") || e->d_name == std::string("..")) {
71  continue;
72  }
73  Path child(*this);
74  child /= std::string(e->d_name);
75  children.emplace_back(child);
76  }
77  ::closedir(d);
78  }
79  }
80  return children;
81 }
bool is_directory(const Path &p)
Returns if the file is a directory.
Definition: filesystem.hpp:133
const char * c_str() const
Definition: path.hpp:64

Here is the call graph for this function:

Here is the caller graph for this function:

int foedus::fs::Path::compare ( const Path p) const
inlinenoexcept

Definition at line 67 of file path.hpp.

Referenced by foedus::fs::operator!=(), foedus::fs::operator<(), and foedus::fs::operator==().

67 { return pathname_.compare(p.pathname_); }

Here is the caller graph for this function:

int foedus::fs::Path::compare ( const std::string &  s) const
inline

Definition at line 68 of file path.hpp.

References compare(), and Path().

Referenced by compare().

68 { return compare(Path(s)); }
int compare(const Path &p) const noexcept
Definition: path.hpp:67

Here is the call graph for this function:

Here is the caller graph for this function:

bool foedus::fs::Path::empty ( ) const
inline

Definition at line 75 of file path.hpp.

Referenced by foedus::fs::create_directories(), and has_parent_path().

75 { return pathname_.empty(); } // name consistent with std containers

Here is the caller graph for this function:

Path foedus::fs::Path::filename ( ) const

Definition at line 46 of file path.cpp.

References kPreferredSeparator, and Path().

46  {
47  size_t pos = pathname_.find_last_of(kPreferredSeparator);
48  if (pos == pathname_.size()) {
49  return Path(pathname_);
50  } else {
51  return Path(pathname_.c_str() + pos);
52  }
53 }
static const char kPreferredSeparator
Definition: path.hpp:39

Here is the call graph for this function:

bool foedus::fs::Path::has_filename ( ) const
inline

Definition at line 77 of file path.hpp.

77 { return !pathname_.empty(); }
bool foedus::fs::Path::has_parent_path ( ) const
inline

Definition at line 76 of file path.hpp.

References empty(), and parent_path().

76 { return !parent_path().empty(); }
bool empty() const
Definition: path.hpp:75
Path parent_path() const
Definition: path.cpp:55

Here is the call graph for this function:

const std::string& foedus::fs::Path::native ( ) const
inline

Definition at line 63 of file path.hpp.

63 { return pathname_; }
Path& foedus::fs::Path::operator+= ( const Path p)
inline

Definition at line 48 of file path.hpp.

48 {pathname_ += p.pathname_; return *this;}
Path& foedus::fs::Path::operator+= ( const std::string &  s)
inline

Definition at line 49 of file path.hpp.

49 {pathname_ += s; return *this;}
Path& foedus::fs::Path::operator/= ( const Path p)
inline

Definition at line 56 of file path.hpp.

References operator/=().

Referenced by operator/=().

56 { return operator/=(p.pathname_); }
Path & operator/=(const Path &p)
Definition: path.hpp:56

Here is the call graph for this function:

Here is the caller graph for this function:

Path& foedus::fs::Path::operator/= ( const std::string &  s)
inline

Definition at line 57 of file path.hpp.

References append_separator_if_needed().

57  {
59  pathname_ += s;
60  return *this;
61  }
void append_separator_if_needed()
Definition: path.hpp:51

Here is the call graph for this function:

Path& foedus::fs::Path::operator= ( const Path p)
inline

Definition at line 46 of file path.hpp.

46 { pathname_ = p.pathname_; return *this; }
Path& foedus::fs::Path::operator= ( const std::string &  s)
inline

Definition at line 47 of file path.hpp.

47 { pathname_ = s; return *this; }
Path foedus::fs::Path::parent_path ( ) const

Definition at line 55 of file path.cpp.

References kPreferredSeparator, and Path().

Referenced by foedus::fs::create_directories(), foedus::fs::durable_atomic_rename(), foedus::fs::fsync(), has_parent_path(), foedus::fs::DirectIoFile::open(), and foedus::externalize::Externalizable::save_to_file().

55  {
56  size_t pos = pathname_.find_last_of(kPreferredSeparator);
57  if (pos == pathname_.size()) {
58  return Path();
59  } else {
60  return Path(pathname_.substr(0, pos));
61  }
62 }
static const char kPreferredSeparator
Definition: path.hpp:39

Here is the call graph for this function:

Here is the caller graph for this function:

bool foedus::fs::Path::root ( ) const
inline

Definition at line 74 of file path.hpp.

References kPreferredSeparator.

74 { return pathname_.size() == 1 && pathname_.at(0) == kPreferredSeparator; }
static const char kPreferredSeparator
Definition: path.hpp:39
const std::string& foedus::fs::Path::string ( ) const
inline

Definition at line 65 of file path.hpp.

Referenced by foedus::fs::operator<<(), Path(), and foedus::snapshot::DumpFileSortedBuffer::to_string().

65 { return pathname_; }

Here is the caller graph for this function:

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  o,
const Path v 
)
friend

Definition at line 84 of file path.cpp.

84  {
85  o << v.string();
86  return o;
87 }

Member Data Documentation

const char foedus::fs::Path::kPreferredSeparator = '/'
static

Definition at line 39 of file path.hpp.

Referenced by append_separator_if_needed(), filename(), parent_path(), Path(), and root().


The documentation for this class was generated from the following files: