World Builder  1.1.0-pre
A geodynamic initial conditions generator
plugin_system.cc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2018-2024 by the authors of the World Builder code.
3 
4  This file is part of the World Builder.
5 
6  This program is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Lesser General Public License as published
8  by the Free Software Foundation, either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public License
17  along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
20 
21 
22 
23 namespace WorldBuilder
24 {
25  namespace Types
26  {
27  PluginSystem::PluginSystem(std::string default_value_,
28  void ( *declare_entries_)(Parameters &, const std::string &, const std::vector<std::string> &),
29  std::vector<std::string> required_entries_,
30  const bool allow_multiple_)
31  :
32  default_value(std::move(default_value_)),
33  declare_entries(declare_entries_),
34  required_entries(std::move(required_entries_)),
35  allow_multiple(allow_multiple_)
36  {
38 
39  WBAssert(declare_entries_ != nullptr, "declare entries may not be a null pointer.");
40  }
41 
42 
44  :
45  default_value(plugin_system.default_value),
46  declare_entries(plugin_system.declare_entries),
47  required_entries(plugin_system.required_entries),
48  allow_multiple(plugin_system.allow_multiple)
49  {
51  }
52 
54  = default;
55 
56  void
58  const std::string &name,
59  const std::string &documentation) const
60  {
61  using namespace rapidjson;
62 
63  prm.enter_subsection(name);
64  {
65  const std::string path = prm.get_full_json_path();
66  Pointer((path + "/description").c_str()).Set(prm.declarations,documentation.c_str());
67  Pointer((path + "/default value").c_str()).Set(prm.declarations,default_value.c_str());
68 
69  if (allow_multiple)
70  {
71  Pointer((path + "/type").c_str()).Set(prm.declarations,"array");
72 
73  prm.enter_subsection("items");
74  {
75  WBAssert(this->declare_entries != nullptr, "No declare entries given.");
76 
77  this->declare_entries(prm, name, required_entries);
78  }
79  prm.leave_subsection();
80  }
81  else
82  {
83  Pointer((path + "/type").c_str()).Set(prm.declarations,"object");
84 
85  WBAssert(this->declare_entries != nullptr, "No declare entries given.");
86  this->declare_entries(prm, name, required_entries);
87 
88 
89  }
90  }
91  prm.leave_subsection();
92  }
93  } // namespace Types
94 } // namespace WorldBuilder
95 
void enter_subsection(const std::string &name)
Definition: parameters.cc:1871
std::vector< std::string > required_entries
Definition: plugin_system.h:70
void write_schema(Parameters &prm, const std::string &name, const std::string &documentation) const override final
#define WBAssert(condition, message)
Definition: assert.h:27
std::string get_full_json_path(size_t max_size=std::numeric_limits< size_t >::max()) const
Definition: parameters.cc:1933
PluginSystem(std::string default_value_, void(*declare_entries)(Parameters &, const std::string &, const std::vector< std::string > &), std::vector< std::string > required_entries, const bool allow_multiple=true)
void(* declare_entries)(Parameters &, const std::string &, const std::vector< std::string > &)
Definition: plugin_system.h:69
rapidjson::Document declarations
Definition: parameters.h:248