SHORE API
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
program.hpp
Go to the documentation of this file.
1 
2 /*
3  * Copyright 2008,2009,2010,2011,2012 Stephan Ossowski, Korbinian Schneeberger,
4  * Felix Ott, Joerg Hagmann, Alf Scotland, Sebastian Bender
5  *
6  * This file is part of SHORE.
7  *
8  * SHORE is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * SHORE is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with SHORE. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
25 
26 
30 
31 
32 #ifndef SHORE_PROGRAM_HPP__
33 #define SHORE_PROGRAM_HPP__
34 
35 #include <algorithm>
36 #include <string>
37 #include <vector>
38 
40 
42 namespace shore {
43 
44 class uncaught_handler;
45 
54 class program
55 {
56  public:
57 
62 
64  static std::string TMPDIR;
65 
66  private:
67 
68  friend class shore::uncaught_handler;
69 
71  std::string m_name;
73  std::string m_title;
75  std::string m_description;
77  std::string m_usage_description;
78 
80  std::string m_conffile;
81  bool m_conffileread;
82 
84  int m_status;
85 
86  av_parser m_optionparser;
87  int m_ac;
88  char **m_av;
89 
90  shore::uncaught_handler *m_uncaught_handler;
91 
93  std::string m_commandline;
94 
95  bool m_allow_mpi;
96 
97  bool m_showexthelp;
98  bool m_showusagedesc;
99  std::string m_helpcmd;
100 
101 
102  void run();
103 
105  program(const program&);
106 
107  protected:
108 
111  void allow_mpi();
112 
114  virtual int main()=0;
115 
117  virtual void sanity_check() {}
118 
122  virtual void basic_sanity_check();
123 
124  public:
125 
127  program();
128 
130  virtual ~program()
131  {}
132 
134  program &operator()(int ac,char** av);
135 
138  const std::string &command,const std::vector<std::string> &args);
139 
141  int status() const;
142 
144  template<class T>
146  const std::string &longshort,
147  T *target,
148  const std::string &info,
149  const std::string &aux_info=std::string())
150  {
151  add_option(longshort,"",target,info,OPT_SET,aux_info);
152  }
153 
155  template<class T>
157  const std::string& longshort,
158  T* target,
159  const std::string &info,
160  const OptionFlags def,
161  const std::string &aux_info=std::string())
162  {
163  add_option(longshort,"",target,info,def,aux_info);
164  }
165 
167  template<class T>
169  const std::string &longshort,
170  const std::string &conflicts_with,
171  T *target,
172  const std::string &info,
173  const std::string &aux_info=std::string())
174  {
175  add_option(longshort,conflicts_with,target,info,OPT_SET,aux_info);
176  }
177 
185  template<class T>
187  const std::string &longshort,
188  const std::string &conflicts_with,
189  T *target,
190  const std::string &info,
191  const OptionFlags def,
192  const std::string &aux_info=std::string())
193  {
194  m_optionparser.add_option(longshort,conflicts_with,target,info,def,aux_info);
195  }
196 
202  template<typename T>
204  T *const target,const std::string &name,const OptionFlags def)
205  {
206  m_optionparser.add_residualargs(target,name,"",def);
207  }
208 
215  template<typename T>
217  T *const target,
218  const std::string &name="FILES",
219  const std::string &conflicts_with=std::string(),
220  const OptionFlags def=shore::OPT_NOTSET,
221  typename boost::disable_if<boost::is_const<T> >::type *dummy=0)
222  {
223  m_optionparser.add_residualargs(target,name,conflicts_with,def);
224  }
225 
229  void add_residualargs(
230  const std::string &opt_id,const std::string &name);
231 
234  void set_configfile(const std::string &fn);
235 
238  void set_optiongroup(const std::string &g=std::string());
239 
242  void set_description(const std::string &desc);
243 
246  virtual const std::string& get_description() const;
247 
248  void set_usage_description(const std::string &desc);
249  void set_title(const std::string &t);
250 
252  void set_programname(const std::string& name);
253 
255  const std::string& get_programname() const;
256 
258  void set_helpcmd(const std::string& cmd);
259 
262  bool is_altered(const void*const ptr) const;
263 
265  size_t num_altered() const;
266 
268  const std::string& get_commandline() const;
269 
272 
277 
279  const av_parser& get_optionparser() const;
280 
282  void set_show_extended_help(const bool f);
283  void set_show_usage_description(const bool f);
284 
286  virtual void show_usage() const;
287 
288  std::string startup_message() const;
289  std::string shutdown_message() const;
290 };
291 
292 } // namespace shore
293 
294 #endif // SHORE_PROGRAM_HPP__
295 
296 // vim: sw=4:softtabstop=4:expandtab