Skip to content

Commit 08f547d

Browse files
Remove "using namespace std" from all cpp files (#91)
1 parent effd0ea commit 08f547d

File tree

13 files changed

+446
-472
lines changed

13 files changed

+446
-472
lines changed

src/filepattern/cpp/external/external_filepattern.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#include "external_filepattern.hpp"
22

3-
using namespace std;
4-
5-
ExternalFilePattern::ExternalFilePattern(const string& path, const string& filePattern, const string& block_size, bool recursive, bool suppressWarnings, bool sorted):
3+
ExternalFilePattern::ExternalFilePattern(const std::string& path, const std::string& filePattern, const std::string& block_size, bool recursive, bool suppressWarnings, bool sorted):
64
ExternalPattern(path, block_size, recursive) {
75

86
this->setSuppressWarnings(suppressWarnings);
@@ -53,7 +51,7 @@ ExternalFilePattern::~ExternalFilePattern(){
5351

5452
void ExternalFilePattern::printFiles(){
5553

56-
vector<Tuple> files;
54+
std::vector<Tuple> files;
5755

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

6462
for(const auto& element: std::get<0>(file)){
65-
cout << element.first << ":" << s::to_string(element.second) << endl;
63+
std::cout << element.first << ":" << s::to_string(element.second) << std::endl;
6664
}
6765
for(const auto& element: std::get<1>(file)){
68-
cout << "file: " << element << endl;
66+
std::cout << "file: " << element << std::endl;
6967
}
70-
cout << endl;
68+
std::cout << std::endl;
7169
}
7270

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

9290
void ExternalFilePattern::matchFilesOneDir(){
93-
vector<string> block;
91+
std::vector<std::string> block;
9492

95-
regex pattern_regex = regex(this->getRegexFilePattern());
96-
string file;
97-
smatch sm;
93+
std::regex pattern_regex = std::regex(this->getRegexFilePattern());
94+
std::string file;
95+
std::smatch sm;
9896

9997
// iterate over files
10098
while(!this->stream_.isEmpty()){

src/filepattern/cpp/external/external_pattern.cpp

Lines changed: 76 additions & 78 deletions
Large diffs are not rendered by default.

src/filepattern/cpp/external/external_stringpattern.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#include "external_stringpattern.hpp"
22

3-
using namespace std;
4-
5-
ExternalStringPattern::ExternalStringPattern(const string& path, const string& file_pattern, const string& block_size, bool suppress_warnings, bool sorted):
3+
ExternalStringPattern::ExternalStringPattern(const std::string& path, const std::string& file_pattern, const std::string& block_size, bool suppress_warnings, bool sorted):
64
ExternalPattern(path, block_size, false) {
75
this->setSuppressWarnings(suppress_warnings);
86
this->setPath(path); // store path to target directory
@@ -43,11 +41,11 @@ void ExternalStringPattern::matchFiles(){
4341

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

46-
vector<string> block;
44+
std::vector<std::string> block;
4745

48-
regex pattern_regex = regex(this->getRegexFilePattern());
49-
string file;
50-
smatch sm;
46+
std::regex pattern_regex = std::regex(this->getRegexFilePattern());
47+
std::string file;
48+
std::smatch sm;
5149

5250
// iterate over files
5351
while(!this->stream_.isEmpty()){

src/filepattern/cpp/external/external_vectorpattern.cpp

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
#include "external_vectorpattern.hpp"
22

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

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

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

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

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

48-
this->setRegexExpression(regex(this->getRegexFilePattern()));
46+
this->setRegexExpression(std::regex(this->getRegexFilePattern()));
4947

50-
string line, file;
48+
std::string line, file;
5149
Tuple temp;
52-
smatch sm;
50+
std::smatch sm;
5351

54-
while(getline(this->vector_reader_, line)){
52+
while(std::getline(this->vector_reader_, line)){
5553
file = VectorParser::getFileName(line);
5654
if(regex_match(file, sm, this->getRegexExpression())){
5755
temp = getVariableMap(file, sm);
@@ -62,17 +60,17 @@ void ExternalVectorPattern::matchFiles(){
6260
this->vector_reader_.close();
6361
}
6462

65-
string ExternalVectorPattern::inferPattern(const string& path, string& variables, const string& block_size){
63+
std::string ExternalVectorPattern::inferPattern(const std::string& path, std::string& variables, const std::string& block_size){
6664

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

69-
vector<string> files;
70-
string file;
71-
ifstream infile(path);
67+
std::vector<std::string> files;
68+
std::string file;
69+
std::ifstream infile(path);
7270

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

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

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

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

8684
if(size >= block) {
8785
pattern = inferPatternInternal(files, variables, pattern);
88-
size = sizeof(vector<string>) + sizeof(vector<vector<int>>);
86+
size = sizeof(std::vector<std::string>) + sizeof(std::vector<std::vector<int>>);
8987
files.clear();
9088
}
9189
}

src/filepattern/cpp/internal/filepattern.cpp

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
#include "../util/util.hpp"
33
#include <chrono>
44

5-
using namespace std;
6-
7-
FilePatternObject::FilePatternObject(const string& path, const string& file_pattern, bool recursive, bool suppress_warnings, bool sorted) {
5+
FilePatternObject::FilePatternObject(const std::string& path, const std::string& file_pattern, bool recursive, bool suppress_warnings, bool sorted) {
86

97
this->setSuppressWarnings(suppress_warnings);
108

@@ -17,7 +15,7 @@ FilePatternObject::FilePatternObject(const string& path, const string& file_patt
1715
this->recursive_ = true;
1816
this->setJustPath(true);
1917
} catch (const std::runtime_error& e) {
20-
string error = "No directory found. Invalid path \"" + path + "\".";
18+
std::string error = "No directory found. Invalid path \"" + path + "\".";
2119
throw std::runtime_error(error);
2220
}
2321

@@ -46,7 +44,7 @@ FilePatternObject::FilePatternObject(const string& path, const string& file_patt
4644
this->iterator_ = fs::directory_iterator(fs::path(this->getPath())); // store iterator for target directory
4745
}
4846
} catch (const std::runtime_error& e) {
49-
string error = "No directory found. Invalid path \"" + path + "\".";
47+
std::string error = "No directory found. Invalid path \"" + path + "\".";
5048
throw std::runtime_error(error);
5149
}
5250
}
@@ -64,10 +62,10 @@ FilePatternObject::FilePatternObject(const string& path, const string& file_patt
6462
void FilePatternObject::matchFilesOneDir(){
6563

6664
Map mapping;
67-
vector<string> parsed_regex;
65+
std::vector<std::string> parsed_regex;
6866

69-
string s;
70-
string file, file_path;
67+
std::string s;
68+
std::string file, file_path;
7169
Tuple member;
7270
// Iterate over every file in directory
7371

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

82-
regex pattern_regex = regex(this->getRegexFilePattern());
83-
smatch sm;
80+
std::regex pattern_regex = std::regex(this->getRegexFilePattern());
81+
std::smatch sm;
8482

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

9795
void FilePatternObject::matchFilesMultDir(){
9896

99-
regex pattern_regex = regex(this->getRegexFilePattern());
97+
std::regex pattern_regex = std::regex(this->getRegexFilePattern());
10098

10199
Tuple tup;
102-
smatch sm;
103-
string file, file_path;
100+
std::smatch sm;
101+
std::string file, file_path;
104102

105103
bool is_pushed = false;
106104

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

128-
if(get<0>(tup).size() > 0){
126+
if(std::get<0>(tup).size() > 0){
129127
this->valid_files_.push_back(tup);
130128
is_pushed = true;
131129
} else {
@@ -134,7 +132,7 @@ void FilePatternObject::matchFilesMultDir(){
134132
}
135133
}
136134

137-
if (!is_pushed && get<1>(tup).size() > 0) {
135+
if (!is_pushed && std::get<1>(tup).size() > 0) {
138136
this->valid_files_.push_back(tup);
139137
}
140138
}

0 commit comments

Comments
 (0)