PDI 1.13.0

the PDI data interface

paraconf_wrapper.h
1/*******************************************************************************
2 * Copyright (C) 2015-2026 Commissariat a l'energie atomique et aux energies alternatives (CEA)
3 * Copyright (C) 2026 Julien Bigot <julien@julien-bigot.fr>
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of CEA nor the names of its contributors may be used to
14 * endorse or promote products derived from this software without specific
15 * prior written permission.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 * THE SOFTWARE.
24 ******************************************************************************/
25
29
30#ifndef PDI_PARACONF_WRAPPER_H_
31#define PDI_PARACONF_WRAPPER_H_
32
33#include <functional>
34#include <optional>
35#include <string>
36
37#include <paraconf.h>
38
39#include <pdi/pdi_fwd.h>
40
41namespace PDI {
42
46struct PDI_EXPORT Paraconf_wrapper {
47 PC_errhandler_t m_handler;
48
50
52};
53
56class PDI_EXPORT Yaml_region
57{
58public:
60 struct Yaml_mark {
62 size_t line;
64 size_t column;
65 };
66
67private:
69 std::string m_file;
70
72 Yaml_mark m_start;
73
75 Yaml_mark m_end;
76
83 Yaml_region(PC_tree_t tree);
84
85public:
90 inline const std::string& file() const { return m_file; }
91
96 inline const Yaml_mark& start() const { return m_start; }
97
102 inline const Yaml_mark& end() const { return m_end; }
103
109 static std::optional<Yaml_region> make(PC_tree_t tree);
110};
111
117std::string PDI_EXPORT to_string(Yaml_region location);
118
124std::string PDI_EXPORT to_string(std::optional<Yaml_region> location);
125
137int PDI_EXPORT len(PC_tree_t tree);
138
151int PDI_EXPORT len(PC_tree_t tree, int dflt);
152
160long PDI_EXPORT to_long(PC_tree_t tree);
161
170long PDI_EXPORT to_long(PC_tree_t tree, long dflt);
171
179double PDI_EXPORT to_double(PC_tree_t tree);
180
189double PDI_EXPORT to_double(PC_tree_t tree, double dflt);
190
198std::string PDI_EXPORT to_string(PC_tree_t tree);
199
208std::string PDI_EXPORT to_string(PC_tree_t tree, const std::string& dflt);
209
219bool PDI_EXPORT to_bool(PC_tree_t tree);
220
230bool PDI_EXPORT to_bool(PC_tree_t tree, bool dflt);
231
232
238bool PDI_EXPORT is_list(PC_tree_t tree);
239
245bool PDI_EXPORT is_map(PC_tree_t tree);
246
252bool PDI_EXPORT is_scalar(PC_tree_t tree);
253
259void PDI_EXPORT each(PC_tree_t tree, std::function<void(PC_tree_t)> operation);
260
267void PDI_EXPORT opt_each(PC_tree_t tree, std::function<void(PC_tree_t)> operation);
268
274void PDI_EXPORT each(PC_tree_t tree, std::function<void(PC_tree_t, PC_tree_t)> operation);
275
282void PDI_EXPORT each_in_omap(PC_tree_t tree, std::function<void(PC_tree_t, PC_tree_t)> operation);
283
284} // namespace PDI
285
286#endif // PDI_PARACONF_WRAPPER_H_
A region in a YAML "file", from start to end.
Definition paraconf_wrapper.h:57
const Yaml_mark & end() const
Gives access to the end location of the region.
Definition paraconf_wrapper.h:102
const Yaml_mark & start() const
Gives access to the start location of the region.
Definition paraconf_wrapper.h:96
const std::string & file() const
Gives access to the "file" where this region resides.
Definition paraconf_wrapper.h:90
size_t line
the line of the location
Definition paraconf_wrapper.h:62
size_t column
the column of the location
Definition paraconf_wrapper.h:64
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:60
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.
std::string to_string(Yaml_region location)
Converts a Yaml region into a string representation for debugging purpose.
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.
PC_errhandler_t m_handler
Definition paraconf_wrapper.h:47