Fixposition SDK 0.0.0-heads/main-0-g7b59b93
Collection of c++ libraries and apps for use with Fixposition products
Loading...
Searching...
No Matches
yaml.hpp
Go to the documentation of this file.
1/**
2 * \verbatim
3 * ___ ___
4 * \ \ / /
5 * \ \/ / Copyright (c) Fixposition AG (www.fixposition.com) and contributors
6 * / /\ \ License: see the LICENSE file
7 * /__/ \__\
8 * \endverbatim
9 *
10 * @file
11 * @brief Fixposition SDK: YAML utilities
12 *
13 * @page FPSDK_COMMON_YAML YAML utilities
14 *
15 * **API**: fpsdk_common/yaml.hpp and fpsdk::common::yaml
16 *
17 */
18#ifndef __FPSDK_COMMON_YAML_HPP__
19#define __FPSDK_COMMON_YAML_HPP__
20
21/* LIBC/STL */
22#include <string>
23
24/* EXTERNAL */
25#include <yaml-cpp/yaml.h>
26
27/* PACKAGE */
28
29namespace fpsdk {
30namespace common {
31/**
32 * @brief YAML utilities
33 */
34namespace yaml {
35/* ****************************************************************************************************************** */
36
37/**
38 * @brief Parse YAML string
39 *
40 * @param[in] yaml_str The YAML string
41 * @param[out] yaml_node The parsed YAML node
42 *
43 * @returns true if string was successfully parsed into a YAML node, false otherwise
44 */
45bool StringToYaml(const std::string& yaml_str, YAML::Node& yaml_node);
46
47/**
48 * @brief Stringify YAML node
49 *
50 * @param[in] yaml_node The YAML node to stringfy
51 *
52 * @returns a, possibly empty, stringification of the YAML node
53 */
54std::string YamlToString(const YAML::Node& yaml_node);
55
56/**
57 * @brief Get keys in YAML
58 *
59 * For example, for the yaml node:
60 * key:
61 * foo: 1
62 * bar:
63 * - 1
64 * - 2
65 * baz:
66 * bla: 42
67 *
68 * GetKeysFromYaml(node, "key") would return `[ "bar", "baz", "foo" ]`.
69 *
70 * @param[in] yaml_node The YAML node
71 * @param[in] key The entry in the node to use, can be empty to use the node itself
72 *
73 * @returns an alphabetically ordered list of all keys found in the parameter space, resp. an empty list if the param is
74 * an empty map or not a map
75 */
76std::vector<std::string> GetKeysFromYaml(const YAML::Node& yaml_node, const std::string& key = "");
77
78/* ****************************************************************************************************************** */
79} // namespace yaml
80} // namespace common
81} // namespace fpsdk
82#endif // __FPSDK_COMMON_YAML_HPP__
std::string YamlToString(const YAML::Node &yaml_node)
Stringify YAML node.
bool StringToYaml(const std::string &yaml_str, YAML::Node &yaml_node)
Parse YAML string.
std::vector< std::string > GetKeysFromYaml(const YAML::Node &yaml_node, const std::string &key="")
Get keys in YAML.
Fixposition SDK.
Definition fpsdk_doc.hpp:20