PISM, A Parallel Ice Sheet Model  stable v2.1-1-g6902d5502 committed by Ed Bueler on 2023-12-20 08:38:27 -0800
pism_options.hh
Go to the documentation of this file.
1 // Copyright (C) 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2021, 2023 PISM Authors
2 //
3 // This file is part of PISM.
4 //
5 // PISM is free software; you can redistribute it and/or modify it under the
6 // terms of the GNU General Public License as published by the Free Software
7 // Foundation; either version 3 of the License, or (at your option) any later
8 // version.
9 //
10 // PISM is distributed in the hope that it will be useful, but WITHOUT ANY
11 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 // details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with PISM; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 
19 #ifndef PISM_OPTIONS_H
20 #define PISM_OPTIONS_H
21 
22 #include <memory>
23 #include <set>
24 #include <string>
25 #include <vector>
26 
27 #include "pism/util/options.hh"
28 
29 namespace pism {
30 
31 namespace units {
32 class System;
33 } // end of namespace units
34 
35 class Config;
36 class Logger;
37 
38 void show_usage(const Logger &log, const std::string &execname, const std::string &usage);
39 
40 //! @brief Returns true if PISM should terminate after printing some
41 //! messages to stdout.
42 bool show_usage_check_req_opts(const Logger &log,
43  const std::string &execname,
44  const std::vector<std::string> &required_options,
45  const std::string &usage);
46 
47 
48 //! Utilities for processing command-line options.
49 namespace options {
50 
52 
53 class String : public Option<std::string> {
54 public:
55  // there is no reasonable default; if the option is set, it has to
56  // have a non-empty argument
57  String(const std::string& option,
58  const std::string& description);
59  // there is a reasonable default
60  String(const std::string& option,
61  const std::string& description,
62  const std::string& default_value,
64 private:
65  int process(const std::string& option,
66  const std::string& description,
67  const std::string& default_value,
68  ArgumentFlag flag);
69 };
70 
71 class Keyword : public Option<std::string> {
72 public:
73  Keyword(const std::string& option,
74  const std::string& description,
75  const std::string& choices,
76  const std::string& default_value);
77 };
78 
79 class Integer : public Option<int> {
80 public:
81  Integer(const std::string& option,
82  const std::string& description,
83  int default_value);
84 };
85 
86 class IntegerList : public Option<std::vector<int> > {
87 public:
88  IntegerList(const std::string& option,
89  const std::string& description,
90  const std::vector<int> &defaults);
91  const int& operator[](size_t index) const;
92 };
93 
94 class Real : public Option<double> {
95 public:
96  Real(std::shared_ptr<units::System> system,
97  const std::string& option,
98  const std::string& description,
99  const std::string& units,
100  double default_value);
101 };
102 
103 class RealList : public Option<std::vector<double> > {
104 public:
105  RealList(const std::string& option,
106  const std::string& description,
107  const std::vector<double> &default_value);
108  const double& operator[](size_t index) const;
109 };
110 
111 bool Bool(const std::string& option,
112  const std::string& description);
113 
114 void deprecated(const std::string &old_name, const std::string &new_name);
115 void ignored(const Logger &log, const std::string &name);
116 void forbidden(const std::string &name);
117 } // end of namespace options
118 
119 } // end of namespace pism
120 
121 #endif /* PISM_OPTIONS_H */
A basic logging class.
Definition: Logger.hh:40
IntegerList(const std::string &option, const std::string &description, const std::vector< int > &defaults)
Definition: options.cc:160
const int & operator[](size_t index) const
Definition: options.cc:185
Integer(const std::string &option, const std::string &description, int default_value)
Definition: options.cc:136
Keyword(const std::string &option, const std::string &description, const std::string &choices, const std::string &default_value)
Definition: options.cc:95
Template base class used by PISM's option-processing classes.
Definition: options.hh:30
RealList(const std::string &option, const std::string &description, const std::vector< double > &default_value)
Definition: options.cc:221
const double & operator[](size_t index) const
Definition: options.cc:236
Real(std::shared_ptr< units::System > system, const std::string &option, const std::string &description, const std::string &units, double default_value)
Definition: options.cc:189
String(const std::string &option, const std::string &description)
Definition: options.cc:33
int process(const std::string &option, const std::string &description, const std::string &default_value, ArgumentFlag flag)
Definition: options.cc:53
void deprecated(const std::string &old_name, const std::string &new_name)
Stop if an option old_name is set, printing a message that new_name should be used instead.
Definition: options.cc:246
bool Bool(const std::string &option, const std::string &description)
Definition: options.cc:240
void ignored(const Logger &log, const std::string &name)
Print a warning telling the user that an option was ignored.
Definition: options.cc:259
void forbidden(const std::string &name)
Stop if an option name is set.
Definition: options.cc:270
void show_usage(const Logger &log, const std::string &execname, const std::string &usage)
Print a usage message.
Definition: pism_options.cc:30
bool show_usage_check_req_opts(const Logger &log, const std::string &execname, const std::vector< std::string > &required_options, const std::string &usage)
In a single call a driver program can provide a usage string to the user and check if required option...
Definition: pism_options.cc:51