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