30#include <boost/algorithm/string.hpp>
31#include <boost/filesystem.hpp>
35#include <unordered_set>
37namespace fs = boost::filesystem;
56 auto order_file = dir /
"order.txt";
58 if (fs::exists(order_file)) {
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";
83 for (fs::directory_iterator iter{dir}; iter != fs::directory_iterator{}; ++iter) {
84 if (ordered_names.count(iter->path().filename().string()) == 0) {
96 auto ordered_contents =
getOrder(dir);
97 for (
auto& name : ordered_contents) {
98 if (fs::is_directory(name)) {
100 result.insert(result.end(), sub_dir_contents.begin(), sub_dir_contents.end());
102 result.emplace_back(name);
122 if (!fs::exists(fspath)) {
123 throw Elements::Exception() <<
"From FileSystemProvider: root path not found : " << fspath;
127 if (fs::is_directory(fspath)) {
129 for (
const auto& file : dir_contents) {
130 if (fs::is_regular_file(file) &&
m_parser->isDatasetFile(file.string())) {
133 if (dataset_name.
empty()) {
141 boost::split(groups, str, boost::is_any_of(
"/"));
151 <<
"in the map. Qualify name : " << qualified_name.qualifiedName()
152 <<
" Path :" << file.string();
157 throw Elements::Exception() <<
" Root path : " << fspath.string() <<
" is not a directory!";
169 while (!my_group.
empty() && my_group.
back() ==
'/') {
174 if (!my_group.
empty() && pos != 0) {
175 my_group = my_group.
substr(pos);
177 if (!my_group.
empty()) {
187 if (boost::starts_with(qualified_name.qualifiedName(), my_group)) {
188 qualified_name_vector.
push_back(qualified_name);
192 return qualified_name_vector;
T back_inserter(T... args)
static Logging getLogger(const std::string &name="")
void warn(const std::string &logMessage)
std::vector< QualifiedName > m_order_names
std::vector< QualifiedName > listContents(const std::string &group) override
List all files which belong to a group.
std::string getParameter(const QualifiedName &qualified_name, const std::string &key_word) override
FileSystemProvider(const std::string &root_path, std::unique_ptr< FileParser > parser)
constructor The FileSystemProvider handles files in a directory tree.
std::unique_ptr< FileParser > m_parser
std::unique_ptr< XYDataset > getDataset(const QualifiedName &qualified_name) override
Get a dataset corresponding to an unique qualified name.
std::map< QualifiedName, std::string > m_name_file_map
Represents a name qualified with a set of groups.
This interface class provides the dataset following a qualified name object.
T find_first_not_of(T... args)
static std::vector< fs::path > getOrder(const fs::path &dir)
static Elements::Logging logger
static std::vector< fs::path > getRecursiveDirectoryContents(const fs::path &dir)
std::string checkEndSlashes(const std::string &input_str)