World Builder  1.1.0-pre
A geodynamic initial conditions generator
one_of.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 
22 
23 namespace WorldBuilder
24 {
25  namespace Types
26  {
27  OneOf::OneOf(const Interface &type_1,
28  const Interface &type_2)
29  {
31  inner_types_ptr.emplace_back(type_1.clone());
32  inner_types_ptr.emplace_back(type_2.clone());
33 
34  }
35 
36  OneOf::OneOf(OneOf const &other)
37  {
39  for (const auto &i : other.inner_types_ptr)
40  {
41  inner_types_ptr.emplace_back(i->clone());
42  }
43  }
44 
45  OneOf::~OneOf ()
46  = default;
47 
48 
49  void
51  const std::string &name,
52  const std::string &documentation) const
53  {
54  using namespace rapidjson;
55  Document &declarations = prm.declarations;
56  const std::string &base = prm.get_full_json_path() + "/" + name;
57 
58  prm.enter_subsection(name);
59  {
60  Pointer((base + "/description").c_str()).Set(declarations,documentation.c_str());
61  prm.enter_subsection("oneOf");
62  {
63  for (size_t i = 0; i < inner_types_ptr.size(); i++)
64  {
65  WBAssertThrow(inner_types_ptr[i] != nullptr, "Internal error, inner pointer is NULL.");
66  inner_types_ptr[i]->write_schema(prm, std::to_string(i), "");
67  }
68  }
69  prm.leave_subsection();
70  }
71  prm.leave_subsection();
72 
73 
74  }
75  } // namespace Types
76 } // namespace WorldBuilder
77 
OneOf(const Interface &type_1, const Interface &type_2)
Definition: one_of.cc:27
virtual std::unique_ptr< Interface > clone() const
Definition: interface.h:71
std::vector< std::unique_ptr< Interface > > inner_types_ptr
Definition: one_of.h:78
void enter_subsection(const std::string &name)
Definition: parameters.cc:1871
void write_schema(Parameters &prm, const std::string &name, const std::string &documentation) const override final
Definition: one_of.cc:50
std::string get_full_json_path(size_t max_size=std::numeric_limits< size_t >::max()) const
Definition: parameters.cc:1933
#define WBAssertThrow(condition, message)
Definition: assert.h:40
~OneOf() override final
rapidjson::Document declarations
Definition: parameters.h:248