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