Ariles
Loading...
Searching...
No Matches
namevalue2.h
Go to the documentation of this file.
1/**
2 @file
3 @author Alexander Sherikov
4
5 @copyright 2018-2024 Alexander Sherikov, Licensed under the Apache License, Version 2.0.
6 (see @ref LICENSE or http://www.apache.org/licenses/LICENSE-2.0)
7
8 @brief
9*/
10
11/**
12@defgroup namevalue2 NameValue2
13@ingroup config
14
15@brief Generates a set of <std::string, double> pairs with flattened member names,
16e.g., <"ariles_class.class_member.real_member", 3.4>.
17*/
18
19
20#pragma once
21
22#define ARILES2_VISITOR_INCLUDED_namevalue2
23
26
27#include <string>
28#include <memory>
29
30
31namespace ariles2
32{
33 namespace ns_namevalue2
34 {
36 {
37 public:
38 virtual ~NameValueContainer() = default;
39
40 virtual std::string &name(const std::size_t index) = 0;
41 virtual double &value(const std::size_t index) = 0;
42 virtual std::size_t size() const = 0;
43 virtual void reserve(const std::size_t size) = 0;
44 virtual void resize(const std::size_t size) = 0;
45 };
46
47
48 /**
49 * @brief Configuration writer class
50 */
52 public serialization::NodeStackBase<serialization::Node<std::string>>
53 {
54 protected:
56 std::size_t index_;
57 std::shared_ptr<NameValueContainer> name_value_pairs_;
58
59 const std::string separator_ = ".";
60 const std::string bracket_left_ = "{";
61 const std::string bracket_right_ = "}";
62
63
64 public:
65 explicit Writer(const std::shared_ptr<NameValueContainer> &container, const std::size_t reserve = 0);
66 virtual void startRoot(const std::string &name, const Parameters &param);
67 void flush();
68 virtual void startMap(const Parameters &, const std::size_t num_entries);
69 virtual void startMapEntry(const std::string &map_name);
70 virtual void endMapEntry();
71 virtual void endMap();
72 virtual bool startIteratedMap(const std::size_t /*num_entries*/, const Parameters &);
73 virtual void startArray(const std::size_t size, const bool /*compact*/ = false);
74 virtual void endArrayElement();
75 virtual void endArray();
76
77
78#define ARILES2_BASIC_TYPE(type) void writeElement(const type &element, const Parameters &);
79
81
82#undef ARILES2_BASIC_TYPE
83
84
85 void writeElement(const std::string &element, const Parameters &parameters);
86 virtual const Parameters &getDefaultParameters() const;
87 };
88 } // namespace ns_namevalue2
89} // namespace ariles2
90
91
92namespace ariles2
93{
94 /**
95 * @brief NameValue2 visitor.
96 * @ingroup namevalue2
97 */
103} // namespace ariles2
virtual double & value(const std::size_t index)=0
virtual void resize(const std::size_t size)=0
virtual std::size_t size() const =0
virtual std::string & name(const std::size_t index)=0
virtual void reserve(const std::size_t size)=0
Configuration writer class.
Definition namevalue2.h:53
std::shared_ptr< NameValueContainer > name_value_pairs_
Definition namevalue2.h:57
#define ARILES2_BASIC_NUMERIC_TYPES_LIST
Definition helpers.h:63
#define CPPUT_MACRO_SUBSTITUTE(macro)
Definition misc.h:21
NameValue2 visitor.
Definition namevalue2.h:99
#define ARILES2_LOCAL
Definition visibility.h:47