28 #include <unordered_set> 30 #include <boost/filesystem.hpp> 31 #include <boost/algorithm/string.hpp> 37 namespace fs = boost::filesystem;
52 static std::vector<fs::path>
getOrder(
const fs::path& dir) {
53 std::vector<fs::path> result {};
56 auto order_file = dir /
"order.txt";
57 std::unordered_set<std::string> ordered_names {};
58 if (fs::exists(order_file)) {
59 std::ifstream in {order_file.c_str()};
63 size_t comment_pos = line.find(
'#');
64 if (comment_pos != std::string::npos) {
65 line = line.substr(0, comment_pos);
69 auto name = dir / line;
70 if (fs::exists(name)) {
71 result.emplace_back(name);
72 ordered_names.emplace(line);
74 logger.
warn() <<
"Unknown name " << line <<
" in order.txt of " << dir <<
" directory";
82 std::set<fs::path> remaining_files {};
83 for (fs::directory_iterator iter {dir}; iter != fs::directory_iterator{}; ++ iter) {
84 if (ordered_names.count(iter->path().filename().string()) == 0) {
85 remaining_files.emplace(*iter);
90 for (
auto& file : remaining_files){
91 result.emplace_back(file);
99 std::vector<fs::path> result {};
100 auto ordered_contents =
getOrder(dir);
101 for (
auto& name : ordered_contents) {
102 if (fs::is_directory(name)) {
104 result.insert(result.end(), sub_dir_contents.begin(), sub_dir_contents.end());
106 result.emplace_back(name);
119 std::vector<std::string> string_vector{};
126 if (!fs::exists(fspath)) {
132 if (fs::is_directory(fspath)) {
134 for (
auto& file : dir_contents) {
135 if (fs::is_regular_file(file) &&
m_parser->isDatasetFile(file.string()))
137 std::string dataset_name =
m_parser->getName(file.string());
139 if (dataset_name.empty()) {
143 std::string str = file.string();
144 str = str.substr(
m_root_path.length(), str.length());
146 std::vector<std::string> groups {};
152 auto ret =
m_name_file_map.insert(make_pair(qualified_name, file.string()));
157 <<
"in the map. Qualify name : " 158 << qualified_name.qualifiedName()
159 <<
" Path :" << file.string();
165 throw Elements::Exception() <<
" Root path : " << fspath.string() <<
" is not a directory!";
176 std::string my_group = group;
178 while (!my_group.empty() && my_group.back() ==
'/') {
182 size_t pos = my_group.find_first_not_of(
"/");
183 if (!my_group.empty() && pos != 0) {
184 my_group = my_group.substr(pos);
186 if (!my_group.empty()) {
187 my_group.push_back(
'/');
190 std::vector<QualifiedName> qualified_name_vector{};
196 if (boost::starts_with(qualified_name.qualifiedName(), my_group)) {
197 qualified_name_vector.push_back(qualified_name);
201 return (qualified_name_vector);
std::vector< QualifiedName > listContents(const std::string &group) override
List all files which belong to a group.
ELEMENTS_API auto split(Args &&... args) -> decltype(splitPath(std::forward< Args >(args)...))
std::map< QualifiedName, std::string > m_name_file_map
std::string getParameter(const QualifiedName &qualified_name, const std::string &key_word) override
std::string checkEndSlashes(const std::string &input_str)
FileSystemProvider(const std::string &root_path, std::unique_ptr< FileParser > parser)
constructor The FileSystemProvider handles files in a directory tree.
static Elements::Logging logger
void warn(const std::string &logMessage)
std::unique_ptr< FileParser > m_parser
std::vector< QualifiedName > m_order_names
static std::vector< fs::path > getOrder(const fs::path &dir)
static std::vector< fs::path > getRecursiveDirectoryContents(const fs::path &dir)
This interface class provides the dataset following a qualified name object.
Represents a name qualified with a set of groups.
static Logging getLogger(const std::string &name="")
std::unique_ptr< XYDataset > getDataset(const QualifiedName &qualified_name) override
Get a dataset corresponding to an unique qualified name.