iash  v0.5
Library to provide a bash-like shell in an application
Directory.h
1 /*
2  * Directory.h
3  *
4  * Created on: Oct 30, 2016
5  * Author: paul
6  */
7 
8 #ifndef SRC_DIRECTORY_H_
9 #define SRC_DIRECTORY_H_
10 
11 #include <string>
12 #include <exception>
13 #include <stdexcept>
14 
26 class Directory {
27 public:
34  Directory();
35 
41  Directory(const std::string &dir);
42  virtual ~Directory();
43 
44  //INSTANCE FUNCTIONS *******************************************************
50  bool isValid () const;
51 
57  const std::string& getAbsPath () const;
58 
67  bool changeDirRel (const std::string &relPath);
68 
76  bool changeDirAbs (const std::string &absPath);
77 
85  std::string resolvePath (const std::string &relpath) const;
86 
94  int mkSubdir (const std::string &dirName) const;
95 
104  bool dirExists (const std::string &dirName) const;
105 
114  bool fileExists (const std::string &filename) const;
115 
116  //STATIC FUNCTIONS *********************************************************
124  static int mkdir (const char *pathname);
125 
133  static bool isDir (const char *pathname);
134 
142  static bool isFile (const char *pathname);
143 
151  static std::string toIash (const std::string &pathname);
152 
160  static std::string toPlatform (const std::string &pathname);
161 
167  static Directory getHomeDir ();
168 
176  static Directory getConfigDir ();
177 
185  static Directory getWorkingDir ();
186 private:
187  void ensureTrailingSlash ();
188 
189  std::string m_dirpath;
190  bool m_valid;
191 };
192 
197 class FileNotFoundException : public std::runtime_error {
198 public:
202  FileNotFoundException(const std::string &fname);
203 };
204 
205 #endif /* SRC_DIRECTORY_H_ */
bool fileExists(const std::string &filename) const
Checks if the given filename represents an existing file inside of the current Directory.
Definition: Directory.cpp:84
static Directory getHomeDir()
Gets the user&#39;s home directory as a Directory instance.
Definition: Directory.cpp:217
Represents a directory on the filesystem.
Definition: Directory.h:26
static std::string toPlatform(const std::string &pathname)
Converts pathname from iash path representation to the platform&#39;s path representation.
Definition: Directory.cpp:106
const std::string & getAbsPath() const
Gets the absolute path to this Directory from the root of the filesystem.
Definition: Directory.cpp:51
static Directory getConfigDir()
Gets the user&#39;s root application configuration directory ad a Directory instance. ...
Definition: Directory.cpp:226
int mkSubdir(const std::string &dirName) const
Creates a directory inside of the current Directory instance.
Definition: Directory.cpp:74
bool changeDirAbs(const std::string &absPath)
Changes this Directory instance to point at the directory with the absolute path absPath.
Definition: Directory.cpp:63
static Directory getWorkingDir()
Gets the working directory for this process.
Definition: Directory.cpp:245
static std::string toIash(const std::string &pathname)
Converts pathname from system path representation to iash path representation.
Definition: Directory.cpp:89
static bool isFile(const char *pathname)
Checks if pathname refers to an existing file.
Definition: Directory.cpp:202
bool changeDirRel(const std::string &relPath)
Changes this Directory instance to point at the directory with path relPath relative to the directory...
Definition: Directory.cpp:56
bool isValid() const
Checks if the Directory object points to an existing directory.
Definition: Directory.cpp:46
static bool isDir(const char *pathname)
Checks if pathname refers to an existing directory.
Definition: Directory.cpp:187
static int mkdir(const char *pathname)
Creates a directory with the absolute path pathname.
Definition: Directory.cpp:178
bool dirExists(const std::string &dirName) const
Checks if the given dirname represents an existing directory inside of the current Directory...
Definition: Directory.cpp:79
std::string resolvePath(const std::string &relpath) const
Converts a path relative to the current Directory to an absolute path.
Definition: Directory.cpp:123
Thrown when an iash component cannot find the requested file.
Definition: Directory.h:197
Directory()
Creates a Directory instance pointed at the application&#39;s current working directory.
Definition: Directory.cpp:25