Skip to content

Commit

Permalink
Merge remote-tracking branch 'proplib-template/main' into cross-platf…
Browse files Browse the repository at this point in the history
…orm-cli-driver
  • Loading branch information
aromanielloNTIA committed Nov 4, 2024
2 parents dc6af9f + 6c6a25e commit c464dbd
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 31 deletions.
3 changes: 2 additions & 1 deletion app/include/Driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ void PrintClutterTypeLabel(std::ofstream &fp, const ClutterType clutter_type);

// Driver Utils
std::string GetDatetimeString();
DrvrReturnCode ParseBoolean(const std::string &str, bool &value);
DrvrReturnCode ParseDouble(const std::string &str, double &value);
DrvrReturnCode ParseInteger(const std::string &str, int &value);
void PrintLabel(std::ofstream &fp, const std::string &lbl);
void PrintLabel(std::ostream &os, const std::string &lbl);
void StringToLower(std::string &str);
void Version(std::ostream &os = std::cout);
59 changes: 29 additions & 30 deletions app/src/DriverUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,32 @@ std::string GetDatetimeString() {
return std::string(mbstr);
}

/*******************************************************************************
* Parse a boolean value read from the input parameter file.
*
* Supports either "true" or "false" (case-insensitive) or "0" or "1"
*
* @param[in] str Input file value as string
* @param[out] value Input file value converted to bool
* @return Return code
******************************************************************************/
DrvrReturnCode ParseBoolean(const std::string &str, bool &value) {
try {
std::string str_lower = str;
StringToLower(str_lower);
if (str_lower == "0" || str_lower == "false") {
value = false;
} else if (str_lower == "1" || str_lower == "true") {
value = true;
} else {
return DRVRERR__PARSE;
}
} catch (...) {
return DRVRERR__PARSE;
}
return DRVR__SUCCESS;
}

/*******************************************************************************
* Parse a double value read from the input parameter file
*
Expand Down Expand Up @@ -86,27 +112,14 @@ DrvrReturnCode ParseInteger(const std::string &str, int &value) {
return DRVR__SUCCESS;
}

/*******************************************************************************
* Common error handling function
*
* @param[in] err Error parsing code
* @param[in] msg Error message
* @return Error code from input param
******************************************************************************/
int ParsingErrorHelper(const int err, const std::string &msg) {
std::cerr << "Driver Error " << err << ": Unable to parse '" << msg
<< "' value." << std::endl;
return err;
}

/*******************************************************************************
* Helper function to standardize printing of text labels to file
*
* @param[in] fp Output stream, a text file open for writing
* @param[in] os Output stream for writing
* @param[in] lbl Text message
******************************************************************************/
void PrintLabel(std::ofstream &fp, const std::string &lbl) {
fp << "[" << lbl << "]";
void PrintLabel(std::ostream &os, const std::string &lbl) {
os << "[" << lbl << "]";
}


Expand All @@ -121,20 +134,6 @@ void StringToLower(std::string &str) {
});
}

/*******************************************************************************
* Helper function to format and print error messages encountered during
* validation of input parameters
*
* @param[in] opt Command flag in error
* @param[in] err Error code
* @return Return code
******************************************************************************/
int Validate_RequiredErrMsgHelper(const std::string &opt, const int err) {
std::cerr << "Driver Error " << err << ": Option \"" << opt
<< "\" is required but was not provided" << std::endl;
return err;
}

/*******************************************************************************
* Print version information to the specified output stream
*
Expand Down

0 comments on commit c464dbd

Please sign in to comment.