forked from PolusAI/filepattern
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpattern_object.hpp
More file actions
101 lines (65 loc) · 3.71 KB
/
Copy pathpattern_object.hpp
File metadata and controls
101 lines (65 loc) · 3.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#pragma once
#include<map>
#include <set>
#include<string>
#include <tuple>
#include<variant>
#include<vector>
#if __has_include(<filesystem>)
#include <filesystem>
namespace fs = std::filesystem;
#elif __has_include(<experimental/filesystem>)
#include <experimental/filesystem>
namespace fs = std::experimental::filesystem;
#else
error "Missing the <filesystem> header."
#endif
using Types = std::variant<int, std::string, double>;
using Map = std::map<std::string, Types>;
#ifdef JAVA_BINDING
using Tuple = std::tuple<Map, std::vector<std::string>>;
#else
using Tuple = std::tuple<Map, std::vector<fs::path>>;
#endif
class PatternObject {
public:
bool external = false;
std::vector<Tuple> valid_files_; // Store files that match given regex
std::string path_;
std::string file_pattern_;
std::vector<std::pair<std::vector<std::pair<std::string, Types>> , std::vector<Tuple>>> valid_grouped_files_; // 2D vector to store grouped files
std::vector<std::string> group_; // current groupBy variable
std::vector<std::string> variables_; // Store the names of variables from the pattern
std::map<std::string, std::map<Types, int>> variable_occurrences_; // store the number of times a variable value occurs
std::map<std::string, std::set<Types>> unique_values_; // store each unique value for every variable
std::vector<std::string> named_groups_;
std::vector<std::string> tmp_directories_; // store paths to all temporary directories used
std::vector<Tuple> current_block_; // Store current block of files
//std::vector<std::pair<std::pair<std::string, Types>, std::vector<Tuple>>> currentGroup; //Store current block of grouped files
std::vector<std::pair<std::vector<std::pair<std::string, Types>> , std::vector<Tuple>>> current_group_;
virtual ~PatternObject() {}
virtual std::vector<Tuple> getMatching(const std::vector<std::tuple<std::string, std::vector<Types>>>& variables) = 0;
virtual void groupBy(std::vector<std::string>& groups) = 0;
virtual std::map<std::string, std::map<Types, int>> getOccurrences(const std::vector<std::tuple<std::string, std::vector<Types>>>& mapping) = 0;
virtual std::map<std::string, std::set<Types>> getUniqueValues(const std::vector<std::string>& mapping) = 0;
virtual std::string outputName(std::vector<Tuple>& vec) = 0;
virtual std::vector<std::string> getVariables() = 0;
//virtual void getNewNaming(std::string& pattern, bool suppressWarnings) = 0;
virtual void next() = 0;
virtual void nextGroup() = 0;
virtual int currentBlockLength() = 0;
virtual void setGroup(const std::vector<std::string>& groups) = 0;
virtual std::vector<Tuple> getSlice(std::vector<Types>& key) = 0;
virtual std::string inferPattern(const std::string& path, std::string& variables, const std::string& block_size) = 0;
virtual std::string inferPattern(std::vector<std::string>& vec, std::string& variables) = 0;
virtual std::vector<Tuple> getMatchingBlock() = 0;
virtual Tuple getItem(unsigned int key) = 0;
virtual std::vector<Tuple> getItemList(std::vector<int>& key) = 0;
size_t length() const {return valid_files_.size();};
const std::pair<std::vector<std::pair<std::string, Types>> , std::vector<Tuple>>& get_grouped_file_by_idx(unsigned int idx) {
if (idx < 0 || idx >= this->valid_grouped_files_.size()) {
throw std::out_of_range("Invalid index " + std::to_string(idx) + " for file vector size of " + std::to_string(valid_grouped_files_.size()));
}
return valid_grouped_files_[idx];
}
};