]> git.tdb.fi Git - r2c2.git/blobdiff - source/engineer/options.cpp
Major architecture rework
[r2c2.git] / source / engineer / options.cpp
diff --git a/source/engineer/options.cpp b/source/engineer/options.cpp
new file mode 100644 (file)
index 0000000..9861c10
--- /dev/null
@@ -0,0 +1,51 @@
+/* $Id$
+
+This file is part of the MSP Märklin suite
+Copyright © 2010  Mikkosoft Productions, Mikko Rasa
+Distributed under the GPL
+*/
+
+#include <msp/core/getopt.h>
+#include <msp/strings/lexicalcast.h>
+#include <msp/strings/regex.h>
+#include "options.h"
+
+using namespace std;
+using namespace Msp;
+
+Options::Options(int argc, char **argv):
+       screen_w(1280),
+       screen_h(960),
+       fullscreen(false),
+       debug(false),
+       network(false),
+       simulate(false)
+{
+       string res;
+
+       GetOpt getopt;
+       getopt.add_option('r', "resolution",  res,         GetOpt::REQUIRED_ARG);
+       getopt.add_option('f', "fullscreen",  fullscreen,  GetOpt::NO_ARG);
+       getopt.add_option('g', "debug",       debug,       GetOpt::NO_ARG);
+       getopt.add_option('d', "driver",      driver,      GetOpt::REQUIRED_ARG);
+       getopt.add_option('s', "simulate",    simulate,    GetOpt::NO_ARG);
+       getopt.add_option('n', "network",     network,     GetOpt::NO_ARG);
+       getopt(argc, argv);
+
+       if(!res.empty())
+       {
+               if(RegMatch m=Regex("([1-9][0-9]*)x([1-9][0-9]*)").match(res))
+               {
+                       screen_w = lexical_cast<unsigned>(m[1].str);
+                       screen_h = lexical_cast<unsigned>(m[2].str);
+               }
+               else
+                       throw UsageError("Invalid resolution");
+       }
+
+       const vector<string> &args = getopt.get_args();
+       if(args.empty())
+               throw UsageError("No layout given");
+
+       layout_fn = args[0];
+}