Browse Source

Finish namespace removal and add directory content functionality

merge-requests/365/head
Jørgen Lien Sellæg 10 years ago
parent
commit
c086052188
  1. 35
      src/filesystem.cc
  2. 18
      src/filesystem.h

35
src/filesystem.cc

@ -169,3 +169,38 @@ bool filesystem::write(const std::string &path, Glib::RefPtr<Gtk::TextBuffer> bu
}
return false;
}
std::vector<boost::filesystem::path> filesystem::get_directory_content(const boost::filesystem::path &path, int filter) {
std::vector<boost::filesystem::path> dirs;
if (boost::filesystem::is_directory(path)) {
for (boost::filesystem::directory_iterator it(path); it != boost::filesystem::directory_iterator(); it++) {
if (filter & DIRS && boost::filesystem::is_directory(it->path()))
dirs.emplace_back(it->path());
if (filter & FILES && boost::filesystem::is_regular_file(it->path()))
dirs.emplace_back(it->path());
}
}
if (filter & SORTED)
std::sort(dirs.begin(), dirs.end());
return dirs;
};
std::vector<boost::filesystem::path> filesystem::dirs(const boost::filesystem::path &path) {
return filesystem::get_directory_content(path, DIRS | SORTED);
}
std::vector<boost::filesystem::path> filesystem::files(const boost::filesystem::path &path) {
return filesystem::get_directory_content(path, FILES | SORTED);
}
std::vector<boost::filesystem::path> filesystem::contents(const boost::filesystem::path &path) {
return filesystem::get_directory_content(path, ALL | SORTED);
}
std::vector<boost::filesystem::path> filesystem::seperate_contents(const boost::filesystem::path &path) {
auto a = dirs(path);
auto b = files(path);
a.insert(a.end(), b.begin(), b.end());
return a;
}

18
src/filesystem.h

@ -5,13 +5,12 @@
#include <boost/filesystem.hpp>
#include <gtkmm.h>
namespace juci {
class filesystem {
public:
static std::string read(const std::string &path);
static std::string read(const boost::filesystem::path &path) { return read(path.string()); }
static int read(const std::string &path, Glib::RefPtr<Gtk::TextBuffer> text_buffer);
static int read(const boost::filesystem::path &path, Glib::RefPtr<Gtk::TextBuffer> text_buffer) { return read(path.string(), text_buffer); }
enum filesystem_options {
DIRS = 1,
FILES = 2,
ALL = DIRS | FILES,
SORTED = 4
};
class filesystem {
public:
@ -32,6 +31,11 @@ public:
static bool write(const boost::filesystem::path &path) { return write(path, ""); };
static bool write(const std::string &path, Glib::RefPtr<Gtk::TextBuffer> text_buffer);
static bool write(const boost::filesystem::path &path, Glib::RefPtr<Gtk::TextBuffer> text_buffer) { return write(path.string(), text_buffer); }
static std::vector<boost::filesystem::path> get_directory_content(const boost::filesystem::path &path, int filter);
static std::vector<boost::filesystem::path> dirs(const boost::filesystem::path &path);
static std::vector<boost::filesystem::path> files(const boost::filesystem::path &path);
static std::vector<boost::filesystem::path> contents(const boost::filesystem::path &path);
static std::vector<boost::filesystem::path> seperate_contents(const boost::filesystem::path &path);
static std::string get_home_folder();
static std::string get_tmp_folder();

Loading…
Cancel
Save