marker_separation/cpp/cmd.cpp

52 lines
1.1 KiB
C++

#include "cmd.h"
inline bool Cmd::in_array(const std::string &value, const std::vector<std::string> &array)
{
return std::find(array.begin(), array.end(), value) != array.end();
}
inline bool Cmd::file_exists (const std::string& name)
{
struct stat buffer;
return (stat (name.c_str(), &buffer) == 0);
}
inline bool Cmd::is_image (const std::string& name)
{
string ext = name.substr(name.find_last_of(".") + 1);
return in_array(ext, supportedExt);
}
string Cmd::get_input (int &argc, string argstr)
{
string input;
if (argc > 1)
{
input = argstr;
}
else if (argc < 2)
{
cerr << "Please provide one image." << endl;
return;
}
else if (argc > 2)
{
cerr << "Please provide only one image." << endl;
return;
}
if (!file_exists(input))
{
cerr << "File " << input << " does not exist." << endl;
return;
}
if (!is_image(input))
{
cerr << "File " << input << " is not a valid image." << endl;
return;
}
return input;
}