- handle seed in args
This commit is contained in:
57
.vscode/settings.json
vendored
Normal file
57
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,57 @@
|
||||
{
|
||||
"files.associations": {
|
||||
"cctype": "cpp",
|
||||
"clocale": "cpp",
|
||||
"cmath": "cpp",
|
||||
"cstdarg": "cpp",
|
||||
"cstddef": "cpp",
|
||||
"cstdio": "cpp",
|
||||
"cstdlib": "cpp",
|
||||
"cstring": "cpp",
|
||||
"cwchar": "cpp",
|
||||
"array": "cpp",
|
||||
"atomic": "cpp",
|
||||
"bit": "cpp",
|
||||
"*.tcc": "cpp",
|
||||
"compare": "cpp",
|
||||
"concepts": "cpp",
|
||||
"cstdint": "cpp",
|
||||
"deque": "cpp",
|
||||
"list": "cpp",
|
||||
"map": "cpp",
|
||||
"set": "cpp",
|
||||
"unordered_map": "cpp",
|
||||
"vector": "cpp",
|
||||
"exception": "cpp",
|
||||
"algorithm": "cpp",
|
||||
"functional": "cpp",
|
||||
"iterator": "cpp",
|
||||
"memory": "cpp",
|
||||
"memory_resource": "cpp",
|
||||
"random": "cpp",
|
||||
"string": "cpp",
|
||||
"string_view": "cpp",
|
||||
"tuple": "cpp",
|
||||
"type_traits": "cpp",
|
||||
"utility": "cpp",
|
||||
"initializer_list": "cpp",
|
||||
"iosfwd": "cpp",
|
||||
"iostream": "cpp",
|
||||
"istream": "cpp",
|
||||
"limits": "cpp",
|
||||
"mutex": "cpp",
|
||||
"new": "cpp",
|
||||
"ostream": "cpp",
|
||||
"ranges": "cpp",
|
||||
"sstream": "cpp",
|
||||
"streambuf": "cpp",
|
||||
"cinttypes": "cpp",
|
||||
"typeinfo": "cpp",
|
||||
"cwctype": "cpp",
|
||||
"fstream": "cpp",
|
||||
"numbers": "cpp",
|
||||
"stdexcept": "cpp",
|
||||
"system_error": "cpp",
|
||||
"optional": "cpp"
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@
|
||||
#include <utility>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include "file_input.h"
|
||||
#include "file_output.h"
|
||||
#include "console_input.h"
|
||||
@ -15,7 +16,8 @@ feature proc_args(int argc, char **argv,
|
||||
std::unique_ptr<cursor> &curse,
|
||||
std::unique_ptr<input> &in,
|
||||
std::unique_ptr<display> &out,
|
||||
std::unique_ptr<logger> &log) {
|
||||
std::unique_ptr<logger> &log,
|
||||
std::unique_ptr<RNG> &rng) {
|
||||
feature result = 0;
|
||||
std::string str;
|
||||
std::string fn_fin;
|
||||
@ -122,6 +124,16 @@ feature proc_args(int argc, char **argv,
|
||||
out = std::make_unique<curses_output>(curse);
|
||||
}
|
||||
|
||||
if (result & FEATURE_SEED) {
|
||||
std::istringstream iss {seed};
|
||||
unsigned int tmp;
|
||||
iss >> tmp;
|
||||
if (!iss.good())
|
||||
return FEATURE_PANIC_SEED;
|
||||
|
||||
rng = std::make_unique<RNG>(tmp);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -153,6 +165,9 @@ void panic_args(feature panic) {
|
||||
cerr << "Something must have went really, really, wrong..."
|
||||
<< endl;
|
||||
}
|
||||
}
|
||||
else if (panic & FEATURE_PANIC_SEED) {
|
||||
cerr << "Invalid seed" << endl;
|
||||
} else
|
||||
cerr << "Something must have went really, really, wrong..."
|
||||
<< endl;
|
||||
|
@ -5,6 +5,8 @@
|
||||
#include "cursor.h"
|
||||
#include "display.h"
|
||||
#include "input.h"
|
||||
#include "rng.h"
|
||||
|
||||
|
||||
#include "constants.h"
|
||||
|
||||
@ -28,7 +30,8 @@ feature proc_args(int argc, char **argv,
|
||||
std::unique_ptr<cursor> &curse,
|
||||
std::unique_ptr<input> &in,
|
||||
std::unique_ptr<display> &out,
|
||||
std::unique_ptr<logger> &log);
|
||||
std::unique_ptr<logger> &log,
|
||||
std::unique_ptr<RNG> &rng);
|
||||
|
||||
void panic_args(feature panic);
|
||||
|
||||
|
@ -82,6 +82,8 @@ const feature FEATURE_SEED = 1 << 7;
|
||||
const feature FEATURE_MENU = 1 << 8;
|
||||
const feature FEATURE_IN_FILE = 1 << 9;
|
||||
const feature FEATURE_OUT_FILE = 1 << 10;
|
||||
|
||||
const feature FEATURE_PANIC_SEED = 1 << 27;
|
||||
const feature FEATURE_PANIC_FILE = 1 << 28;
|
||||
const feature FEATURE_PANIC = 1 << 29;
|
||||
const feature FEATURE_CONFLICT = 1 << 30;
|
||||
|
@ -6,11 +6,15 @@ int main(int argc, char **argv) {
|
||||
std::unique_ptr<input> in;
|
||||
std::unique_ptr<display> out;
|
||||
std::unique_ptr<logger> log;
|
||||
std::unique_ptr<RNG> rng;
|
||||
|
||||
feature enabled_features = proc_args(argc, argv, curse, in, out, log);
|
||||
|
||||
feature enabled_features = proc_args(argc, argv,
|
||||
curse, in, out, log, rng);
|
||||
|
||||
if (enabled_features &
|
||||
(FEATURE_PANIC | FEATURE_PANIC_FILE | FEATURE_CONFLICT)) {
|
||||
(FEATURE_PANIC | FEATURE_PANIC_FILE |
|
||||
FEATURE_CONFLICT | FEATURE_PANIC_SEED)) {
|
||||
panic_args(enabled_features);
|
||||
return RETURN_PANICKED;
|
||||
}
|
||||
|
Reference in New Issue
Block a user