rapidyaml 0.14.0
parse and emit YAML, and do it fast
Loading...
Searching...
No Matches
common.hpp
Go to the documentation of this file.
1#ifndef _C4_YML_COMMON_HPP_
2#define _C4_YML_COMMON_HPP_
3
4/** @file common.hpp Common utilities and infrastructure used by ryml. */
5
6#include <cstddef>
7#include <c4/substr.hpp>
8#include <c4/charconv.hpp>
9#include <c4/yml/export.hpp>
10
11
12//-----------------------------------------------------------------------------
13
14#ifndef RYML_DEFAULT_TREE_CAPACITY
15/// default capacity for the tree when not set explicitly
16#define RYML_DEFAULT_TREE_CAPACITY (16)
17#endif
18
19#ifndef RYML_DEFAULT_TREE_ARENA_CAPACITY
20/// default capacity for the tree's arena when not set explicitly
21#define RYML_DEFAULT_TREE_ARENA_CAPACITY (0)
22#endif
23
24
25#ifndef RYML_LOCATIONS_SMALL_THRESHOLD
26/// threshold at which a location search will revert from linear to
27/// binary search.
28#define RYML_LOCATIONS_SMALL_THRESHOLD (30)
29#endif
30
31
32#ifndef RYML_ERRMSG_SIZE
33/// size for the error message buffer
34#define RYML_ERRMSG_SIZE (1024)
35#endif
36
37
38#ifndef RYML_LOGBUF_SIZE
39/// size for the buffer used to format individual values to string
40/// while preparing an error message. This is only used for formatting
41/// individual values in the message; final messages will be larger
42/// than this value (see @ref RYML_ERRMSG_SIZE). This is also used for
43/// the detailed debug log messages when RYML_DBG is defined.
44#define RYML_LOGBUF_SIZE (256)
45#endif
46
47
48#ifndef RYML_LOGBUF_SIZE
49/// size for the buffer used to format individual values to string
50/// while preparing an error message. This is only used for formatting
51/// individual values in the message; final messages will be larger
52/// than this value (see @ref RYML_ERRMSG_SIZE). This size is also
53/// used for the detailed debug log messages when RYML_DBG is defined.
54#define RYML_LOGBUF_SIZE (256)
55#endif
56static_assert(RYML_LOGBUF_SIZE < RYML_ERRMSG_SIZE, "invalid size");
57
58
59#ifndef RYML_LOGBUF_SIZE_MAX
60/// size for the fallback larger log buffer. When @ref
61/// RYML_LOGBUF_SIZE is not large enough to convert a value to string,
62/// then temporary stack memory is allocated up to
63/// RYML_LOGBUF_SIZE_MAX. This limit is in place to prevent a stack
64/// overflow. If the printed value requires more than
65/// RYML_LOGBUF_SIZE_MAX, the value is silently skipped.
66#define RYML_LOGBUF_SIZE_MAX (1024)
67#endif
68
69
70//-----------------------------------------------------------------------------
71// Specify groups to have a predefined topic order in doxygen:
72
73/** @defgroup doc_quickstart Quickstart
74 *
75 * Example code for every feature.
76 */
77
78/** @defgroup doc_parse Parse utilities
79 * @see sample::sample_parse_in_place
80 * @see sample::sample_parse_in_arena
81 * @see sample::sample_parse_file
82 * @see sample::sample_parse_reuse_tree
83 * @see sample::sample_parse_reuse_parser
84 * @see sample::sample_parse_reuse_tree_and_parser
85 * @see sample::sample_location_tracking
86 */
87
88/** @defgroup doc_emit Emit utilities
89 *
90 * Utilities to emit YAML and JSON, either to a memory buffer or to a
91 * file or ostream-like class.
92 *
93 * @see sample::sample_emit_to_container
94 * @see sample::sample_emit_to_stream
95 * @see sample::sample_emit_to_file
96 * @see sample::sample_emit_nested_node
97 * @see sample::sample_emit_style
98 */
99
100/** @defgroup doc_node_type Node types
101 */
102
103/** @defgroup doc_tree Tree utilities
104 * @see sample::sample_quick_overview
105 * @see sample::sample_iterate_trees
106 * @see sample::sample_create_trees
107 * @see sample::sample_tree_arena
108 *
109 * @see sample::sample_static_trees
110 * @see sample::sample_location_tracking
111 *
112 * @see sample::sample_docs
113 * @see sample::sample_anchors_and_aliases
114 * @see sample::sample_tags
115 */
116
117/** @defgroup doc_node_classes Node classes
118 *
119 * High-level node classes.
120 *
121 * @see sample::sample_quick_overview
122 * @see sample::sample_iterate_trees
123 * @see sample::sample_create_trees
124 * @see sample::sample_tree_arena
125 */
126
127/** @defgroup doc_error_handling Error handling
128 *
129 * Utilities to report handle errors, and to build and report error
130 * messages.
131 *
132 * @see sample::sample_error_handler
133 */
134
135/** @defgroup doc_callbacks Callbacks for errors and allocation
136 *
137 * Functions called by ryml to allocate/free memory and to report
138 * errors.
139 *
140 * @see sample::sample_error_handler
141 * @see sample::sample_global_allocator
142 * @see sample::sample_per_tree_allocator
143 */
144
145/** @defgroup doc_serialization Serialization/deserialization
146 *
147 * Contains information on how to serialize and deserialize
148 * fundamental types, user scalar types, user container types and
149 * interop with std scalar/container types.
150 *
151 */
152
153/** @defgroup doc_ref_utils Anchor/Reference utilities
154 *
155 * @see sample::sample_anchors_and_aliases
156 * */
157
158/** @defgroup doc_tag_utils Tag utilities
159 * @see sample::sample_tags
160 */
161
162/** @defgroup doc_preprocessors Preprocessors
163 *
164 * Functions for preprocessing YAML prior to parsing.
165 */
166
167/** @defgroup doc_file_utils File utils
168 *
169 * Functions for loading/saving a file from/to disk.
170 */
171
172
173//-----------------------------------------------------------------------------
174
175// document macros for doxygen
176#ifdef __DOXYGEN__ // defined in Doxyfile::PREDEFINED
177
178/** define this macro with a boolean value to enable/disable
179 * assertions to check preconditions and assumptions throughout the
180 * codebase; this causes a slowdown of the code, and larger code
181 * size. By default, this macro is defined unless NDEBUG is defined
182 * (see C4_USE_ASSERT); as a result, by default this macro is truthy
183 * only in debug builds. */
184# define RYML_USE_ASSERT
185
186/** (Undefined by default) Define this macro to disable ryml's default
187 * implementation of the callback functions. See @ref doc_callbacks. */
188# define RYML_NO_DEFAULT_CALLBACKS
189
190/** (Undefined by default) When this macro is defined (and
191 * @ref RYML_NO_DEFAULT_CALLBACKS is not defined), the default error
192 * handler will throw exceptions. See @ref doc_error_handling. */
193# define RYML_DEFAULT_CALLBACK_USES_EXCEPTIONS
194
195/** Conditionally expands to `noexcept` when @ref RYML_USE_ASSERT is 0 and
196 * is empty otherwise. The user is unable to override this macro. */
197# define RYML_NOEXCEPT
198
199/** (Undefined by default) Use shorter error message from
200 * checks/asserts: do not show the check condition in the error
201 * message. */
202# defined RYML_SHORT_CHECK_MSG
203
204#endif
205
206
207//-----------------------------------------------------------------------------
208
209/** @cond dev */
210
211#ifndef RYML_USE_ASSERT
212# define RYML_USE_ASSERT C4_USE_ASSERT
213#endif
214
215#if RYML_USE_ASSERT
216# define RYML_NOEXCEPT
217#else
218# define RYML_NOEXCEPT noexcept
219#endif
220
221#define RYML_DEPRECATED(msg) C4_DEPRECATED(msg)
222
223/** @endcond */
224
225
226//-----------------------------------------------------------------------------
227//-----------------------------------------------------------------------------
228//-----------------------------------------------------------------------------
229
230namespace c4 {
231namespace yml {
232
233C4_SUPPRESS_WARNING_GCC_CLANG_WITH_PUSH("-Wold-style-cast")
234
235class Tree;
236
237
238#ifndef RYML_ID_TYPE
239/** The type of a node id in the YAML tree. In the future, the default
240 * will likely change to int32_t, which was observed to be faster.
241 * @see id_type */
242#define RYML_ID_TYPE size_t
243#endif
244
245
246/** The type of a node id in the YAML tree; to override the default
247 * type, define the macro @ref RYML_ID_TYPE to a suitable integer
248 * type. */
250static_assert(std::is_integral<id_type>::value, "id_type must be an integer type");
251
252
253C4_SUPPRESS_WARNING_GCC_WITH_PUSH("-Wuseless-cast")
254enum : id_type { // NOLINT
255 /** an index to none */
256 NONE = id_type(-1), // NOLINT
257};
258C4_SUPPRESS_WARNING_GCC_CLANG_POP
259
260
261enum : size_t { // NOLINT
262 /** a null string position */
263 npos = size_t(-1) // NOLINT
264};
265
266
267typedef enum Encoding_ { // NOLINT
268 NOBOM, //!< No Byte Order Mark was found
269 UTF8, //!< UTF8
270 UTF16LE, //!< UTF16, Little-Endian
271 UTF16BE, //!< UTF16, Big-Endian
272 UTF32LE, //!< UTF32, Little-Endian
273 UTF32BE, //!< UTF32, Big-Endian
275
276
277//-----------------------------------------------------------------------------
278//-----------------------------------------------------------------------------
279//-----------------------------------------------------------------------------
280
281C4_SUPPRESS_WARNING_MSVC_WITH_PUSH(4251) // csubstr needs to have dll-interface to be used by clients of Location
282
283/** holds a source or yaml file position, for example when an error is
284 * detected; See also @ref location_format() and @ref
285 * location_format_with_context().
286 *
287 * @ingroup doc_error_handling */
289{
290 size_t offset; ///< number of bytes from the beginning of the source buffer
291 size_t line; ///< line
292 size_t col; ///< column
293 csubstr name; ///< name of the file
294
295 operator bool () const noexcept { return !name.empty() || line != npos || offset != npos || col != npos; }
296
297 C4_NO_INLINE Location() noexcept : offset(npos), line(npos), col(npos), name() {}
298 C4_NO_INLINE Location( size_t l ) noexcept : offset(npos), line(l), col(npos), name() {}
299 C4_NO_INLINE Location( size_t l, size_t c) noexcept : offset(npos), line(l), col(c ), name() {}
300 C4_NO_INLINE Location( size_t b, size_t l, size_t c) noexcept : offset(b ), line(l), col(c ), name() {}
301 C4_NO_INLINE Location( csubstr n, size_t l ) noexcept : offset(npos), line(l), col(npos), name(n) {}
302 C4_NO_INLINE Location( csubstr n, size_t l, size_t c) noexcept : offset(npos), line(l), col(c ), name(n) {}
303 C4_NO_INLINE Location( csubstr n, size_t b, size_t l, size_t c) noexcept : offset(b ), line(l), col(c ), name(n) {}
304 C4_NO_INLINE Location(const char *n, size_t l ) noexcept : offset(npos), line(l), col(npos), name(to_csubstr(n)) {}
305 C4_NO_INLINE Location(const char *n, size_t l, size_t c) noexcept : offset(npos), line(l), col(c ), name(to_csubstr(n)) {}
306 C4_NO_INLINE Location(const char *n, size_t b, size_t l, size_t c) noexcept : offset(b ), line(l), col(c ), name(to_csubstr(n)) {}
307};
308static_assert(std::is_standard_layout<Location>::value, "Location not trivial");
309
310C4_SUPPRESS_WARNING_MSVC_POP
311
312/// @cond dev
313#define RYML_LOC_HERE() (::c4::yml::Location(__FILE__, static_cast<size_t>(__LINE__)))
314/// @endcond
315
316
317/** Data for a basic error.
318 * @ingroup doc_error_handling */
320{
321 Location location; ///< location where the error was detected (may be from YAML or C++ source code)
322 ErrorDataBasic() noexcept = default;
323 ErrorDataBasic(Location const& cpploc_) noexcept : location(cpploc_) {}
324};
325
326/** Data for a parse error.
327 * @ingroup doc_error_handling */
329{
330 Location cpploc; ///< location in the C++ source file where the error was detected.
331 Location ymlloc; ///< location in the YAML source buffer where the error was detected.
332 ErrorDataParse() noexcept = default;
333 ErrorDataParse(Location const& cpploc_, Location const& ymlloc_) noexcept : cpploc(cpploc_), ymlloc(ymlloc_) {}
334};
335
336/** Data for a visit error.
337 * @ingroup doc_error_handling */
339{
340 Location cpploc; ///< location in the C++ source file where the error was detected.
341 Tree const* tree; ///< tree where the error was detected
342 id_type node; ///< node where the error was detected
343 ErrorDataVisit() noexcept = default;
344 ErrorDataVisit(Location const& cpploc_, Tree const *tree_ , id_type node_) noexcept : cpploc(cpploc_), tree(tree_), node(node_) {}
345};
346
347
348
349//-----------------------------------------------------------------------------
350//-----------------------------------------------------------------------------
351//-----------------------------------------------------------------------------
352
353/** Options to give to the parser to control its behavior. */
355{
356private:
357
358 typedef enum : uint32_t { // NOLINT
359 DETECT_FLOW_ML = (1u << 0u),
360 RESOLVE_TAGS = (1u << 1u),
361 RESOLVE_TAGS_ALL = (1u << 2u),
362 SCALAR_FILTERING = (1u << 3u),
363 LOCATIONS = (1u << 4u),
364 DEFAULTS = SCALAR_FILTERING|DETECT_FLOW_ML,
365 } Flags_e;
366
367 uint32_t flags = DEFAULTS;
368
369 ParserOptions& set_flags_(bool enabled, Flags_e f)
370 {
371 if(enabled)
372 flags |= f;
373 else
374 flags &= ~f;
375 return *this;
376 }
377
378public:
379
380 ParserOptions() = default;
381
382public:
383
384 /** @name detection of @ref FLOW_ML container style */
385 /** @{ */
386
387 /** enable/disable detection of @ref FLOW_ML container style. When
388 * enabled, the parser will set @ref FLOW_ML as the style of flow
389 * containers which have the terminating bracket on a line
390 * different from that of the opening bracket. */
391 ParserOptions& detect_flow_ml(bool enabled) noexcept
392 {
393 return set_flags_(enabled, DETECT_FLOW_ML);
394 }
395 /** query status of detection of @ref FLOW_ML container style. */
396 C4_ALWAYS_INLINE bool detect_flow_ml() const noexcept { return (flags & DETECT_FLOW_ML); }
397
398 /** @} */
399
400public:
401
402 /** @name resolution of tags */
403 /** @{ */
404
405 /** enable/disable resolution of YAML tags during parsing. When
406 * enabled, tags are resolved according to existing tag
407 * directives. Disabled by default. See also @ref
408 * ParserOptions::resolve_tags_all(). */
409 ParserOptions& resolve_tags(bool enabled) noexcept
410 {
411 return set_flags_(enabled, RESOLVE_TAGS);
412 }
413 /** query status of tag resolution setting. */
414 C4_ALWAYS_INLINE bool resolve_tags() const noexcept { return (flags & RESOLVE_TAGS); }
415
416 /** When resolve_tags() is enabled, resolve not just prefixed tags
417 * of the form <pre>!handle!tag</pre>, but also non-prefixed tags
418 * (<pre>!!tag</pre> and <pre>!tag!</pre>). Disabled by default. */
419 ParserOptions& resolve_tags_all(bool enabled) noexcept
420 {
421 return set_flags_(enabled, RESOLVE_TAGS_ALL);
422 }
423 /** query status of non-prefixed tag resolution setting. */
424 C4_ALWAYS_INLINE bool resolve_tags_all() const noexcept { return (flags & RESOLVE_TAGS_ALL); }
425
426 /** @} */
427
428public:
429
430 /** @name source location tracking */
431 /** @{ */
432
433 /** enable/disable source location tracking */
434 ParserOptions& locations(bool enabled) noexcept
435 {
436 return set_flags_(enabled, LOCATIONS);
437 }
438 /** query source location tracking status */
439 C4_ALWAYS_INLINE bool locations() const noexcept { return (flags & LOCATIONS); }
440
441 /** @} */
442
443public:
444
445 /** @name scalar filtering status (experimental; disable at your discretion) */
446 /** @{ */
447
448 /** enable/disable scalar filtering while parsing */
449 ParserOptions& scalar_filtering(bool enabled) noexcept
450 {
451 return set_flags_(enabled, SCALAR_FILTERING);
452 }
453 /** query scalar filtering status */
454 C4_ALWAYS_INLINE bool scalar_filtering() const noexcept { return (flags & SCALAR_FILTERING); }
455
456 /** @} */
457};
458
459
460//-----------------------------------------------------------------------------
461
462/** @addtogroup doc_callbacks
463 *
464 * @{ */
465
466struct Callbacks;
467
468
469/** set the global callbacks for the library; after a call to this
470 * function, these callbacks will be used by newly created objects
471 * (unless they are copying older objects with different
472 * callbacks). If @ref RYML_NO_DEFAULT_CALLBACKS is defined, it is
473 * mandatory to call this function prior to using any other library
474 * facility.
475 *
476 * @warning This function is NOT thread-safe, because it sets global static data
477 * */
478RYML_EXPORT void set_callbacks(Callbacks const& c);
479
480/** get the global callbacks
481 *
482 * @warning This function is NOT thread-safe, because it reads global static data
483 * */
484RYML_EXPORT Callbacks const& get_callbacks();
485
486/** set the global callbacks back to their defaults.
487 *
488 * @warning This function is NOT thread-safe, because it sets global static data
489 * */
491
492
493/** the type of the function used to allocate memory; ryml will only
494 * allocate memory through this callback. */
495using pfn_allocate = void* (*)(size_t len, void* hint, void *user_data);
496
497
498/** the type of the function used to free memory; ryml will only free
499 * memory through this callback. */
500using pfn_free = void (*)(void* mem, size_t size, void *user_data);
501
502
503/** the type of the function used to report basic errors.
504 *
505 * @warning Must not return. When implemented by the user, this
506 * function MUST interrupt execution (and ideally be marked with
507 * `[[noreturn]]`). If the function returned, the caller could enter
508 * into an infinite loop, or the program may crash. It is up to the
509 * user to choose the interruption mechanism; typically by either
510 * throwing an exception, or using `std::longjmp()` ([see
511 * documentation](https://en.cppreference.com/w/cpp/utility/program/setjmp))
512 * or ultimately by calling `std::abort()`. */
513using pfn_error_basic = void (*) (csubstr msg, ErrorDataBasic const& errdata, void *user_data);
514/** the type of the function used to report parse errors.
515 *
516 * @warning Must not return. When implemented by the user, this
517 * function MUST interrupt execution (and ideally be marked with
518 * `[[noreturn]]`). If the function returned, the caller could enter
519 * into an infinite loop, or the program may crash. It is up to the
520 * user to choose the interruption mechanism; typically by either
521 * throwing an exception, or using `std::longjmp()` ([see
522 * documentation](https://en.cppreference.com/w/cpp/utility/program/setjmp))
523 * or ultimately by calling `std::abort()`. */
524using pfn_error_parse = void (*) (csubstr msg, ErrorDataParse const& errdata, void *user_data);
525/** the type of the function used to report visit errors.
526 *
527 * @warning Must not return. When implemented by the user, this
528 * function MUST interrupt execution (and ideally be marked with
529 * `[[noreturn]]`). If the function returned, the caller could enter
530 * into an infinite loop, or the program may crash. It is up to the
531 * user to choose the interruption mechanism; typically by either
532 * throwing an exception, or using `std::longjmp()` ([see
533 * documentation](https://en.cppreference.com/w/cpp/utility/program/setjmp))
534 * or ultimately by calling `std::abort()`. */
535using pfn_error_visit = void (*) (csubstr msg, ErrorDataVisit const& errdata, void *user_data);
536
537/// @cond dev
538using pfn_error RYML_DEPRECATED("use a more specific error type: `basic`, `parse` or `visit`") = void (*) (const char* msg, size_t msg_len, Location const& cpploc, void *user_data);
539/// @endcond
540
541
542/** A c-style callbacks class to customize behavior on errors or
543 * allocation. Can be used globally by the library and/or locally by
544 * @ref Tree and @ref Parser objects. */
546{
547 void * m_user_data; ///< data to be forwarded in every call to a callback
548 pfn_allocate m_allocate; ///< a pointer to an allocate handler function
549 pfn_free m_free; ///< a pointer to a free handler function
550 pfn_error_basic m_error_basic; ///< a pointer to a basic error handler function
551 pfn_error_parse m_error_parse; ///< a pointer to a parse error handler function
552 pfn_error_visit m_error_visit; ///< a pointer to a visit error handler function
553
554public:
555
556 /** Construct an object with the default callbacks. If
557 * @ref RYML_NO_DEFAULT_CALLBACKS is defined, the object will be set with null
558 * members.*/
559 Callbacks() noexcept;
560
561 RYML_DEPRECATED("use the default constructor, followed by the appropriate setters")
562 Callbacks(void *user_data, pfn_allocate alloc, pfn_free free, pfn_error_basic error_basic);
563
564public:
565
566 /** Set the user data. */
567 Callbacks& set_user_data(void* user_data);
568
569 /** Set or reset the allocate callback. When the parameter is
570 * null, m_allocate will fall back to ryml's default allocate
571 * implementation, unless @ref RYML_NO_DEFAULT_CALLBACKS is
572 * defined. */
573 Callbacks& set_allocate(pfn_allocate allocate=nullptr);
574
575 /** Set or reset the free callback. When the parameter is null,
576 * m_free will fall back to ryml's default free implementation,
577 * unless @ref RYML_NO_DEFAULT_CALLBACKS is defined. */
578 Callbacks& set_free(pfn_free free=nullptr);
579
580 /** Set or reset the error_basic callback. When the parameter is null,
581 * m_error_basic will fall back to ryml's default error_basic implementation,
582 * unless @ref RYML_NO_DEFAULT_CALLBACKS is defined. */
583 Callbacks& set_error_basic(pfn_error_basic error_basic=nullptr);
584
585 /** Set or reset the error_parse callback. When the parameter is null,
586 * m_error_parse will fall back to ryml's default error_parse implementation,
587 * unless @ref RYML_NO_DEFAULT_CALLBACKS is defined. */
588 Callbacks& set_error_parse(pfn_error_parse error_parse=nullptr);
589
590 /** Set or reset the error_visit callback. When the parameter is null,
591 * m_error_visit will fall back to ryml's default error_visit implementation,
592 * unless @ref RYML_NO_DEFAULT_CALLBACKS is defined. */
593 Callbacks& set_error_visit(pfn_error_visit error_visit=nullptr);
594
595public:
596
597 bool operator!= (Callbacks const& that) const { return !operator==(that); }
598 bool operator== (Callbacks const& that) const
599 {
600 return (m_user_data == that.m_user_data &&
601 m_allocate == that.m_allocate &&
602 m_free == that.m_free &&
606 }
607};
608
609
610/** @} */
611
612
613//-----------------------------------------------------------------------------
614//-----------------------------------------------------------------------------
615//-----------------------------------------------------------------------------
616
617/// @cond dev
618
619#define _RYML_CB_ALLOC_HINT(cb, T, num, hint) (T*) (cb).m_allocate((num) * sizeof(T), (hint), (cb).m_user_data)
620#define _RYML_CB_ALLOC(cb, T, num) _RYML_CB_ALLOC_HINT((cb), T, (num), nullptr)
621#define _RYML_CB_FREE(cb, buf, T, num) \
622 do { \
623 (cb).m_free((buf), (num) * sizeof(T), (cb).m_user_data); \
624 (buf) = nullptr; \
625 } while(false)
626
627namespace detail {
628template<int8_t signedval, uint8_t unsignedval>
629struct _charconstant_t // is there a better way to do this?
630 : public std::conditional<std::is_signed<char>::value,
631 std::integral_constant<int8_t, static_cast<int8_t>(unsignedval)>,
632 std::integral_constant<uint8_t, unsignedval>>::type
633{};
634#define _RYML_CHCONST(signedval, unsignedval) ::c4::yml::detail::_charconstant_t<INT8_C(signedval), UINT8_C(unsignedval)>::value
635} // namespace detail
636
637inline csubstr _c4prc(const char &C4_RESTRICT c) // pass by reference!
638{
639 switch(c)
640 {
641 case '\n': return csubstr("\\n");
642 case '\t': return csubstr("\\t");
643 case '\0': return csubstr("\\0");
644 case '\r': return csubstr("\\r");
645 case '\f': return csubstr("\\f");
646 case '\b': return csubstr("\\b");
647 case '\v': return csubstr("\\v");
648 case '\a': return csubstr("\\a");
649 default: return csubstr(&c, 1);
650 }
651}
652
653/// @endcond
654
655C4_SUPPRESS_WARNING_GCC_POP
656
657} // namespace yml
658} // namespace c4
659
660#endif /* _C4_YML_COMMON_HPP_ */
Lightweight generic type-safe wrappers for converting individual values to/from strings.
#define RYML_ID_TYPE
The type of a node id in the YAML tree.
Definition common.hpp:242
#define RYML_ERRMSG_SIZE
size for the error message buffer
Definition common.hpp:34
#define RYML_LOGBUF_SIZE
size for the buffer used to format individual values to string while preparing an error message....
Definition common.hpp:44
#define RYML_EXPORT
Definition export.hpp:18
void *(*)(size_t len, void *hint, void *user_data) pfn_allocate
the type of the function used to allocate memory; ryml will only allocate memory through this callbac...
Definition common.hpp:495
void(*)(csubstr msg, ErrorDataVisit const &errdata, void *user_data) pfn_error_visit
the type of the function used to report visit errors.
Definition common.hpp:535
void reset_callbacks()
set the global callbacks back to their defaults.
Definition common.cpp:99
void(*)(void *mem, size_t size, void *user_data) pfn_free
the type of the function used to free memory; ryml will only free memory through this callback.
Definition common.hpp:500
void set_callbacks(Callbacks const &c)
set the global callbacks for the library; after a call to this function, these callbacks will be used...
Definition common.cpp:89
void(*)(csubstr msg, ErrorDataParse const &errdata, void *user_data) pfn_error_parse
the type of the function used to report parse errors.
Definition common.hpp:524
Callbacks const & get_callbacks()
get the global callbacks
Definition common.cpp:94
void(*)(csubstr msg, ErrorDataBasic const &errdata, void *user_data) pfn_error_basic
the type of the function used to report basic errors.
Definition common.hpp:513
csubstr to_csubstr(const char(&s)[N]) noexcept
Definition substr.hpp:2381
basic_substring< const char > csubstr
an immutable string view
Definition substr.hpp:2357
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:249
@ npos
a null string position
Definition common.hpp:263
@ UTF16BE
UTF16, Big-Endian.
Definition common.hpp:271
@ UTF8
UTF8.
Definition common.hpp:269
@ UTF16LE
UTF16, Little-Endian.
Definition common.hpp:270
@ NOBOM
No Byte Order Mark was found.
Definition common.hpp:268
@ UTF32BE
UTF32, Big-Endian.
Definition common.hpp:273
@ UTF32LE
UTF32, Little-Endian.
Definition common.hpp:272
@ NONE
an index to none
Definition common.hpp:256
enum c4::yml::Encoding_ Encoding_e
(Undefined by default) Use shorter error message from checks/asserts: do not show the check condition...
Definition common.cpp:14
pfn_error_basic m_error_basic
a pointer to a basic error handler function
Definition common.hpp:550
pfn_error_parse m_error_parse
a pointer to a parse error handler function
Definition common.hpp:551
Callbacks & set_error_visit(pfn_error_visit error_visit=nullptr)
Set or reset the error_visit callback.
Definition common.cpp:186
Callbacks & set_free(pfn_free free=nullptr)
Set or reset the free callback.
Definition common.cpp:159
void * m_user_data
data to be forwarded in every call to a callback
Definition common.hpp:547
pfn_allocate m_allocate
a pointer to an allocate handler function
Definition common.hpp:548
bool operator==(Callbacks const &that) const
Definition common.hpp:598
Callbacks() noexcept
Construct an object with the default callbacks.
Definition common.cpp:105
Callbacks & set_error_parse(pfn_error_parse error_parse=nullptr)
Set or reset the error_parse callback.
Definition common.cpp:177
Callbacks & set_allocate(pfn_allocate allocate=nullptr)
Set or reset the allocate callback.
Definition common.cpp:150
Callbacks & set_error_basic(pfn_error_basic error_basic=nullptr)
Set or reset the error_basic callback.
Definition common.cpp:168
pfn_error_visit m_error_visit
a pointer to a visit error handler function
Definition common.hpp:552
pfn_free m_free
a pointer to a free handler function
Definition common.hpp:549
Callbacks & set_user_data(void *user_data)
Set the user data.
Definition common.cpp:144
Data for a basic error.
Definition common.hpp:320
ErrorDataBasic() noexcept=default
Location location
location where the error was detected (may be from YAML or C++ source code)
Definition common.hpp:321
Data for a parse error.
Definition common.hpp:329
Location cpploc
location in the C++ source file where the error was detected.
Definition common.hpp:330
ErrorDataParse() noexcept=default
Location ymlloc
location in the YAML source buffer where the error was detected.
Definition common.hpp:331
Data for a visit error.
Definition common.hpp:339
ErrorDataVisit() noexcept=default
Location cpploc
location in the C++ source file where the error was detected.
Definition common.hpp:340
Tree const * tree
tree where the error was detected
Definition common.hpp:341
id_type node
node where the error was detected
Definition common.hpp:342
holds a source or yaml file position, for example when an error is detected; See also location_format...
Definition common.hpp:289
Location(const char *n, size_t l) noexcept
Definition common.hpp:304
size_t col
column
Definition common.hpp:292
size_t line
line
Definition common.hpp:291
Location(csubstr n, size_t l) noexcept
Definition common.hpp:301
Location(const char *n, size_t l, size_t c) noexcept
Definition common.hpp:305
Location(csubstr n, size_t l, size_t c) noexcept
Definition common.hpp:302
Location(size_t l, size_t c) noexcept
Definition common.hpp:299
size_t offset
number of bytes from the beginning of the source buffer
Definition common.hpp:290
Location(size_t b, size_t l, size_t c) noexcept
Definition common.hpp:300
csubstr name
name of the file
Definition common.hpp:293
Location(csubstr n, size_t b, size_t l, size_t c) noexcept
Definition common.hpp:303
Location(const char *n, size_t b, size_t l, size_t c) noexcept
Definition common.hpp:306
Location(size_t l) noexcept
Definition common.hpp:298
Location() noexcept
Definition common.hpp:297
ParserOptions & detect_flow_ml(bool enabled) noexcept
enable/disable detection of FLOW_ML container style.
Definition common.hpp:391
bool scalar_filtering() const noexcept
query scalar filtering status
Definition common.hpp:454
ParserOptions & locations(bool enabled) noexcept
enable/disable source location tracking
Definition common.hpp:434
bool resolve_tags_all() const noexcept
query status of non-prefixed tag resolution setting.
Definition common.hpp:424
ParserOptions & scalar_filtering(bool enabled) noexcept
enable/disable scalar filtering while parsing
Definition common.hpp:449
bool locations() const noexcept
query source location tracking status
Definition common.hpp:439
bool detect_flow_ml() const noexcept
query status of detection of FLOW_ML container style.
Definition common.hpp:396
ParserOptions & resolve_tags(bool enabled) noexcept
enable/disable resolution of YAML tags during parsing.
Definition common.hpp:409
ParserOptions & resolve_tags_all(bool enabled) noexcept
When resolve_tags() is enabled, resolve not just prefixed tags of the form.
Definition common.hpp:419
bool resolve_tags() const noexcept
query status of tag resolution setting.
Definition common.hpp:414
read+write string views