author | František Kučera <franta-hg@frantovo.cz> |
Fri, 02 Oct 2020 00:34:14 +0200 | |
branch | v_0 |
changeset 9 | 14cf28d7681c |
parent 2 | 01553c2ffa1d |
child 15 | b3239e4ad328 |
permissions | -rw-r--r-- |
0 | 1 |
/** |
2 |
* Relational pipes |
|
3 |
* Copyright © 2020 František Kučera (Frantovo.cz, GlobalCode.info) |
|
4 |
* |
|
5 |
* This program is free software: you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation, version 3 of the License. |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 |
*/ |
|
17 |
#pragma once |
|
18 |
||
19 |
#include <vector> |
|
20 |
#include <iostream> |
|
21 |
||
22 |
#include <relpipe/common/type/typedefs.h> |
|
23 |
#include <relpipe/cli/CLI.h> |
|
24 |
#include <relpipe/cli/RelpipeCLIException.h> |
|
25 |
||
26 |
#include "Configuration.h" |
|
27 |
||
28 |
namespace relpipe { |
|
29 |
namespace out { |
|
30 |
namespace jack { |
|
31 |
||
32 |
class CLIParser { |
|
33 |
private: |
|
34 |
||
35 |
relpipe::common::type::StringX readNext(const std::vector<relpipe::common::type::StringX>& arguments, int& i) { |
|
36 |
if (i < arguments.size()) return arguments[i++]; |
|
37 |
else throw relpipe::cli::RelpipeCLIException(L"Missing CLI argument" + (i > 0 ? (L" after " + arguments[i - 1]) : L""), relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS); |
|
38 |
} |
|
39 |
||
40 |
/** |
|
41 |
* TODO: use a common method |
|
42 |
*/ |
|
43 |
bool parseBoolean(const relpipe::common::type::StringX& value) { |
|
44 |
if (value == L"true") return true; |
|
45 |
else if (value == L"false") return false; |
|
46 |
else throw relpipe::cli::RelpipeCLIException(L"Unable to parse boolean value: " + value + L" (expecting true or false)", relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS); |
|
47 |
} |
|
48 |
||
49 |
public: |
|
50 |
||
2
01553c2ffa1d
configurable JACK client name
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
51 |
static const relpipe::common::type::StringX OPTION_JACK_CLIENT_NAME; |
9
14cf28d7681c
option: --required-jack-connections (start after given number of port connections)
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
52 |
static const relpipe::common::type::StringX OPTION_REQUIRED_JACK_CONNECTIONS; |
0 | 53 |
|
54 |
Configuration parse(const std::vector<relpipe::common::type::StringX>& arguments) { |
|
55 |
Configuration c; |
|
56 |
||
57 |
for (int i = 0; i < arguments.size();) { |
|
58 |
relpipe::common::type::StringX option = readNext(arguments, i); |
|
59 |
||
2
01553c2ffa1d
configurable JACK client name
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
60 |
if (option == OPTION_JACK_CLIENT_NAME) { |
01553c2ffa1d
configurable JACK client name
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
61 |
c.jackClientName = readNext(arguments, i); |
9
14cf28d7681c
option: --required-jack-connections (start after given number of port connections)
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
62 |
} else if (option == OPTION_REQUIRED_JACK_CONNECTIONS) { |
14cf28d7681c
option: --required-jack-connections (start after given number of port connections)
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
63 |
c.requiredJackConnections = std::stoi(readNext(arguments, i)); |
0 | 64 |
} else throw relpipe::cli::RelpipeCLIException(L"Unsupported CLI option: " + option, relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS); |
65 |
} |
|
66 |
||
67 |
return c; |
|
68 |
} |
|
69 |
||
70 |
virtual ~CLIParser() { |
|
71 |
} |
|
72 |
}; |
|
73 |
||
2
01553c2ffa1d
configurable JACK client name
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
74 |
const relpipe::common::type::StringX CLIParser::OPTION_JACK_CLIENT_NAME = L"--jack-client-name"; |
9
14cf28d7681c
option: --required-jack-connections (start after given number of port connections)
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
75 |
const relpipe::common::type::StringX CLIParser::OPTION_REQUIRED_JACK_CONNECTIONS = L"--required-jack-connections"; |
0 | 76 |
|
77 |
} |
|
78 |
} |
|
79 |
} |