author | František Kučera <franta-hg@frantovo.cz> |
Thu, 09 Aug 2018 22:58:38 +0200 | |
branch | v_0 |
changeset 18 | 9e543fd0254c |
parent 11 | 3798b6bc9aea |
permissions | -rw-r--r-- |
10
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
1 |
#pragma once |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
2 |
|
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
3 |
#include <locale.h> |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
4 |
#include <string> |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
5 |
#include <vector> |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
6 |
#include <sstream> |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
7 |
#include <locale> |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
8 |
#include <codecvt> |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
9 |
|
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
10 |
using namespace std; |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
11 |
|
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
12 |
namespace relpipe { |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
13 |
namespace cli { |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
14 |
|
11
3798b6bc9aea
ArgumentsCommand: generate relational data from CLI arguments
František Kučera <franta-hg@frantovo.cz>
parents:
10
diff
changeset
|
15 |
/** |
3798b6bc9aea
ArgumentsCommand: generate relational data from CLI arguments
František Kučera <franta-hg@frantovo.cz>
parents:
10
diff
changeset
|
16 |
* TODO: move to relpipe-lib-cli (a common header-only library) |
3798b6bc9aea
ArgumentsCommand: generate relational data from CLI arguments
František Kučera <franta-hg@frantovo.cz>
parents:
10
diff
changeset
|
17 |
*/ |
10
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
18 |
class CLI { |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
19 |
public: |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
20 |
|
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
21 |
CLI(int argc, char* argv[]) { |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
22 |
setlocale(LC_ALL, ""); |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
23 |
|
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
24 |
this->argc = &argc; |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
25 |
this->argv = &argv; |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
26 |
|
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
27 |
program = convertor.from_bytes(argv[0]); |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
28 |
|
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
29 |
for (int i = 1; i < argc; i++) { |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
30 |
args.insert(args.end(), convertor.from_bytes(argv[i])); |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
31 |
} |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
32 |
|
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
33 |
} |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
34 |
|
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
35 |
CLI(const CLI& orig) { |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
36 |
} |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
37 |
|
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
38 |
virtual ~CLI() { |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
39 |
} |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
40 |
|
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
41 |
const wstring programName() { |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
42 |
return (const wstring) program; |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
43 |
} |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
44 |
|
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
45 |
const vector<wstring> arguments() { |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
46 |
return (const vector<wstring>)args; |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
47 |
} |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
48 |
|
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
49 |
static const int EXIT_CODE_SUCCESS = 0; |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
50 |
static const int EXIT_CODE_UNEXPECTED_ERROR = 1; |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
51 |
static const int EXIT_CODE_BAD_SYNTAX = 3; |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
52 |
static const int EXIT_CODE_UNKNOWN_COMMAND = 4; |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
53 |
static const int EXIT_CODE_DATA_ERROR = 5; |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
54 |
|
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
55 |
private: |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
56 |
int* argc; |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
57 |
char*** argv; |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
58 |
wstring program; |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
59 |
vector<wstring> args; |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
60 |
wstring_convert<codecvt_utf8<wchar_t>> convertor; // TODO: support also other encodings. |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
61 |
}; |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
62 |
|
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
63 |
} |
77593735b057
CLI infrastructure ported from the prototype
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
64 |
} |