25 #include "pism/util/Grid.hh"
26 #include "pism/util/error_handling.hh"
27 #include "pism/util/pism_utilities.hh"
28 #include "pism/util/ConfigInterface.hh"
29 #include "pism/util/Context.hh"
33 template <
class Model>
42 virtual std::shared_ptr<Model>
create() {
51 auto choices =
split(list,
',');
56 if (choices.empty()) {
58 "Parameter %s (%s) cannot be empty (got '%s')",
62 auto model1 =
m_models.begin()->first;
67 "The first item on the list %s\n"
69 "has to be a 'model' (one of %s),\n"
70 "while the rest have to be 'modifiers' (one of %s).\n"
72 "To use %s you also have to select a model, e.g. using the command-line option\n"
77 opt.c_str(), model1.c_str(), list.c_str());
82 virtual std::shared_ptr<Model>
create(
const std::string &type) {
85 std::vector<std::string> choices =
split(type,
',');
88 auto j = choices.begin();
90 auto result =
model(*j);
95 for (;j != choices.end(); ++j) {
114 template <
typename T>
115 std::string
key_list(std::map<std::string, T> list)
const {
116 std::vector<std::string> keys;
118 for (
const auto &i : list) {
119 keys.push_back(i.first);
122 return "[" +
join(keys,
", ") +
"]";
125 std::shared_ptr<Model>
model(
const std::string &type) {
128 "cannot allocate %s \"%s\".\n"
129 "Available models: %s\n",
137 std::shared_ptr<Model>
modifier(
const std::string &type, std::shared_ptr<T> input) {
140 "cannot allocate %s modifier \"%s\".\n"
141 "Available modifiers: %s\n",
153 virtual std::shared_ptr<Model>
create(std::shared_ptr<const Grid>
g) = 0;
161 std::shared_ptr<Model>
create(std::shared_ptr<const Grid>
g) {
162 return std::shared_ptr<Model>(
new M(
g));
170 virtual std::shared_ptr<Model>
create(std::shared_ptr<const Grid>
g,
171 std::shared_ptr<Model> input) = 0;
180 std::shared_ptr<Model>
create(std::shared_ptr<const Grid>
g, std::shared_ptr<Model> input) {
181 return std::shared_ptr<Model>(
new M(
g, input));
186 std::map<std::string, std::shared_ptr<ModelCreator> >
m_models;
187 std::map<std::string, std::shared_ptr<ModifierCreator> >
m_modifiers;
virtual ~ModelCreator()=default
virtual std::shared_ptr< Model > create(std::shared_ptr< const Grid > g)=0
virtual std::shared_ptr< Model > create(std::shared_ptr< const Grid > g, std::shared_ptr< Model > input)=0
virtual ~ModifierCreator()=default
std::shared_ptr< Model > create(std::shared_ptr< const Grid > g)
std::shared_ptr< Model > create(std::shared_ptr< const Grid > g, std::shared_ptr< Model > input)
std::shared_ptr< Model > modifier(const std::string &type, std::shared_ptr< T > input)
std::shared_ptr< Model > model(const std::string &type)
void add_model(const std::string &name)
Adds a boundary model to the dictionary.
void add_modifier(const std::string &name)
void validate(const std::string &list) const
std::shared_ptr< const Grid > m_grid
std::map< std::string, std::shared_ptr< ModifierCreator > > m_modifiers
std::string key_list(std::map< std::string, T > list) const
virtual std::shared_ptr< Model > create(const std::string &type)
Creates a boundary model.
std::map< std::string, std::shared_ptr< ModelCreator > > m_models
virtual std::shared_ptr< Model > create()
Creates a boundary model. Processes command-line options.
static RuntimeError formatted(const ErrorLocation &location, const char format[],...) __attribute__((format(printf
build a RuntimeError with a formatted message
#define PISM_ERROR_LOCATION
std::string join(const std::vector< std::string > &strings, const std::string &separator)
Concatenate strings, inserting separator between elements.
std::vector< std::string > split(const std::string &input, char separator)
Transform a separator-separated list (a string) into a vector of strings.