[TechDraw] Simplify return logic

Normal warmup
This commit is contained in:
Benjamin Bræstrup Sayoc
2023-04-09 19:03:50 +02:00
committed by WandererFan
parent 6df0a20214
commit a93060c6b9
16 changed files with 164 additions and 238 deletions

View File

@@ -298,26 +298,24 @@ void PATLineSpec::dump(const char* title)
//static class methods
std::vector<PATLineSpec> PATLineSpec::getSpecsForPattern(std::string& parmFile, std::string& parmName)
{
std::vector<PATLineSpec> result;
std::vector<std::string> lineSpecs;
Base::FileInfo fi(parmFile);
Base::ifstream inFile;
inFile.open (fi, std::ifstream::in);
inFile.open(fi, std::ifstream::in);
if(!inFile.is_open()) {
Base::Console().Message( "Cannot open input file.\n");
return result;
Base::Console().Message("Cannot open input file.\n");
return std::vector<PATLineSpec>();
}
//get all the definition lines for this pattern
bool status = findPatternStart(inFile, parmName);
if (status) {
lineSpecs = loadPatternDef(inFile);
} else {
//this can come up when changing PAT file or pattern name
return result;
if (!status) { // This can come up when changing PAT file or pattern name
return std::vector<PATLineSpec>();
}
lineSpecs = loadPatternDef(inFile);
//decode definition lines into PATLineSpec objects
std::vector<PATLineSpec> result;
for (auto& l: lineSpecs) {
PATLineSpec hl(l);
result.push_back(hl);
@@ -328,16 +326,15 @@ std::vector<PATLineSpec> PATLineSpec::getSpecsForPattern(std::string& parmFile,
bool PATLineSpec::findPatternStart(std::ifstream& inFile, std::string& parmName)
{
// Base::Console().Message("HL::findPatternStart() - parmName: %s\n", parmName.c_str());
bool result = false;
while ( inFile.good() ){
while (inFile.good() ){
std::string line;
std::getline(inFile, line);
std::string nameTag = line.substr(0, 1);
std::string patternName;
std::size_t commaPos;
if ((nameTag == ";") ||
(nameTag == " ") ||
(line.empty()) ) { //is cr/lf empty?
if (nameTag == ";" ||
nameTag == " " ||
line.empty()) { //is cr/lf empty?
continue;
} else if (nameTag == "*") {
commaPos = line.find(',',1);
@@ -348,12 +345,11 @@ bool PATLineSpec::findPatternStart(std::ifstream& inFile, std::string& parmName
}
if (patternName == parmName) {
//this is our pattern
result = true;
break;
return true;
}
}
} //endwhile
return result;
return false;
}
//get the definition lines for this pattern