MAST3
Multidisciplinary-design Adaptation and Sensitivity Toolkit (MAST)
getpot_wrapper.hpp
Go to the documentation of this file.
1 /*
2  * MAST: Multidisciplinary-design Adaptation and Sensitivity Toolkit
3  * Copyright (C) 2013-2020 Manav Bhatia and MAST authors
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 
21 #ifndef __mast_getpot_wrapper_h__
22 #define __mast_getpot_wrapper_h__
23 
24 
25 // GetPot includes
26 #include <getpot/GetPot>
27 
28 
29 namespace MAST {
30 namespace Utility {
31 
32 
34 
35 public:
36 
43  GetPotWrapper(const int argc,
44  char **argv,
45  const std::string &input):
46  _input (nullptr),
47  _print (false) {
48 
49  GetPot command_line(argc, argv);
50  std::string
51  input_name = command_line(input, "");
52 
53  if (input_name == "")
54  _input = new GetPot(argc, argv);
55  else
56  _input = new GetPot(input_name);
57 
58  _print = (*_input)("print_params", false);
59  }
60 
61 
66  GetPotWrapper(const int argc, char** argv):
67  _input (new GetPot(argc, argv)),
68  _print (false) {}
69 
74  GetPotWrapper(const std::string& file):
75  _input (new GetPot(file)),
76  _print (false) {
77 
78  }
79 
80  virtual ~GetPotWrapper() {
81  delete _input;
82  }
83 
84 
85  GetPot& get() {
86  return *_input;
87  }
88 
89  void set_print(bool f) {
90  _print = f;
91  }
92 
93 
94  const char* operator()(const std::string& nm, const std::string& doc, const char* v) {
95 
96  if (_print)
97  libMesh::out
98  << nm << " : " << doc
99  << " [Default: v = " << v << " ]" << std::endl;
100 
101  return (*_input)(nm, v);
102  }
103 
104 
105  template <typename ValType>
106  ValType operator()(const std::string& nm, const std::string& doc, const ValType& v) {
107 
108  if (_print)
109  libMesh::out
110  << nm << " : " << doc
111  << " [Default: v = " << v << " ]" << std::endl;
112 
113  return (*_input)(nm, v);
114  }
115 
116  template <typename ValType>
117  ValType operator()(const std::string& nm, const std::string& doc, const ValType& v, const unsigned int i) {
118 
119 
120  if (_print)
121  libMesh::out
122  << "Vector: " << nm << " : " << doc
123  << " [ Default: v(i) = " << v << " ] " << std::endl;
124 
125  return (*_input)(nm, v, i);
126  }
127 
128 
129 protected:
130 
131  GetPot* _input;
132  bool _print;
133 };
134 
135 } // namespace Utility
136 } // namespace MAST
137 
138 #endif // __mast_getpot_wrapper_h__
ValType operator()(const std::string &nm, const std::string &doc, const ValType &v, const unsigned int i)
GetPotWrapper(const std::string &file)
creates a wrapper for the input arguments in the input file named file.
const char * operator()(const std::string &nm, const std::string &doc, const char *v)
GetPotWrapper(const int argc, char **argv)
creates a wrapper around the input arguments given to the executable in argc and argv ...
ValType operator()(const std::string &nm, const std::string &doc, const ValType &v)
GetPotWrapper(const int argc, char **argv, const std::string &input)
Identifies if an input file name is provided in argc by the parameter name input. ...