World Builder  1.1.0-pre
A geodynamic initial conditions generator
array.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  {
28  const unsigned int min_items_,
29  const unsigned int max_items_,
30  const bool unique_items_)
31  :
32  inner_type(type.get_type()),
33  inner_type_ptr(type.clone()),
34  required(false),
35  min_items(min_items_),
36  max_items(max_items_),
37  unique_items(unique_items_)
38  {
40  }
41 
42  Array::Array(Array const &other)
43  :
44  inner_type(other.inner_type),
46  required(other.required),
47  min_items(other.min_items),
48  max_items(other.max_items),
50  {
52  }
53 
54  Array::~Array ()
55  = default;
56 
57 
58  void
60  const std::string &name,
61  const std::string &documentation) const
62  {
63  using namespace rapidjson;
64  Document &declarations = prm.declarations;
65  const std::string &base = prm.get_full_json_path() + "/" + name;
66 
67  Pointer((base + "/type").c_str()).Set(declarations,"array");
68  Pointer((base + "/minItems").c_str()).Set(declarations,min_items);
69  Pointer((base + "/maxItems").c_str()).Set(declarations,max_items);
70  Pointer((base + "/uniqueItems").c_str()).Set(declarations,unique_items);
71  Pointer((base + "/description").c_str()).Set(declarations,documentation.c_str());
72 
73  prm.enter_subsection(name);
74  {
75  WBAssertThrow(this->inner_type_ptr != nullptr, "Internal error, inner pointer is NULL.");
76  this->inner_type_ptr->write_schema(prm, "items", "");
77  }
78  prm.leave_subsection();
79 
80 
81  }
82  } // namespace Types
83 } // namespace WorldBuilder
84 
unsigned int min_items
Definition: array.h:98
virtual std::unique_ptr< Interface > clone() const
Definition: interface.h:71
void enter_subsection(const std::string &name)
Definition: parameters.cc:1871
Array(const Interface &type, const unsigned int min_items=0, const unsigned int max_items=std::numeric_limits< unsigned int >::max(), const bool unique_items=false)
Definition: array.cc:27
std::string get_full_json_path(size_t max_size=std::numeric_limits< size_t >::max()) const
Definition: parameters.cc:1933
std::unique_ptr< Interface > inner_type_ptr
Definition: array.h:87
unsigned int max_items
Definition: array.h:103
#define WBAssertThrow(condition, message)
Definition: assert.h:40
Types::type inner_type
Definition: array.h:76
void write_schema(Parameters &prm, const std::string &name, const std::string &documentation) const override final
Definition: array.cc:59
rapidjson::Document declarations
Definition: parameters.h:248
~Array() override final