-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmatoolargs.h
80 lines (69 loc) · 1.89 KB
/
matoolargs.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#ifndef MATOOL_MATOOLARGS_H
#define MATOOL_MATOOLARGS_H
#include <stdexcept>
#include <filesystem>
#include <vector>
#include <cmdutils/options.h>
#include <libim/common.h>
#include <libim/utils/utils.h>
namespace matool {
namespace fs = std::filesystem;
class MatoolArgs : public cmdutils::CmdArgs
{
public:
MatoolArgs(std::size_t argc, const char *argv[])
{
parse(argc, argv, [&](auto tp, auto t){
parseToken(tp, t);
});
}
const std::string& cmd() const
{
return cmd_;
}
/**
* Returns sub-command argument which is
* equal to positionalArgs().at(0).
*/
std::string subcmd() const
{
return positionalArgs().empty() ? "" : positionalArgs().at(0);
}
const fs::path& matFile() const
{
return matfile_;
}
const std::vector<fs::path>& imageFiles() const
{
return imgfiles_;
}
private:
void parseToken(std::size_t tokenPos, std::string_view token)
{
if(libim::fileExtMatch(token, ".mat"))
{
if(!matfile_.empty()) {
throw std::invalid_argument("Only one MAT file path should be set");
}
matfile_ = token;
}
if(libim::fileExtMatch(token, ".png") || libim::fileExtMatch(token, ".bmp"))
{
auto file = std::string(token);
imgfiles_.push_back(file);
}
else if(tokenPos == 1)
{
cmd_ = token;
}
else {
CmdArgs::parseToken(tokenPos, token);
}
}
private:
fs::path matfile_;
std::vector<fs::path> imgfiles_;
std::string cmd_;
};
}
#endif // MATOOL_MATOOLARGS_H