Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions src/filepattern/cpp/external/external_filepattern.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#include "external_filepattern.hpp"

using namespace std;

ExternalFilePattern::ExternalFilePattern(const string& path, const string& filePattern, const string& block_size, bool recursive, bool suppressWarnings, bool sorted):
ExternalFilePattern::ExternalFilePattern(const std::string& path, const std::string& filePattern, const std::string& block_size, bool recursive, bool suppressWarnings, bool sorted):
ExternalPattern(path, block_size, recursive) {

this->setSuppressWarnings(suppressWarnings);
Expand Down Expand Up @@ -53,7 +51,7 @@ ExternalFilePattern::~ExternalFilePattern(){

void ExternalFilePattern::printFiles(){

vector<Tuple> files;
std::vector<Tuple> files;

while(true){
files = this->stream_.getValidFilesBlock();
Expand All @@ -62,12 +60,12 @@ void ExternalFilePattern::printFiles(){
if(std::get<0>(file).size() < this->stream_.map_size_) continue;

for(const auto& element: std::get<0>(file)){
cout << element.first << ":" << s::to_string(element.second) << endl;
std::cout << element.first << ":" << s::to_string(element.second) << std::endl;
}
for(const auto& element: std::get<1>(file)){
cout << "file: " << element << endl;
std::cout << "file: " << element << std::endl;
}
cout << endl;
std::cout << std::endl;
}

if (this->stream_.endOfValidFiles()) break;
Expand All @@ -90,11 +88,11 @@ void ExternalFilePattern::matchFiles() {
}

void ExternalFilePattern::matchFilesOneDir(){
vector<string> block;
std::vector<std::string> block;

regex pattern_regex = regex(this->getRegexFilePattern());
string file;
smatch sm;
std::regex pattern_regex = std::regex(this->getRegexFilePattern());
std::string file;
std::smatch sm;

// iterate over files
while(!this->stream_.isEmpty()){
Expand Down
154 changes: 76 additions & 78 deletions src/filepattern/cpp/external/external_pattern.cpp

Large diffs are not rendered by default.

12 changes: 5 additions & 7 deletions src/filepattern/cpp/external/external_stringpattern.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#include "external_stringpattern.hpp"

using namespace std;

ExternalStringPattern::ExternalStringPattern(const string& path, const string& file_pattern, const string& block_size, bool suppress_warnings, bool sorted):
ExternalStringPattern::ExternalStringPattern(const std::string& path, const std::string& file_pattern, const std::string& block_size, bool suppress_warnings, bool sorted):
ExternalPattern(path, block_size, false) {
this->setSuppressWarnings(suppress_warnings);
this->setPath(path); // store path to target directory
Expand Down Expand Up @@ -43,11 +41,11 @@ void ExternalStringPattern::matchFiles(){

this->setMapSize(this->variables_.size());

vector<string> block;
std::vector<std::string> block;

regex pattern_regex = regex(this->getRegexFilePattern());
string file;
smatch sm;
std::regex pattern_regex = std::regex(this->getRegexFilePattern());
std::string file;
std::smatch sm;

// iterate over files
while(!this->stream_.isEmpty()){
Expand Down
30 changes: 14 additions & 16 deletions src/filepattern/cpp/external/external_vectorpattern.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
#include "external_vectorpattern.hpp"

using namespace std;

const std::regex ExternalVectorPattern::STITCH_REGEX_ = std::regex("(corr): (.*); (position): \\((.*), (.*)\\); (grid): \\((.*), (.*)\\);"); // regex of a stitching vector line
const std::vector<std::regex> ExternalVectorPattern::STITCH_REGEX_VECTOR_ = {std::regex("(corr):\\s*(.*?);"), std::regex("(position):\\s*\\((.*?),\\s*(.*?)\\);"), std::regex("(grid):\\s*\\((.*),\\s*(.*)\\);")};
const std::vector<std::string> ExternalVectorPattern::STITCH_VARIABLES_ = {"correlation","posX","posY","gridX","gridY"}; // stitching vector variables

ExternalVectorPattern::ExternalVectorPattern(const string& path, const string& file_pattern, const string& block_size, bool suppress_warnings, bool sorted):
ExternalVectorPattern::ExternalVectorPattern(const std::string& path, const std::string& file_pattern, const std::string& block_size, bool suppress_warnings, bool sorted):
ExternalPattern(path, block_size, false){
this->setSuppressWarnings(suppress_warnings);
this->path_ = path; // store path to target directory
Expand All @@ -15,7 +13,7 @@ ExternalPattern(path, block_size, false){
this->setBlockSize(Block::parseblockSize(block_size));

this->vector_reader_.open(path);
if(!this->vector_reader_.is_open()) throw invalid_argument("Invalid path \"" + path + "\".");
if(!this->vector_reader_.is_open()) throw std::invalid_argument("Invalid path \"" + path + "\".");

this->setFilePattern(file_pattern); // cast input string to regex
this->setRegexFilePattern(""); // Regex version of pattern
Expand Down Expand Up @@ -45,13 +43,13 @@ void ExternalVectorPattern::matchFiles(){

this->setMapSize(this->variables_.size() + this->STITCH_VARIABLES_.size()); // Change the size of the map to include stitching variables

this->setRegexExpression(regex(this->getRegexFilePattern()));
this->setRegexExpression(std::regex(this->getRegexFilePattern()));

string line, file;
std::string line, file;
Tuple temp;
smatch sm;
std::smatch sm;

while(getline(this->vector_reader_, line)){
while(std::getline(this->vector_reader_, line)){
file = VectorParser::getFileName(line);
if(regex_match(file, sm, this->getRegexExpression())){
temp = getVariableMap(file, sm);
Expand All @@ -62,17 +60,17 @@ void ExternalVectorPattern::matchFiles(){
this->vector_reader_.close();
}

string ExternalVectorPattern::inferPattern(const string& path, string& variables, const string& block_size){
std::string ExternalVectorPattern::inferPattern(const std::string& path, std::string& variables, const std::string& block_size){

long block = Block::parseblockSize(block_size); // parse string

vector<string> files;
string file;
ifstream infile(path);
std::vector<std::string> files;
std::string file;
std::ifstream infile(path);

long size = sizeof(vector<string>) + sizeof(vector<vector<int>>); // memory footprint
long size = sizeof(std::vector<std::string>) + sizeof(std::vector<std::vector<int>>); // memory footprint

string pattern = "";
std::string pattern = "";
// while the stitching vector contains another line:
// get block of file from stitching vector and call internal memory version of infer pattern on the block
while(getline(infile, file)){
Expand All @@ -81,11 +79,11 @@ string ExternalVectorPattern::inferPattern(const string& path, string& variables

files.push_back(s::escape_regex_characters(file));

size += sizeof(string) + file.length() + sizeof(int)*2*file.length(); // account for size of filenames
size += sizeof(std::string) + file.length() + sizeof(int)*2*file.length(); // account for size of filenames

if(size >= block) {
pattern = inferPatternInternal(files, variables, pattern);
size = sizeof(vector<string>) + sizeof(vector<vector<int>>);
size = sizeof(std::vector<std::string>) + sizeof(std::vector<std::vector<int>>);
files.clear();
}
}
Expand Down
30 changes: 14 additions & 16 deletions src/filepattern/cpp/internal/filepattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
#include "../util/util.hpp"
#include <chrono>

using namespace std;

FilePatternObject::FilePatternObject(const string& path, const string& file_pattern, bool recursive, bool suppress_warnings, bool sorted) {
FilePatternObject::FilePatternObject(const std::string& path, const std::string& file_pattern, bool recursive, bool suppress_warnings, bool sorted) {

this->setSuppressWarnings(suppress_warnings);

Expand All @@ -17,7 +15,7 @@ FilePatternObject::FilePatternObject(const string& path, const string& file_patt
this->recursive_ = true;
this->setJustPath(true);
} catch (const std::runtime_error& e) {
string error = "No directory found. Invalid path \"" + path + "\".";
std::string error = "No directory found. Invalid path \"" + path + "\".";
throw std::runtime_error(error);
}

Expand Down Expand Up @@ -46,7 +44,7 @@ FilePatternObject::FilePatternObject(const string& path, const string& file_patt
this->iterator_ = fs::directory_iterator(fs::path(this->getPath())); // store iterator for target directory
}
} catch (const std::runtime_error& e) {
string error = "No directory found. Invalid path \"" + path + "\".";
std::string error = "No directory found. Invalid path \"" + path + "\".";
throw std::runtime_error(error);
}
}
Expand All @@ -64,10 +62,10 @@ FilePatternObject::FilePatternObject(const string& path, const string& file_patt
void FilePatternObject::matchFilesOneDir(){

Map mapping;
vector<string> parsed_regex;
std::vector<std::string> parsed_regex;

string s;
string file, file_path;
std::string s;
std::string file, file_path;
Tuple member;
// Iterate over every file in directory

Expand All @@ -76,11 +74,11 @@ void FilePatternObject::matchFilesOneDir(){
auto start = this->getRegexFilePattern().find('{');
auto end = this->getRegexFilePattern().find('}');
auto length = end - start;
throw invalid_argument("Invalid pattern found in bracket expressions in filepattern: \"" + this->getRegexFilePattern().substr(start, length+1) + "\"");
throw std::invalid_argument("Invalid pattern found in bracket expressions in filepattern: \"" + this->getRegexFilePattern().substr(start, length+1) + "\"");
}

regex pattern_regex = regex(this->getRegexFilePattern());
smatch sm;
std::regex pattern_regex = std::regex(this->getRegexFilePattern());
std::smatch sm;

for (const auto& entry : this->iterator_) {
// Get the current file
Expand All @@ -96,11 +94,11 @@ void FilePatternObject::matchFilesOneDir(){

void FilePatternObject::matchFilesMultDir(){

regex pattern_regex = regex(this->getRegexFilePattern());
std::regex pattern_regex = std::regex(this->getRegexFilePattern());

Tuple tup;
smatch sm;
string file, file_path;
std::smatch sm;
std::string file, file_path;

bool is_pushed = false;

Expand All @@ -125,7 +123,7 @@ void FilePatternObject::matchFilesMultDir(){
tup = getVariableMapMultDir(file_path, sm);
}

if(get<0>(tup).size() > 0){
if(std::get<0>(tup).size() > 0){
this->valid_files_.push_back(tup);
is_pushed = true;
} else {
Expand All @@ -134,7 +132,7 @@ void FilePatternObject::matchFilesMultDir(){
}
}

if (!is_pushed && get<1>(tup).size() > 0) {
if (!is_pushed && std::get<1>(tup).size() > 0) {
this->valid_files_.push_back(tup);
}
}
Expand Down
Loading
Loading