PDI 1.12.0-alpha.2026-05-07

the PDI data interface

paraconf_wrapper.h
1/*******************************************************************************
2 * Copyright (C) 2015-2021 Commissariat a l'energie atomique et aux energies alternatives (CEA)
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of CEA nor the names of its contributors may be used to
13 * endorse or promote products derived from this software without specific
14 * prior written permission.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 ******************************************************************************/
24
28
29#ifndef PDI_PARACONF_WRAPPER_H_
30#define PDI_PARACONF_WRAPPER_H_
31
32#include <functional>
33#include <optional>
34#include <string>
35
36#include <paraconf.h>
37
38#include <pdi/pdi_fwd.h>
39
40namespace PDI {
41
45struct PDI_EXPORT Paraconf_wrapper {
46 PC_errhandler_t m_handler;
47
49
51};
52
55class Yaml_region
56{
57public:
59 struct Yaml_mark {
61 size_t line;
63 size_t column;
64 };
65
66private:
68 std::string m_file;
69
71 Yaml_mark m_start;
72
74 Yaml_mark m_end;
75
82 Yaml_region(PC_tree_t tree);
83
84public:
89 inline const std::string& file() const { return m_file; }
90
95 inline const Yaml_mark& start() const { return m_start; }
96
101 inline const Yaml_mark& end() const { return m_end; }
102
108 static std::optional<Yaml_region> make(PC_tree_t tree);
109};
110
122int PDI_EXPORT len(PC_tree_t tree);
123
136int PDI_EXPORT len(PC_tree_t tree, int dflt);
137
145long PDI_EXPORT to_long(PC_tree_t tree);
146
155long PDI_EXPORT to_long(PC_tree_t tree, long dflt);
156
164double PDI_EXPORT to_double(PC_tree_t tree);
165
174double PDI_EXPORT to_double(PC_tree_t tree, double dflt);
175
183std::string PDI_EXPORT to_string(PC_tree_t tree);
184
193std::string PDI_EXPORT to_string(PC_tree_t tree, const std::string& dflt);
194
202bool PDI_EXPORT to_bool(PC_tree_t tree);
203
212bool PDI_EXPORT to_bool(PC_tree_t tree, bool dflt);
213
214
220bool PDI_EXPORT is_list(PC_tree_t tree);
221
227bool PDI_EXPORT is_map(PC_tree_t tree);
228
234bool PDI_EXPORT is_scalar(PC_tree_t tree);
235
241void PDI_EXPORT each(PC_tree_t tree, std::function<void(PC_tree_t)> operation);
242
249void PDI_EXPORT opt_each(PC_tree_t tree, std::function<void(PC_tree_t)> operation);
250
256void PDI_EXPORT each(PC_tree_t tree, std::function<void(PC_tree_t, PC_tree_t)> operation);
257
264void PDI_EXPORT each_in_omap(PC_tree_t tree, std::function<void(PC_tree_t, PC_tree_t)> operation);
265
266} // namespace PDI
267
268#endif // PDI_PARACONF_WRAPPER_H_
const Yaml_mark & end() const
Gives access to the end location of the region.
Definition paraconf_wrapper.h:101
const Yaml_mark & start() const
Gives access to the start location of the region.
Definition paraconf_wrapper.h:95
const std::string & file() const
Gives access to the "file" where this region resides.
Definition paraconf_wrapper.h:89
size_t line
the line of the location
Definition paraconf_wrapper.h:61
size_t column
the column of the location
Definition paraconf_wrapper.h:63
static std::optional< Yaml_region > make(PC_tree_t tree)
Builds a YAML region that contains a given YAML subtree or nothing if the tree is invalid.
a location in a YAML stream
Definition paraconf_wrapper.h:59
Definition array_datatype.h:38
int len(PC_tree_t tree)
Returns the length of a node.
bool is_list(PC_tree_t tree)
Checks if the tree is a list.
bool to_bool(PC_tree_t tree)
Returns the boolean value of a scalar node.
void opt_each(PC_tree_t tree, std::function< void(PC_tree_t)> operation)
Iterates and apply the provided function to all elements of a PC list or directly to the provided ele...
void each_in_omap(PC_tree_t tree, std::function< void(PC_tree_t, PC_tree_t)> operation)
Iterates and apply the provided function to all elements of a PC ordered mapping.
bool is_map(PC_tree_t tree)
Checks if the tree is a map.
double to_double(PC_tree_t tree)
Returns the floating point value of a scalar node.
void each(PC_tree_t tree, std::function< void(PC_tree_t)> operation)
Iterates and apply the provided function to all elements of a PC list.
long to_long(PC_tree_t tree)
Returns the int value of a scalar node.
bool is_scalar(PC_tree_t tree)
Checks if the tree is a scalar.
std::string to_string(PC_tree_t tree)
Returns the string content of a scalar node.
PC_errhandler_t m_handler
Definition paraconf_wrapper.h:46