]> git.localhorst.tv Git - l2e.git/blob - src/app/Arguments.cpp
store complete entity in hero
[l2e.git] / src / app / Arguments.cpp
1 /*
2  * Arguments.cpp
3  *
4  *  Created on: Sep 15, 2012
5  *      Author: holy
6  */
7
8 #include "Arguments.h"
9
10 #include <stdexcept>
11 #include <string>
12
13 namespace app {
14
15 Arguments::Arguments()
16 : outfile(0)
17 , dump(false) {
18
19 }
20
21
22 void Arguments::Read(int argc, char **argv) {
23         for (int i(1); i < argc; ++i) {
24                 char *arg(argv[i]);
25                 if (arg[0] == '-') {
26                         switch (arg[1]) {
27                                 case 'd':
28                                         dump = true;
29                                         break;
30                                 case 'o':
31                                         if (i + 1 >= argc) {
32                                                 throw std::runtime_error("missing argument to -o");
33                                         }
34                                         ++i;
35                                         outfile = argv[i];
36                                         break;
37                                 default:
38                                         throw std::runtime_error(std::string("unknown option ") + arg[1]);
39                                         break;
40                         }
41                 } else {
42                         infiles.push_back(arg);
43                 }
44         }
45 }
46
47 Arguments::RunLevel Arguments::DetectRunLevel() const {
48         if (dump) {
49                 return DUMP;
50         } else if (outfile) {
51                 return WRITE;
52         } else {
53                 return PLAY;
54         }
55 }
56
57 }