30 #include <boost/algorithm/string.hpp>
31 #include <boost/filesystem.hpp>
35 #include <unordered_set>
37 namespace 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) {
90 for (
auto& file : remaining_files) {
91 result.emplace_back(file);
99 auto ordered_contents =
getOrder(dir);
100 for (
auto& name : ordered_contents) {
101 if (fs::is_directory(name)) {
103 result.insert(result.end(), sub_dir_contents.begin(), sub_dir_contents.end());
105 result.emplace_back(name);
125 if (!fs::exists(fspath)) {
126 throw Elements::Exception() <<
"From FileSystemProvider: root path not found : " << fspath;
130 if (fs::is_directory(fspath)) {
132 for (
auto& file : dir_contents) {
133 if (fs::is_regular_file(file) &&
m_parser->isDatasetFile(file.string())) {
136 if (dataset_name.
empty()) {
149 auto ret =
m_name_file_map.insert(make_pair(qualified_name, file.string()));
154 <<
"in the map. Qualify name : " << qualified_name.qualifiedName()
155 <<
" Path :" << file.string();
160 throw Elements::Exception() <<
" Root path : " << fspath.string() <<
" is not a directory!";
172 while (!my_group.
empty() && my_group.
back() ==
'/') {
177 if (!my_group.
empty() && pos != 0) {
178 my_group = my_group.
substr(pos);
180 if (!my_group.
empty()) {
190 if (boost::starts_with(qualified_name.qualifiedName(), my_group)) {
191 qualified_name_vector.
push_back(qualified_name);
195 return (qualified_name_vector);
T find_first_not_of(T...args)
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.