2019-01-03 18:01:43 +00:00
|
|
|
#ifndef FSLIB_H
|
|
|
|
#define FSLIB_H
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
namespace FSLib{
|
2019-01-04 19:19:08 +00:00
|
|
|
bool exists(const std::string &path);
|
|
|
|
bool isDirectory(const std::string &path);
|
|
|
|
std::string canonical(const std::string &path);
|
|
|
|
bool rename(const std::string &file_a, const std::string &file_b);
|
|
|
|
|
|
|
|
class Directory {
|
|
|
|
public:
|
|
|
|
Directory(const std::string &path_) : dir_path(path_) {}
|
|
|
|
Directory() = delete;
|
|
|
|
Directory(const Directory &d) = default;
|
|
|
|
Directory(Directory &&d) = default;
|
|
|
|
|
|
|
|
class Iterator {
|
|
|
|
public:
|
|
|
|
Iterator( const Directory &d_ ) : d(opendir(d_.path())) {
|
|
|
|
current_entry = readdir(d);
|
|
|
|
}
|
|
|
|
|
|
|
|
Iterator( const Directory &d_, const struct dirent *current_entry_) : d(opendir(d_.path())), current_entry(current_entry_) {}
|
|
|
|
|
|
|
|
Iterator() = delete;
|
|
|
|
|
|
|
|
Iterator(const Iterator &i) = default;
|
|
|
|
|
|
|
|
Iterator(Iterator &&i) = default;
|
|
|
|
|
|
|
|
~Iterator() {
|
|
|
|
closedir(d);
|
|
|
|
}
|
|
|
|
|
2019-01-07 21:21:02 +00:00
|
|
|
char const *operator*() const;
|
2019-01-04 19:19:08 +00:00
|
|
|
|
2019-01-06 19:40:16 +00:00
|
|
|
Iterator &operator++();
|
2019-01-04 19:19:08 +00:00
|
|
|
|
2019-01-06 19:40:16 +00:00
|
|
|
Iterator operator++(int);
|
2019-01-04 19:19:08 +00:00
|
|
|
|
2019-01-07 21:21:02 +00:00
|
|
|
bool operator==(const Iterator &i_other) const;
|
2019-01-04 19:19:08 +00:00
|
|
|
|
2019-01-07 21:21:02 +00:00
|
|
|
bool operator!=(const Iterator &i_other) const;
|
2019-01-04 19:19:08 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
DIR *d;
|
|
|
|
const struct dirent *current_entry;
|
|
|
|
};
|
|
|
|
|
|
|
|
using iterator = Iterator;
|
|
|
|
using const_iterator = Iterator;
|
|
|
|
|
2019-01-06 19:40:16 +00:00
|
|
|
iterator begin();
|
|
|
|
|
|
|
|
const_iterator begin() const;
|
2019-01-04 19:19:08 +00:00
|
|
|
|
2019-01-06 19:40:16 +00:00
|
|
|
const_iterator cbegin() const;
|
2019-01-04 19:19:08 +00:00
|
|
|
|
2019-01-06 19:40:16 +00:00
|
|
|
iterator end();
|
2019-01-04 19:19:08 +00:00
|
|
|
|
2019-01-06 19:40:16 +00:00
|
|
|
const_iterator end() const;
|
2019-01-04 19:19:08 +00:00
|
|
|
|
2019-01-06 19:40:16 +00:00
|
|
|
const_iterator cend() const;
|
2019-01-04 19:19:08 +00:00
|
|
|
|
2019-01-06 19:40:16 +00:00
|
|
|
const char *path() const;
|
2019-01-04 19:19:08 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
std::string dir_path;
|
|
|
|
};
|
2019-01-03 18:01:43 +00:00
|
|
|
} //end FSLib
|
|
|
|
|
|
|
|
#endif
|