Skip to content
Snippets Groups Projects
Commit ce669fe4 authored by samuel.hayden's avatar samuel.hayden
Browse files

Command line parser checks if file path directories exist

Will present an error if they do not exist. This means no time is wasted generating the lattice just for it to not be able to be saved
parent 75b7d5c5
No related branches found
No related tags found
No related merge requests found
......@@ -7,15 +7,17 @@
enum ErrorCodes {
NoError = 0,
FileNotFound,
CellSizeNotDefined,
StrutRadiusNotDefined,
CantDetermineLatticeType,
LatticeTypeNotDefined,
FileNotFound, DirectoryNotFound, InvalidExtension,
CellSizeNotDefined, StrutRadiusNotDefined,
CantDetermineLatticeType, LatticeTypeNotDefined,
InvalidArgument,
FailedToMergeCells, FailedToTrimLattice,
LatticeIsNull, BoundingBoxIsNull,
UnknownError,
};
constexpr const char* errorcode2string(const ErrorCodes code)
......@@ -24,6 +26,8 @@ constexpr const char* errorcode2string(const ErrorCodes code)
{
case NoError: return "NO_ERROR";
case FileNotFound: return "FILE_NOT_FOUND";
case DirectoryNotFound: return "DIRECTORY_NOT_FOUND";
case InvalidExtension: return "INVALID_FILE_EXTENSION";
case CellSizeNotDefined: return "CELL_SIZE_NOT_DEFINED";
case StrutRadiusNotDefined: return "STRUT_RADIUS_NOT_DEFINED";
case CantDetermineLatticeType: return "CANT_DETERMINE_LATTICE_TYPE";
......
......@@ -2,6 +2,7 @@
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <sys/stat.h>
#include "ErrorCodes.h"
......@@ -21,6 +22,23 @@ private:
std::vector<ErrorCodes> _errors;
std::vector<std::string> _errorMsgs;
bool directoryExists(const std::string& filepath)
{
size_t directoryIdx = filepath.find_last_of('/');
if (directoryIdx == std::string::npos)
directoryIdx = filepath.find_last_of('\\');
// Isnt a directory. Just a file name to be placed in current path
if (directoryIdx == std::string::npos)
return true;
struct stat sb;
if (stat(filepath.substr(0, directoryIdx).c_str(), &sb) == 0)
return true; // Valid path
else
return false; // directory not found
}
private:
static AcceptedKeys s_validKeys;
......@@ -44,6 +62,14 @@ public:
_errorMsgs.emplace_back(key);
}
}
if (hasKey("input"))
{
if (!directoryExists(getValue("input")))
{
_errors.emplace_back(ErrorCodes::DirectoryNotFound);
_errorMsgs.emplace_back(getValue("input"));
}
}
}
inline const std::string& getValue(const std::string& key) const
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment