Ginkgo
Generated from branch based on main. Ginkgo version 1.11.0
A numerical linear algebra library targeting many-core architectures
Toggle main menu visibility
Loading...
Searching...
No Matches
property_tree.hpp
1
// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
2
//
3
// SPDX-License-Identifier: BSD-3-Clause
4
5
#ifndef GKO_PUBLIC_CORE_CONFIG_PROPERTY_TREE_HPP_
6
#define GKO_PUBLIC_CORE_CONFIG_PROPERTY_TREE_HPP_
7
8
9
#include <cstdint>
10
#include <limits>
11
#include <map>
12
#include <stdexcept>
13
#include <string>
14
#include <type_traits>
15
#include <vector>
16
17
18
namespace
gko
{
19
namespace
config {
20
21
28
class
pnode
final {
29
public
:
30
using
key_type = std::string;
31
using
map_type = std::map<key_type, pnode>;
32
using
array_type = std::vector<pnode>;
33
37
enum class
tag_t
{ empty,
array
, boolean,
real
, integer, string, map };
38
42
explicit
pnode
();
43
49
explicit
pnode
(
bool
boolean
);
50
58
template
<
typename
T,
59
std::enable_if_t<std::is_integral<T>::value>* =
nullptr
>
60
explicit
pnode
(T integer);
61
67
explicit
pnode
(
const
std::string& str);
68
74
explicit
pnode
(
const
char
* str);
75
81
explicit
pnode
(
double
real
);
82
88
explicit
pnode
(
const
array_type&
array
);
89
95
explicit
pnode
(
const
map_type& map);
96
100
explicit
operator
bool() const noexcept;
101
105
bool
operator==(const
pnode
& rhs) const;
106
110
bool
operator!=(const
pnode
& rhs) const;
111
117
tag_t
get_tag
() const;
118
125
const array_type&
get_array
() const;
126
133
const map_type&
get_map
() const;
134
142
bool
get_boolean
() const;
143
151
std
::int64_t
get_integer
() const;
152
159
double
get_real
() const;
160
167
const
std
::
string
&
get_string
() const;
168
179
const
pnode
&
get
(const
std
::
string
& key) const;
180
189
const
pnode
&
get
(
int
index) const;
190
191
private:
192
void
throw_if_not_contain(
tag_t
tag) const;
193
194
static const
pnode
& empty_node();
195
196
tag_t
tag_;
197
array_type array_;
// for array
198
map_type map_;
// for map
199
// value
200
std
::
string
str_;
201
union {
202
std::int64_t integer_;
203
double
real_;
204
bool
boolean_;
205
} union_data_;
206
};
207
208
209
template <typename T, std::enable_if_t<std::is_integral<T>::value>*>
210
pnode::pnode
(T integer) : tag_(
tag_t
::integer)
211
{
212
if
(integer > std::numeric_limits<std::int64_t>::max() ||
213
(std::is_signed<T>::value &&
214
integer < std::numeric_limits<std::int64_t>::min())) {
215
throw
std::runtime_error(
"The input is out of the range of int64_t."
);
216
}
217
union_data_.integer_ =
static_cast<
std::int64_t
>
(integer);
218
}
219
220
221
}
// namespace config
222
}
// namespace gko
223
224
#endif
// GKO_PUBLIC_CORE_CONFIG_PROPERTY_TREE_HPP_
gko::array
An array is a container which encapsulates fixed-sized arrays, stored on the Executor tied to the arr...
Definition
array.hpp:166
gko::config::pnode::tag_t
tag_t
tag_t is the indicator for the current node storage.
Definition
property_tree.hpp:37
gko::config::pnode::pnode
pnode(const array_type &array)
Constructor for array.
gko::config::pnode::pnode
pnode(const map_type &map)
Constructor for map.
gko::config::pnode::get_boolean
bool get_boolean() const
Access the boolean value stored in this property node.
gko::config::pnode::get_map
const map_type & get_map() const
Access the map stored in this property node.
gko::config::pnode::get_real
double get_real() const
Access the real floating point value stored in this property node.
gko::config::pnode::get
const pnode & get(const std::string &key) const
This function is to access the data under the map.
gko::config::pnode::pnode
pnode(double real)
Constructor for double (and also float).
gko::config::pnode::get_string
const std::string & get_string() const
Access the string stored in this property node.
gko::config::pnode::pnode
pnode(const std::string &str)
Constructor for string.
gko::config::pnode::pnode
pnode(bool boolean)
Constructor for bool.
gko::config::pnode::get_tag
tag_t get_tag() const
Get the current node tag.
gko::config::pnode::pnode
pnode()
Default constructor: create an empty node.
gko::config::pnode::get_array
const array_type & get_array() const
Access the array stored in this property node.
gko::config::pnode::pnode
pnode(const char *str)
Constructor for char* (otherwise, it will use bool).
gko::config::pnode::get_integer
std::int64_t get_integer() const
gko
The Ginkgo namespace.
Definition
abstract_factory.hpp:20
gko::real
constexpr auto real(const T &x)
Returns the real part of the object.
Definition
math.hpp:900
std
STL namespace.
ginkgo
core
config
property_tree.hpp
Generated by
1.18.0