KASKADE 7 development version
kaskopt.hh
Go to the documentation of this file.
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2/* */
3/* This file is part of the library KASKADE 7 */
4/* https://www.zib.de/research/projects/kaskade7-finite-element-toolbox */
5/* */
6/* Copyright (C) 2010-2012 Zuse Institute Berlin */
7/* */
8/* KASKADE 7 is distributed under the terms of the ZIB Academic License. */
9/* see $KASKADE/academic.txt */
10/* */
11/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
12#ifndef KASKOPT_HH
13#define KASKOPT_HH
14
15#include <memory>
16#include <string>
17
18#include <boost/property_tree/ptree.hpp>
19
21namespace boost { namespace program_options { class options_description; } }
23
24namespace Kaskade
25{
26 class Options
27 {
28 public:
29 template <class T>
30 Options(char const* option, T& parameter, T const& defaultValue, char const* comment);
31 Options(char const* option, std::string& parameter, char const* defaultValue, char const* comment);
32
33 template <class T>
34 Options& operator()(char const* option, T& parameter, T const& defaultValue, char const* comment);
35 Options& operator()(char const* option, std::string& parameter, char const* defaultValue, char const* comment);
36
37 boost::program_options::options_description const& descriptions() const;
38
40
41 private:
42 std::unique_ptr<boost::program_options::options_description> desc;
43 };
44
63 bool getKaskadeOptions(int argc, char** argv, Options const& options);
64}
65
66
67
68
81std::unique_ptr<boost::property_tree::ptree> getKaskadeOptions(int argc, char *argv[], int verbosity, bool dumpParameter);
82
83
90template <class TYPE>
91TYPE getParameter(std::unique_ptr<boost::property_tree::ptree> const& pt, const std::string s, TYPE defaultValue)
92{
93 return (*pt).get(s,defaultValue);
94}
95
96#endif
Options(char const *option, T &parameter, T const &defaultValue, char const *comment)
boost::program_options::options_description const & descriptions() const
Options(char const *option, std::string &parameter, char const *defaultValue, char const *comment)
Options & operator()(char const *option, std::string &parameter, char const *defaultValue, char const *comment)
Options & operator()(char const *option, T &parameter, T const &defaultValue, char const *comment)
bool getKaskadeOptions(int argc, char **argv, Options const &options)
Supports the extraction of program option values from command line arguments.
std::unique_ptr< boost::property_tree::ptree > getKaskadeOptions(int argc, char *argv[], int verbosity, bool dumpParameter)
The parameters can be written to a log file named "run-<starttime>-<pid>.json" in JSON format....
TYPE getParameter(std::unique_ptr< boost::property_tree::ptree > const &pt, const std::string s, TYPE defaultValue)
Extracts parameters from the parameter set.
Definition: kaskopt.hh:91