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