config.cpp 1.85 KB
Newer Older
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
#include "config.h"

#include <cassert>
#include <sstream>

#include "common.h"

Config::Config(int argc, char **argv)
	: mode_(UNSET)
{
	assert(argc>=1);
	program_name_=argv[0];

	auto i=1;

	while (i<argc) {
		std::string arg(argv[i]);

		if (arg=="--help") {
			mode_=HELP;
			break;
		} else if (arg=="--version") {
			mode_=VERSION;
			break;
		} else {
			if (mode_==UNSET) {
				mode_=NORMAL;
				fp_path_=arg;
			} else {
Vladislav Perepelkin's avatar
Vladislav Perepelkin committed
30
				argv_.push_back(arg);
31
32
33
34
			}
		}
		i++;
	}
35

36
37
	if (mode_==UNSET) {
		mode_=ERROR;
38
		ERROR("Not enough command-line arguments")
39
40
41
42
43
44
45
	}

	if (mode_==ERROR) {
		ABORT("Invalid command-line arguments, run with '--help' for info.")
	}
}

46
Config::RunMode Config::get_run_mode() const noexcept { return mode_; }
47

Vladislav Perepelkin's avatar
Vladislav Perepelkin committed
48
49
50
51
52
53
54
55
56
const std::string &Config::argv(unsigned int idx) const
{
	if (idx>=argv_.size()) {
		ABORT("Argv index out of range: " + std::to_string(idx) + ">="
			+ std::to_string(argv_.size()))
	}

	return argv_.at(idx);
}
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78

const std::string &Config::get_fp_path() const
{
	assert(mode_==NORMAL);

	return fp_path_;
}

std::string Config::get_help() const
{
	std::ostringstream os;

	os << std::endl;
	os << "Usage:" << std::endl;
	os << "\t" << program_name_ << " path/to/program.so" << std::endl;
	os << "\t" << program_name_ << " --version" << std::endl;
	os << "\t" << program_name_ << " --help" << std::endl;
	os << std::endl;

	return os.str();
}

79
80
81
82
83
84
85
86
87
88
89
std::string Config::get_version() const
{
	std::ostringstream os;

	os << std::endl;
	os << "LuNA version: " << VERSION_RTS << std::endl;
	os << std::endl;

	return os.str();
}

90
unsigned int Config::get_worker_threads_count() const noexcept
91
92
93
94
{
	return DEFAULT_WORKER_THREADS_COUNT;
}

95
unsigned int Config::get_comm_request_threads_count() const noexcept
96
97
98
99
{
	return DEFAULT_COMM_REQUEST_THREADS_COUNT;
}

100
unsigned int Config::get_comm_recv_threads_count() const noexcept
101
102
103
{
	return DEFAULT_COMM_RECEIVE_THREADS_COUNT;
}