-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
update C++ codebase for handling of feature dependencies [vcs: #minor] #334
Changes from 60 commits
0e6dbcd
5cc3c5e
2a84582
84626df
954613a
e9cbcc8
443e083
f11e36d
108ca85
71f687d
2ba460d
3748628
9fa5fa4
f07895b
655cd03
34cfb4d
b8f629a
d91d476
9172cc7
8ed52a8
786f636
6a80aeb
cf52d1d
1abfbac
32eb094
13c21f6
9ad88fd
4de7876
3c86f4e
4d36018
65e8f60
d0084a3
84b3020
841f2b3
ffd9d03
90a5dc6
749e002
932b1b1
35a8450
0510877
378c278
8ded463
a21b653
f3b3a73
4e6514b
f7425b8
d1101d9
a4335ec
bde76af
d6848c3
3ca2801
9b9d382
d5d5ed7
e7907c8
e790e16
f3adcc3
83a57b1
444bfe7
5a5c22d
d7c576f
944140a
b3a33f3
1253dd3
5784c06
c101450
2ff86ed
267220d
9e9286f
241a2d7
46007d2
818e3a1
f778c6a
eebc16e
31b7212
4c1aae3
d287792
7a2594d
133a48e
cc4f705
c02f4c9
df224bd
c7ff80a
082f205
c7a4cc9
5f8881b
b6940d1
87cc375
41b087e
f39e7eb
489c247
c6033de
2682494
43bf8b3
bc15caa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,3 +21,4 @@ bin | |
*.ipynb_checkpoints | ||
lib | ||
fllog.txt | ||
.DS_STORE |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,40 +18,31 @@ | |
|
||
#include "DependencyTree.h" | ||
|
||
#include <algorithm> //remove | ||
#include <cctype> //isspace | ||
#include <algorithm> //remove | ||
#include <cctype> //isspace | ||
#include <fstream> | ||
|
||
static void removeAllWhiteSpace(string &str) { | ||
str.erase(std::remove_if(str.begin(), str.end(), isspace), str.end()); | ||
} | ||
|
||
cTree::cTree(const char *strFileName) { | ||
std::string line; | ||
|
||
std::ifstream input(strFileName); | ||
if (input.is_open()) { | ||
|
||
std::getline(input, line); | ||
if (!input) { | ||
ErrorStr += "\nCould not open the file " + string(strFileName); | ||
return; | ||
} | ||
|
||
for (string line; std::getline(input, line);) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wow, so this allows us to skip all the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The difference is due to the range based for loop vs while loop. While loop requires those conditions to figure out how long to run. The use of range based for loop is the same in the docs. // read file line by line
std::istringstream input;
input.str("1\n2\n3\n4\n5\n6\n7\n");
int sum = 0;
for (std::string line; std::getline(input, line);)
sum += std::stoi(line);
std::cout << "\nThe sum is " << sum << ".\n\n";
https://en.cppreference.com/w/cpp/string/basic_string/getline There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. great, thanks for the explanation |
||
removeAllWhiteSpace(line); | ||
if (!line.empty()) | ||
strDependencyFile.push_back(line); | ||
while (!(input.fail() || input.eof())) { | ||
std::getline(input, line); | ||
removeAllWhiteSpace(line); | ||
if (!line.empty()) | ||
strDependencyFile.push_back(line); | ||
if (!line.empty()) { | ||
strDependencyFile.push_back(std::move(line)); | ||
} | ||
} else { | ||
ErrorStr = ErrorStr + string("\nCould not open the file ") + strFileName; | ||
} | ||
|
||
getAllParents(vecFeature); | ||
} | ||
int cTree::getDependencyList(string) { | ||
for (unsigned i = 0; i < strDependencyFile.size(); i++) { | ||
} | ||
return 1; | ||
} | ||
|
||
/** | ||
* | ||
|
@@ -61,33 +52,31 @@ int cTree::getDependencyList(string) { | |
* FptrTable : | ||
* FptrLookup | vector of pairs: | ||
* first | string: feature name | ||
* second | vector of featureStringPair | ||
* second | vector of feature_function to represent list of | ||
* dependent features | ||
* | ||
*/ | ||
int cTree::setFeaturePointers(map<string, feature2function *> &mapFptrLib, | ||
feature2function *FptrTable, | ||
map<string, vector<featureStringPair > > *FptrLookup) | ||
{ | ||
int cTree::setFeaturePointers( | ||
map<string, feature2function *> &mapFptrLib, feature2function *FptrTable, | ||
map<string, vector<feature_function> > *FptrLookup) { | ||
list<string>::iterator lstItr; | ||
map<string, feature2function *>::iterator mapLibItr; | ||
feature2function *fptrTbl; | ||
feature2function::iterator mapFeatureItr; | ||
|
||
string strLibFeature, strLib, strFeature; | ||
string wildcards; | ||
|
||
vector<featureStringPair> vecfptr; | ||
vector<feature_function> vecfptr; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sorry, noob question here. I don't see this feature_function type defined anywhere. Is that normal? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was created in typedef int (*feature_function)(mapStr2intVec &,
mapStr2doubleVec &,
mapStr2Str &); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
if (vecFeature.size() == 0) return -1; | ||
|
||
// vecFeature is a list with all the feature names in the first column | ||
// of the dependency file | ||
for (unsigned i = 0; i < vecFeature.size(); i++) { | ||
|
||
FinalList.clear(); | ||
strLibFeature = vecFeature[i]; | ||
// fill FinalList with all the dependencies of feature vecFeature[i] | ||
getDependency(strLibFeature, ""); | ||
getDependency(strLibFeature); | ||
vecfptr.clear(); | ||
for (lstItr = FinalList.begin(); lstItr != FinalList.end(); lstItr++) { | ||
// Here strLibFeature is the feature name of the dependent feature | ||
|
@@ -102,14 +91,7 @@ int cTree::setFeaturePointers(map<string, feature2function *> &mapFptrLib, | |
strLib = strLibFeature.substr(0, nPos); | ||
|
||
// Put feature name in strFeature | ||
size_t wcpos = strLibFeature.find(";"); | ||
if (wcpos == string::npos) { | ||
strFeature = strLibFeature.substr(nPos + 1); | ||
wildcards = ""; | ||
} else { | ||
strFeature = strLibFeature.substr(nPos + 1, wcpos - nPos - 1); | ||
wildcards = strLibFeature.substr(wcpos); | ||
} | ||
strFeature = strLibFeature.substr(nPos + 1); | ||
|
||
// Find the feature function pointer map for the library | ||
mapLibItr = mapFptrLib.find(strLib); | ||
|
@@ -127,15 +109,13 @@ int cTree::setFeaturePointers(map<string, feature2function *> &mapFptrLib, | |
return -1; | ||
} | ||
|
||
// Add the feature function pointer and wildcards to the list of dependent | ||
// features | ||
vecfptr.push_back(featureStringPair(mapFeatureItr->second, wildcards)); | ||
vecfptr.push_back(mapFeatureItr->second); | ||
FptrTable->insert(std::pair<string, feature_function>( | ||
strFeature, mapFeatureItr->second)); | ||
strFeature, mapFeatureItr->second)); | ||
} | ||
// Add the vecfptr from above to a map with as key the base featurei | ||
FptrLookup->insert( | ||
std::pair<string, vector<featureStringPair> >(strFeature, vecfptr)); | ||
std::pair<string, vector<feature_function> >(strFeature, vecfptr)); | ||
} | ||
|
||
return 1; | ||
|
@@ -149,7 +129,7 @@ int cTree::setFeaturePointers(map<string, feature2function *> &mapFptrLib, | |
*/ | ||
int cTree::getAllParents(vector<string> &lstFeature) { | ||
for (unsigned i = 0; i < strDependencyFile.size(); i++) { | ||
const string& strLine = strDependencyFile[i]; | ||
const string &strLine = strDependencyFile[i]; | ||
size_t nPos = strLine.find_first_of('#'); | ||
string FeatureName = strLine.substr(0, nPos); | ||
if (!FeatureName.empty()) { | ||
|
@@ -180,43 +160,21 @@ int cTree::getChilds(string str, list<string> &childs) { | |
return 1; | ||
} | ||
|
||
/* | ||
* | ||
* Fill FinalList with a list of all the feature matching the wildcards | ||
* | ||
*/ | ||
int cTree::getDependency(string strLine, string wildcards) { | ||
list<string> tmpChild; | ||
|
||
// parse wildcards out of "LibVx:feature_name;wildcards_name" | ||
size_t wcpos = strLine.find(";"); | ||
if (wcpos != string::npos) { | ||
wildcards = strLine.substr(wcpos); | ||
strLine = strLine.substr(0, wcpos); | ||
} | ||
unsigned childCount = 0; | ||
int cTree::getDependency(const string &strLine) { | ||
std::list<string> tmpChild; | ||
|
||
getChilds(strLine, tmpChild); | ||
if (tmpChild.size() != 0) { | ||
childCount = tmpChild.size(); | ||
for (unsigned i = 0; i < childCount; i++) { | ||
string str = tmpChild.front(); | ||
tmpChild.pop_front(); | ||
getDependency(str, wildcards); | ||
} | ||
for (const auto &childFeature : tmpChild) { | ||
getDependency( | ||
childFeature); // Recursively get dependencies of the child feature. | ||
} | ||
AddUniqueItem(strLine + wildcards, FinalList); | ||
AddUniqueItem(strLine); // Add the feature itself to the FinalList. | ||
return 0; | ||
} | ||
|
||
int cTree::AddUniqueItem(string strFeature, list<string> &lstFinal) { | ||
list<string>::iterator lstItr; | ||
bool FoundFlag = false; | ||
for (lstItr = lstFinal.begin(); lstItr != lstFinal.end(); lstItr++) { | ||
if (strFeature == *lstItr) { | ||
FoundFlag = true; | ||
break; | ||
} | ||
void cTree::AddUniqueItem(const string &strFeature) { | ||
auto it = std::find(FinalList.begin(), FinalList.end(), strFeature); | ||
if (it == FinalList.end()) { | ||
FinalList.push_back(strFeature); | ||
} | ||
if (!FoundFlag) lstFinal.push_back(strFeature); | ||
return 1; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to keep this feature. Some users have used it before:
#137
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is reimplemented as a Python function.