Lumiera  0.pre.03
»edit your freedom«
option.cpp
Go to the documentation of this file.
1 /*
2  Option - handle cmdline for starting the Lumiera application
3 
4  Copyright (C) Lumiera.org
5  2008, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 * *****************************************************/
22 
23 
30 #include "lib/error.hpp"
31 #include "lib/util.hpp"
32 #include "common/option.hpp"
33 
34 
35 
36 typedef boost::program_options::options_description Syntax;
37 typedef boost::program_options::variables_map VarMap;
38 
39 namespace op = boost::program_options;
40 
41 using lib::VectS;
42 
43 
44 namespace lumiera {
45 
58  : syntax("Lumiera, the non linear video editor.\nSupported parameters"),
59  parameters()
60  {
61  syntax.add_options()
62  ("help,h", "produce help message")
63  ("session,f", op::value<string>(),
64  "session file to load (UNIMPLEMENTED)")
65  ("script,s", op::value<VectS>(),
66  "execute the given script (UNIMPLEMENTED)")
67  ("headless", op::bool_switch(),
68  "start without GUI")
69  ("port,p", op::value<int>(),
70  "open renderfarm node at given port (UNIMPLEMENTED)")
71  ("define,def,D",op::value<VectS>(),
72  "enter definition into config system (UNIMPLEMENTED)")
73  ;
74 
75  // the name of an session file to open...
76  op::positional_options_description posopt;
77  posopt.add("session", 1); // ... can be given as 1st positional parameter
78 
79  op::parsed_options parsed =
80  op::command_line_parser (cmdline)
81  .options (syntax)
82  .positional(posopt)
83  .allow_unregistered()
84  .run();
85 
86  op::store (parsed, parameters);
87  op::notify(parameters);
88 
89  // remove all recognised options from original cmdline vector
90  cmdline = op::collect_unrecognized(parsed.options, op::include_positional);
91 
92  if (isHelp())
93  {
94  cerr << *this;
95  exit(-1);
96  }
97  if (isConfigDefs())
98  {
99  UNIMPLEMENTED ("feed definitions from commandline to Config system");
100  }
101  }
102 
103 
104 
106  bool Option::isHelp () { return (parameters.count("help")); }
107 
109  bool Option::isOpenSession () { return (parameters.count ("session")); }
110 
112  bool Option::isConfigDefs () { return (parameters.count ("define")); }
113 
114 
116  const string
118  {
119  ASSERT (parameters.count ("session"));
120  return parameters["session"].as<string>();
121  }
122 
125  const VectS
127  {
128  return parameters["script"].as<VectS>();
129  }
130 
133  const VectS
135  {
136  return parameters["define"].as<VectS>();
137  }
138 
140  bool
142  {
143  return parameters["headless"].as<bool>();
144  }
145 
148  int
150  {
151  if (parameters.count ("port"))
152  return parameters["port"].as<int>();
153  else
154  return 0;
155  }
156 
157 
158 
159  ostream&
160  operator<< (ostream& os, const Option& ops)
161  {
162  return os << ops.syntax;
163  }
164 
165 
166 
167 } // namespace lumiera
const VectS getConfigDefs()
Definition: option.cpp:134
bool isOpenSession()
should an existing session file be loaded?
Definition: option.cpp:109
Option(lib::Cmdline &cmdline)
set up an options parser to use the application commandline.
Definition: option.cpp:57
Frontend for handling the Lumiera application commandline arguments.
Definition: option.hpp:77
bool isHeadless()
Definition: option.cpp:141
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
friend ostream & operator<<(ostream &, const Option &)
for outputting the help messages.
Definition: option.cpp:160
front-end for handling the commandline arguments.
bool isHelp()
syntax help requested?
Definition: option.cpp:106
bool isConfigDefs()
additional Config defs to fed to config system?
Definition: option.cpp:112
Lumiera error handling (C++ interface).
const string getSessName()
Definition: option.cpp:117
Lumiera public interface.
Definition: advice.cpp:113
Abstraction of the usual int argc, int** argv-Commandline, to be able to treat it as a vector of stri...
Definition: cmdline.hpp:57
const VectS getScripts()
Definition: option.cpp:126