27template <
typename T>
concept _arithmetic = std::is_arithmetic_v<T>;
68 std::variant<long long, double, std::string> m_value;
95 template <_arithmetic T>
98 if (std::holds_alternative<long long>(m_value)) {
99 return static_cast<T>(std::get<long long>(m_value));
100 }
else if (std::holds_alternative<double>(m_value)) {
101 return static_cast<T>(std::get<double>(m_value));
104 throw std::runtime_error(
"Number is stored as a string.");
117 std::optional<std::string> m_type_annotation;
124 const std::optional<std::string>&
type_annotation()
const {
return m_type_annotation; }
148 std::variant<std::monostate, bool, Number, std::string> m_value;
168 m_value{
std::move(
s)}
173 m_value{
std::move(
n)}
178 m_value{
std::move(
n)}
198 m_value = std::string{
s};
204 m_value = std::move(
s);
216 m_value = std::move(
n);
235 if (std::holds_alternative<Number>(m_value)) {
236 return std::get<Number>(m_value);
238 throw TypeError{
"Value is not a number"};
244 if (std::holds_alternative<std::string>(m_value)) {
245 return std::get<std::string>(m_value);
247 throw TypeError{
"Value is not a string"};
253 if (std::holds_alternative<bool>(m_value)) {
254 return std::get<bool>(m_value);
256 throw TypeError{
"Value is not a boolean"};
262 return std::holds_alternative<std::monostate>(m_value);
270 std::optional<std::string> m_type_annotation;
272 std::vector<Value> m_args;
273 std::map<std::string, Value, std::less<>> m_properties;
274 std::vector<Node> m_children;
287 std::vector<Value>
args,
297 std::string_view
name,
298 std::vector<Value>
args,
312 std::string
const&
name()
const {
return m_name; }
315 const std::vector<Value>&
args()
const {
return m_args; }
316 std::vector<Value>&
args() {
return m_args; }
317 const std::map<std::string, Value, std::less<>>&
properties()
const {
return m_properties; }
318 std::map<std::string, Value, std::less<>>&
properties() {
return m_properties; }
319 const std::vector<Node>&
children()
const {
return m_children; }
320 std::vector<Node>&
children() {
return m_children; }
325 std::vector<Node> m_nodes;
339 const std::vector<Node>&
nodes()
const {
return m_nodes; }
340 std::vector<Node>&
nodes() {
return m_nodes; }
342 auto begin()
const {
return m_nodes.begin(); }
343 auto begin() {
return m_nodes.begin(); }
344 auto end()
const {
return m_nodes.end(); }
345 auto end() {
return m_nodes.end(); }
Document(Document &&)=default
const std::vector< Node > & nodes() const
std::vector< Node > & nodes()
std::string to_string() const
Document & operator=(Document &&)=default
Document(Document const &)=default
Document & operator=(Document const &)=default
Document(std::vector< Node > nodes)
static Document read_from(kdl_parser *parser)
std::string to_string(KdlVersion version) const
Document(std::initializer_list< Node > nodes)
const char * what() const noexcept
EmitterError(std::string msg)
void remove_type_annotation()
HasTypeAnnotation(std::string_view t)
void set_type_annotation(std::string_view type_annotation)
bool operator!=(const HasTypeAnnotation &) const =default
bool operator==(const HasTypeAnnotation &) const =default
HasTypeAnnotation()=default
const std::optional< std::string > & type_annotation() const
Node & operator=(Node &&)=default
std::vector< Value > & args()
Node(std::string_view type_annotation, std::string_view name, std::vector< Value > args, std::map< std::string, Value, std::less<> > properties, std::vector< Node > children)
const std::vector< Value > & args() const
Node & operator=(Node const &)=default
Node(Node const &)=default
std::vector< Node > & children()
const std::map< std::string, Value, std::less<> > & properties() const
Node(std::string_view name, std::vector< Value > args, std::map< std::string, Value, std::less<> > properties, std::vector< Node > children)
std::map< std::string, Value, std::less<> > & properties()
std::string const & name() const
void set_name(std::string_view name)
Node(std::string_view name)
const std::vector< Node > & children() const
Node(std::string_view type_annotation, std::string_view name)
Number(const kdl_number &n)
Number & operator=(Number &&)=default
Number(Number &&)=default
Number(Number const &)=default
bool operator!=(const Number &) const =default
Number & operator=(Number const &)=default
NumberRepresentation representation() const noexcept
bool operator==(const Number &) const =default
ParseError(kdl_str const &msg)
const char * what() const noexcept
ParseError(std::string msg)
const char * what() const noexcept
TypeError(const char *msg)
Value(std::string_view type_annotation, std::string s)
Value & operator=(bool b)
Value(std::string_view type_annotation, bool b)
Value & operator=(Value &&)=default
Value & operator=(Number const &n)
Value(std::string_view type_annotation, std::string_view s)
bool operator==(const Value &) const =default
Value & operator=(Value const &)=default
Value & operator=(_into_number auto n)
Value(Value const &)=default
Value(std::string_view type_annotation, Number n)
Value(kdl_value const &val)
bool operator!=(const Value &) const =default
const Number & as_number() const
Type type() const noexcept
Value & operator=(Number &&n)
Value(_into_number auto n)
Value(std::string_view type_annotation, _into_number auto n)
static Value from_string(std::string_view s)
Value(std::string_view s)
const std::string & as_string() const
Value & operator=(std::string_view s)
Value & operator=(std::string s)
struct kdl_number kdl_number
struct _kdl_parser kdl_parser
struct kdl_value kdl_value
Document parse(std::string_view kdl_text)
A (inclusive) range between two values.