]> git.tdb.fi Git - r2c2.git/blob - source/engineer/options.cpp
Major architecture rework
[r2c2.git] / source / engineer / options.cpp
1 /* $Id$
2
3 This file is part of the MSP Märklin suite
4 Copyright © 2010  Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
6 */
7
8 #include <msp/core/getopt.h>
9 #include <msp/strings/lexicalcast.h>
10 #include <msp/strings/regex.h>
11 #include "options.h"
12
13 using namespace std;
14 using namespace Msp;
15
16 Options::Options(int argc, char **argv):
17         screen_w(1280),
18         screen_h(960),
19         fullscreen(false),
20         debug(false),
21         network(false),
22         simulate(false)
23 {
24         string res;
25
26         GetOpt getopt;
27         getopt.add_option('r', "resolution",  res,         GetOpt::REQUIRED_ARG);
28         getopt.add_option('f', "fullscreen",  fullscreen,  GetOpt::NO_ARG);
29         getopt.add_option('g', "debug",       debug,       GetOpt::NO_ARG);
30         getopt.add_option('d', "driver",      driver,      GetOpt::REQUIRED_ARG);
31         getopt.add_option('s', "simulate",    simulate,    GetOpt::NO_ARG);
32         getopt.add_option('n', "network",     network,     GetOpt::NO_ARG);
33         getopt(argc, argv);
34
35         if(!res.empty())
36         {
37                 if(RegMatch m=Regex("([1-9][0-9]*)x([1-9][0-9]*)").match(res))
38                 {
39                         screen_w = lexical_cast<unsigned>(m[1].str);
40                         screen_h = lexical_cast<unsigned>(m[2].str);
41                 }
42                 else
43                         throw UsageError("Invalid resolution");
44         }
45
46         const vector<string> &args = getopt.get_args();
47         if(args.empty())
48                 throw UsageError("No layout given");
49
50         layout_fn = args[0];
51 }