rapidyaml  0.7.2
parse and emit YAML, and do it fast
tag.hpp
Go to the documentation of this file.
1 #ifndef _C4_YML_TAG_HPP_
2 #define _C4_YML_TAG_HPP_
3 
4 #include <c4/yml/common.hpp>
5 
6 namespace c4 {
7 namespace yml {
8 
9 class Tree;
10 
11 /** @addtogroup doc_tag_utils
12  *
13  * @{
14  */
15 
16 
17 #ifndef RYML_MAX_TAG_DIRECTIVES
18 /** the maximum number of tag directives in a Tree */
19 #define RYML_MAX_TAG_DIRECTIVES 4
20 #endif
21 
22 /** the integral type necessary to cover all the bits marking node tags */
23 using tag_bits = uint16_t;
24 
25 /** a bit mask for marking tags for types */
26 typedef enum : tag_bits {
27  TAG_NONE = 0,
28  // container types
29  TAG_MAP = 1, /**< !!map Unordered set of key: value pairs without duplicates. @see https://yaml.org/type/map.html */
30  TAG_OMAP = 2, /**< !!omap Ordered sequence of key: value pairs without duplicates. @see https://yaml.org/type/omap.html */
31  TAG_PAIRS = 3, /**< !!pairs Ordered sequence of key: value pairs allowing duplicates. @see https://yaml.org/type/pairs.html */
32  TAG_SET = 4, /**< !!set Unordered set of non-equal values. @see https://yaml.org/type/set.html */
33  TAG_SEQ = 5, /**< !!seq Sequence of arbitrary values. @see https://yaml.org/type/seq.html */
34  // scalar types
35  TAG_BINARY = 6, /**< !!binary A sequence of zero or more octets (8 bit values). @see https://yaml.org/type/binary.html */
36  TAG_BOOL = 7, /**< !!bool Mathematical Booleans. @see https://yaml.org/type/bool.html */
37  TAG_FLOAT = 8, /**< !!float Floating-point approximation to real numbers. https://yaml.org/type/float.html */
38  TAG_INT = 9, /**< !!float Mathematical integers. https://yaml.org/type/int.html */
39  TAG_MERGE = 10, /**< !!merge Specify one or more mapping to be merged with the current one. https://yaml.org/type/merge.html */
40  TAG_NULL = 11, /**< !!null Devoid of value. https://yaml.org/type/null.html */
41  TAG_STR = 12, /**< !!str A sequence of zero or more Unicode characters. https://yaml.org/type/str.html */
42  TAG_TIMESTAMP = 13, /**< !!timestamp A point in time https://yaml.org/type/timestamp.html */
43  TAG_VALUE = 14, /**< !!value Specify the default value of a mapping https://yaml.org/type/value.html */
44  TAG_YAML = 15, /**< !!yaml Specify the default value of a mapping https://yaml.org/type/yaml.html */
45 } YamlTag_e;
46 
47 RYML_EXPORT YamlTag_e to_tag(csubstr tag);
48 RYML_EXPORT csubstr from_tag(YamlTag_e tag);
50 RYML_EXPORT csubstr normalize_tag(csubstr tag);
51 RYML_EXPORT csubstr normalize_tag_long(csubstr tag);
52 RYML_EXPORT csubstr normalize_tag_long(csubstr tag, substr output);
53 
54 RYML_EXPORT bool is_custom_tag(csubstr tag);
55 
56 
58 {
59  /** Eg `!e!` in `%TAG !e! tag:example.com,2000:app/` */
60  csubstr handle;
61  /** Eg `tag:example.com,2000:app/` in `%TAG !e! tag:example.com,2000:app/` */
62  csubstr prefix;
63  /** The next node to which this tag directive applies */
65 
66  bool create_from_str(csubstr directive_); ///< leaves next_node_id unfilled
67  bool create_from_str(csubstr directive_, Tree *tree);
68  size_t transform(csubstr tag, substr output, Callbacks const& callbacks) const;
69 };
70 
72 {
73  TagDirective const* C4_RESTRICT b;
74  TagDirective const* C4_RESTRICT e;
75  C4_ALWAYS_INLINE TagDirective const* begin() const noexcept { return b; }
76  C4_ALWAYS_INLINE TagDirective const* end() const noexcept { return e; }
77 };
78 
79 /** @} */
80 
81 } // namespace yml
82 } // namespace c4
83 
84 #endif /* _C4_YML_TAG_HPP_ */
Common utilities and infrastructure used by ryml.
#define RYML_EXPORT
Definition: export.hpp:15
csubstr from_tag_long(YamlTag_e tag)
Definition: tag.cpp:123
bool is_custom_tag(csubstr tag)
Definition: tag.cpp:9
csubstr normalize_tag_long(csubstr tag)
Definition: tag.cpp:31
YamlTag_e
a bit mask for marking tags for types
Definition: tag.hpp:26
csubstr normalize_tag(csubstr tag)
Definition: tag.cpp:19
uint16_t tag_bits
the integral type necessary to cover all the bits marking node tags
Definition: tag.hpp:23
csubstr from_tag(YamlTag_e tag)
Definition: tag.cpp:163
YamlTag_e to_tag(csubstr tag)
Definition: tag.cpp:67
@ TAG_SET
!!set Unordered set of non-equal values.
Definition: tag.hpp:32
@ TAG_MERGE
!!merge Specify one or more mapping to be merged with the current one.
Definition: tag.hpp:39
@ TAG_INT
!!float Mathematical integers.
Definition: tag.hpp:38
@ TAG_SEQ
!!seq Sequence of arbitrary values.
Definition: tag.hpp:33
@ TAG_NULL
!!null Devoid of value.
Definition: tag.hpp:40
@ TAG_YAML
!!yaml Specify the default value of a mapping https://yaml.org/type/yaml.html
Definition: tag.hpp:44
@ TAG_TIMESTAMP
!!timestamp A point in time https://yaml.org/type/timestamp.html
Definition: tag.hpp:42
@ TAG_NONE
Definition: tag.hpp:27
@ TAG_STR
!!str A sequence of zero or more Unicode characters.
Definition: tag.hpp:41
@ TAG_BOOL
!!bool Mathematical Booleans.
Definition: tag.hpp:36
@ TAG_MAP
!!map Unordered set of key: value pairs without duplicates.
Definition: tag.hpp:29
@ TAG_BINARY
!!binary A sequence of zero or more octets (8 bit values).
Definition: tag.hpp:35
@ TAG_PAIRS
!!pairs Ordered sequence of key: value pairs allowing duplicates.
Definition: tag.hpp:31
@ TAG_VALUE
!!value Specify the default value of a mapping https://yaml.org/type/value.html
Definition: tag.hpp:43
@ TAG_OMAP
!!omap Ordered sequence of key: value pairs without duplicates.
Definition: tag.hpp:30
@ TAG_FLOAT
!!float Floating-point approximation to real numbers.
Definition: tag.hpp:37
RYML_ID_TYPE id_type
The type of a node id in the YAML tree; to override the default type, define the macro RYML_ID_TYPE t...
Definition: common.hpp:252
Definition: common.cpp:12
a c-style callbacks class.
Definition: common.hpp:375
TagDirective const * b
Definition: tag.hpp:73
TagDirective const * begin() const noexcept
Definition: tag.hpp:75
TagDirective const * end() const noexcept
Definition: tag.hpp:76
TagDirective const * e
Definition: tag.hpp:74
csubstr handle
Eg !e! in TAG !e! tag:example.com,2000:app/
Definition: tag.hpp:60
id_type next_node_id
The next node to which this tag directive applies.
Definition: tag.hpp:64
csubstr prefix
Eg tag:example.com,2000:app/ in TAG !e! tag:example.com,2000:app/
Definition: tag.hpp:62