rapidyaml  0.11.1
parse and emit YAML, and do it fast
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
56 static_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 
168 //-----------------------------------------------------------------------------
169 
170 // document macros for doxygen
171 #ifdef __DOXYGEN__ // defined in Doxyfile::PREDEFINED
172 
173 /** define this macro with a boolean value to enable/disable
174  * assertions to check preconditions and assumptions throughout the
175  * codebase; this causes a slowdown of the code, and larger code
176  * size. By default, this macro is defined unless NDEBUG is defined
177  * (see C4_USE_ASSERT); as a result, by default this macro is truthy
178  * only in debug builds. */
179 # define RYML_USE_ASSERT
180 
181 /** (Undefined by default) Define this macro to disable ryml's default
182  * implementation of the callback functions. See @ref doc_callbacks. */
183 # define RYML_NO_DEFAULT_CALLBACKS
184 
185 /** (Undefined by default) When this macro is defined (and
186  * @ref RYML_NO_DEFAULT_CALLBACKS is not defined), the default error
187  * handler will throw exceptions. See @ref doc_error_handling. */
188 # define RYML_DEFAULT_CALLBACK_USES_EXCEPTIONS
189 
190 /** Conditionally expands to `noexcept` when @ref RYML_USE_ASSERT is 0 and
191  * is empty otherwise. The user is unable to override this macro. */
192 # define RYML_NOEXCEPT
193 
194 /** (Undefined by default) Use shorter error message from
195  * checks/asserts: do not show the check condition in the error
196  * message. */
197 # defined RYML_SHORT_CHECK_MSG
198 
199 #endif
200 
201 
202 //-----------------------------------------------------------------------------
203 
204 /** @cond dev */
205 
206 #ifndef RYML_USE_ASSERT
207 # define RYML_USE_ASSERT C4_USE_ASSERT
208 #endif
209 
210 #if RYML_USE_ASSERT
211 # define RYML_NOEXCEPT
212 #else
213 # define RYML_NOEXCEPT noexcept
214 #endif
215 
216 #define RYML_DEPRECATED(msg) C4_DEPRECATED(msg)
217 
218 /** @endcond */
219 
220 
221 //-----------------------------------------------------------------------------
222 //-----------------------------------------------------------------------------
223 //-----------------------------------------------------------------------------
224 
225 namespace c4 {
226 namespace yml {
227 
228 C4_SUPPRESS_WARNING_GCC_CLANG_WITH_PUSH("-Wold-style-cast")
229 
230 class Tree;
231 
232 
233 #ifndef RYML_ID_TYPE
234 /** The type of a node id in the YAML tree. In the future, the default
235  * will likely change to int32_t, which was observed to be faster.
236  * @see id_type */
237 #define RYML_ID_TYPE size_t
238 #endif
239 
240 
241 /** The type of a node id in the YAML tree; to override the default
242  * type, define the macro @ref RYML_ID_TYPE to a suitable integer
243  * type. */
245 static_assert(std::is_integral<id_type>::value, "id_type must be an integer type");
246 
247 
248 C4_SUPPRESS_WARNING_GCC_WITH_PUSH("-Wuseless-cast")
249 enum : id_type {
250  /** an index to none */
251  NONE = id_type(-1),
252 };
253 C4_SUPPRESS_WARNING_GCC_CLANG_POP
254 
255 
256 enum : size_t {
257  /** a null string position */
258  npos = size_t(-1)
259 };
260 
261 
262 typedef enum Encoding_ {
263  NOBOM, //!< No Byte Order Mark was found
264  UTF8, //!< UTF8
265  UTF16LE, //!< UTF16, Little-Endian
266  UTF16BE, //!< UTF16, Big-Endian
267  UTF32LE, //!< UTF32, Little-Endian
268  UTF32BE, //!< UTF32, Big-Endian
270 
271 
272 //-----------------------------------------------------------------------------
273 //-----------------------------------------------------------------------------
274 //-----------------------------------------------------------------------------
275 
276 
277 /** holds a source or yaml file position, for example when an error is
278  * detected; See also @ref location_format() and @ref
279  * location_format_with_context().
280  *
281  * @ingroup doc_error_handling */
283 {
284  size_t offset; ///< number of bytes from the beginning of the source buffer
285  size_t line; ///< line
286  size_t col; ///< column
287  csubstr name; ///< name of the file
288 
289  operator bool () const noexcept { return !name.empty() || line != npos || offset != npos || col != npos; }
290 
291  C4_NO_INLINE Location() noexcept : offset(npos), line(npos), col(npos), name() {};
292  C4_NO_INLINE Location( size_t l ) noexcept : offset(npos), line(l), col(npos), name() {}
293  C4_NO_INLINE Location( size_t l, size_t c) noexcept : offset(npos), line(l), col(c ), name() {}
294  C4_NO_INLINE Location( size_t b, size_t l, size_t c) noexcept : offset(b ), line(l), col(c ), name() {}
295  C4_NO_INLINE Location( csubstr n, size_t l ) noexcept : offset(npos), line(l), col(npos), name(n) {}
296  C4_NO_INLINE Location( csubstr n, size_t l, size_t c) noexcept : offset(npos), line(l), col(c ), name(n) {}
297  C4_NO_INLINE Location( csubstr n, size_t b, size_t l, size_t c) noexcept : offset(b ), line(l), col(c ), name(n) {}
298  C4_NO_INLINE Location(const char *n, size_t l ) noexcept : offset(npos), line(l), col(npos), name(to_csubstr(n)) {}
299  C4_NO_INLINE Location(const char *n, size_t l, size_t c) noexcept : offset(npos), line(l), col(c ), name(to_csubstr(n)) {}
300  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)) {}
301 };
302 static_assert(std::is_standard_layout<Location>::value, "Location not trivial");
303 
304 /// @cond dev
305 #define RYML_LOC_HERE() (::c4::yml::Location(__FILE__, static_cast<size_t>(__LINE__)))
306 /// @endcond
307 
308 
309 /** Data for a basic error.
310  * @ingroup doc_error_handling */
312 {
313  Location location; ///< location where the error was detected (may be from YAML or C++ source code)
314  ErrorDataBasic() noexcept = default;
315  ErrorDataBasic(Location const& cpploc_) noexcept : location(cpploc_) {}
316 };
317 
318 /** Data for a parse error.
319  * @ingroup doc_error_handling */
321 {
322  Location cpploc; ///< location in the C++ source file where the error was detected.
323  Location ymlloc; ///< location in the YAML source buffer where the error was detected.
324  ErrorDataParse() noexcept = default;
325  ErrorDataParse(Location const& cpploc_, Location const& ymlloc_) noexcept : cpploc(cpploc_), ymlloc(ymlloc_) {}
326 };
327 
328 /** Data for a visit error.
329  * @ingroup doc_error_handling */
331 {
332  Location cpploc; ///< location in the C++ source file where the error was detected.
333  Tree const* tree; ///< tree where the error was detected
334  id_type node; ///< node where the error was detected
335  ErrorDataVisit() noexcept = default;
336  ErrorDataVisit(Location const& cpploc_, Tree const *tree_ , id_type node_) noexcept : cpploc(cpploc_), tree(tree_), node(node_) {}
337 };
338 
339 
340 
341 //-----------------------------------------------------------------------------
342 //-----------------------------------------------------------------------------
343 //-----------------------------------------------------------------------------
344 
345 /** Options to give to the parser to control its behavior. */
347 {
348 private:
349 
350  typedef enum : uint32_t {
351  SCALAR_FILTERING = (1u << 0u),
352  LOCATIONS = (1u << 1u),
353  DETECT_FLOW_ML = (1u << 2u),
354  DEFAULTS = SCALAR_FILTERING|DETECT_FLOW_ML,
355  } Flags_e;
356 
357  uint32_t flags = DEFAULTS;
358 
359 public:
360 
361  ParserOptions() = default;
362 
363 public:
364 
365  /** @name source location tracking */
366  /** @{ */
367 
368  /** enable/disable source location tracking */
369  ParserOptions& locations(bool enabled) noexcept
370  {
371  if(enabled)
372  flags |= LOCATIONS;
373  else
374  flags &= ~LOCATIONS;
375  return *this;
376  }
377  /** query source location tracking status */
378  C4_ALWAYS_INLINE bool locations() const noexcept { return (flags & LOCATIONS); }
379 
380  /** @} */
381 
382 public:
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  if(enabled)
394  flags |= DETECT_FLOW_ML;
395  else
396  flags &= ~DETECT_FLOW_ML;
397  return *this;
398  }
399  /** query status of detection of @ref FLOW_ML container style. */
400  C4_ALWAYS_INLINE bool detect_flow_ml() const noexcept { return (flags & DETECT_FLOW_ML); }
401 
402  /** @} */
403 
404 public:
405 
406  /** @name scalar filtering status (experimental; disable at your discretion) */
407  /** @{ */
408 
409  /** enable/disable scalar filtering while parsing */
410  ParserOptions& scalar_filtering(bool enabled) noexcept
411  {
412  if(enabled)
413  flags |= SCALAR_FILTERING;
414  else
415  flags &= ~SCALAR_FILTERING;
416  return *this;
417  }
418  /** query scalar filtering status */
419  C4_ALWAYS_INLINE bool scalar_filtering() const noexcept { return (flags & SCALAR_FILTERING); }
420 
421  /** @} */
422 };
423 
424 
425 //-----------------------------------------------------------------------------
426 
427 /** @addtogroup doc_callbacks
428  *
429  * @{ */
430 
431 struct Callbacks;
432 
433 
434 /** set the global callbacks for the library; after a call to this
435  * function, these callbacks will be used by newly created objects
436  * (unless they are copying older objects with different
437  * callbacks). If @ref RYML_NO_DEFAULT_CALLBACKS is defined, it is
438  * mandatory to call this function prior to using any other library
439  * facility.
440  *
441  * @warning This function is NOT thread-safe, because it sets global static data
442  * */
443 RYML_EXPORT void set_callbacks(Callbacks const& c);
444 
445 /** get the global callbacks
446  *
447  * @warning This function is NOT thread-safe, because it reads global static data
448  * */
449 RYML_EXPORT Callbacks const& get_callbacks();
450 
451 /** set the global callbacks back to their defaults.
452  *
453  * @warning This function is NOT thread-safe, because it sets global static data
454  * */
456 
457 
458 /** the type of the function used to allocate memory; ryml will only
459  * allocate memory through this callback. */
460 using pfn_allocate = void* (*)(size_t len, void* hint, void *user_data);
461 
462 
463 /** the type of the function used to free memory; ryml will only free
464  * memory through this callback. */
465 using pfn_free = void (*)(void* mem, size_t size, void *user_data);
466 
467 
468 /** the type of the function used to report basic errors.
469  *
470  * @warning Must not return. When implemented by the user, this
471  * function MUST interrupt execution (and ideally be marked with
472  * `[[noreturn]]`). If the function returned, the caller could enter
473  * into an infinite loop, or the program may crash. It is up to the
474  * user to choose the interruption mechanism; typically by either
475  * throwing an exception, or using `std::longjmp()` ([see
476  * documentation](https://en.cppreference.com/w/cpp/utility/program/setjmp))
477  * or ultimately by calling `std::abort()`. */
478 using pfn_error_basic = void (*) (csubstr msg, ErrorDataBasic const& errdata, void *user_data);
479 /** the type of the function used to report parse errors.
480  *
481  * @warning Must not return. When implemented by the user, this
482  * function MUST interrupt execution (and ideally be marked with
483  * `[[noreturn]]`). If the function returned, the caller could enter
484  * into an infinite loop, or the program may crash. It is up to the
485  * user to choose the interruption mechanism; typically by either
486  * throwing an exception, or using `std::longjmp()` ([see
487  * documentation](https://en.cppreference.com/w/cpp/utility/program/setjmp))
488  * or ultimately by calling `std::abort()`. */
489 using pfn_error_parse = void (*) (csubstr msg, ErrorDataParse const& errdata, void *user_data);
490 /** the type of the function used to report visit errors.
491  *
492  * @warning Must not return. When implemented by the user, this
493  * function MUST interrupt execution (and ideally be marked with
494  * `[[noreturn]]`). If the function returned, the caller could enter
495  * into an infinite loop, or the program may crash. It is up to the
496  * user to choose the interruption mechanism; typically by either
497  * throwing an exception, or using `std::longjmp()` ([see
498  * documentation](https://en.cppreference.com/w/cpp/utility/program/setjmp))
499  * or ultimately by calling `std::abort()`. */
500 using pfn_error_visit = void (*) (csubstr msg, ErrorDataVisit const& errdata, void *user_data);
501 
502 /// @cond dev
503 using 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);
504 /// @endcond
505 
506 
507 /** A c-style callbacks class to customize behavior on errors or
508  * allocation. Can be used globally by the library and/or locally by
509  * @ref Tree and @ref Parser objects. */
511 {
512  void * m_user_data; ///< data to be forwarded in every call to a callback
513  pfn_allocate m_allocate; ///< a pointer to an allocate handler function
514  pfn_free m_free; ///< a pointer to a free handler function
515  pfn_error_basic m_error_basic; ///< a pointer to a basic error handler function
516  pfn_error_parse m_error_parse; ///< a pointer to a parse error handler function
517  pfn_error_visit m_error_visit; ///< a pointer to a visit error handler function
518 
519 public:
520 
521  /** Construct an object with the default callbacks. If
522  * @ref RYML_NO_DEFAULT_CALLBACKS is defined, the object will be set with null
523  * members.*/
524  Callbacks() noexcept;
525 
526  RYML_DEPRECATED("use the default constructor, followed by the appropriate setters")
527  Callbacks(void *user_data, pfn_allocate alloc, pfn_free free, pfn_error_basic error_basic);
528 
529 public:
530 
531  /** Set the user data. */
532  Callbacks& set_user_data(void* user_data);
533 
534  /** Set or reset the allocate callback. When the parameter is
535  * null, m_allocate will fall back to ryml's default allocate
536  * implementation, unless @ref RYML_NO_DEFAULT_CALLBACKS is
537  * defined. */
538  Callbacks& set_allocate(pfn_allocate allocate=nullptr);
539 
540  /** Set or reset the free callback. When the parameter is null,
541  * m_free will fall back to ryml's default free implementation,
542  * unless @ref RYML_NO_DEFAULT_CALLBACKS is defined. */
543  Callbacks& set_free(pfn_free free=nullptr);
544 
545  /** Set or reset the error_basic callback. When the parameter is null,
546  * m_error_basic will fall back to ryml's default error_basic implementation,
547  * unless @ref RYML_NO_DEFAULT_CALLBACKS is defined. */
548  Callbacks& set_error_basic(pfn_error_basic error_basic=nullptr);
549 
550  /** Set or reset the error_parse callback. When the parameter is null,
551  * m_error_parse will fall back to ryml's default error_parse implementation,
552  * unless @ref RYML_NO_DEFAULT_CALLBACKS is defined. */
553  Callbacks& set_error_parse(pfn_error_parse error_parse=nullptr);
554 
555  /** Set or reset the error_visit callback. When the parameter is null,
556  * m_error_visit will fall back to ryml's default error_visit implementation,
557  * unless @ref RYML_NO_DEFAULT_CALLBACKS is defined. */
558  Callbacks& set_error_visit(pfn_error_visit error_visit=nullptr);
559 
560 public:
561 
562  bool operator!= (Callbacks const& that) const { return !operator==(that); }
563  bool operator== (Callbacks const& that) const
564  {
565  return (m_user_data == that.m_user_data &&
566  m_allocate == that.m_allocate &&
567  m_free == that.m_free &&
568  m_error_basic == that.m_error_basic &&
569  m_error_parse == that.m_error_parse &&
570  m_error_visit == that.m_error_visit);
571  }
572 };
573 
574 
575 /** @} */
576 
577 
578 //-----------------------------------------------------------------------------
579 //-----------------------------------------------------------------------------
580 //-----------------------------------------------------------------------------
581 
582 /// @cond dev
583 
584 #define _RYML_CB_ALLOC_HINT(cb, T, num, hint) (T*) (cb).m_allocate((num) * sizeof(T), (hint), (cb).m_user_data)
585 #define _RYML_CB_ALLOC(cb, T, num) _RYML_CB_ALLOC_HINT((cb), T, (num), nullptr)
586 #define _RYML_CB_FREE(cb, buf, T, num) \
587  do { \
588  (cb).m_free((buf), (num) * sizeof(T), (cb).m_user_data); \
589  (buf) = nullptr; \
590  } while(false)
591 
592 namespace detail {
593 template<int8_t signedval, uint8_t unsignedval>
594 struct _charconstant_t // is there a better way to do this?
595  : public std::conditional<std::is_signed<char>::value,
596  std::integral_constant<int8_t, static_cast<int8_t>(unsignedval)>,
597  std::integral_constant<uint8_t, unsignedval>>::type
598 {};
599 #define _RYML_CHCONST(signedval, unsignedval) ::c4::yml::detail::_charconstant_t<INT8_C(signedval), UINT8_C(unsignedval)>::value
600 } // namespace detail
601 
602 inline csubstr _c4prc(const char &C4_RESTRICT c) // pass by reference!
603 {
604  switch(c)
605  {
606  case '\n': return csubstr("\\n");
607  case '\t': return csubstr("\\t");
608  case '\0': return csubstr("\\0");
609  case '\r': return csubstr("\\r");
610  case '\f': return csubstr("\\f");
611  case '\b': return csubstr("\\b");
612  case '\v': return csubstr("\\v");
613  case '\a': return csubstr("\\a");
614  default: return csubstr(&c, 1);
615  }
616 }
617 
618 /// @endcond
619 
620 C4_SUPPRESS_WARNING_GCC_POP
621 
622 } // namespace yml
623 } // namespace c4
624 
625 #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:237
#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:15
void reset_callbacks()
set the global callbacks back to their defaults.
Definition: common.cpp:99
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, ErrorDataVisit const &errdata, void *user_data) pfn_error_visit
the type of the function used to report visit errors.
Definition: common.hpp:500
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:460
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:489
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:478
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:465
csubstr to_csubstr(substr s) noexcept
neutral version for use in generic code
Definition: substr.hpp:2210
bool operator==(const char(&s)[N], basic_substring< C > const that) noexcept
Definition: substr.hpp:2282
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:244
@ npos
a null string position
Definition: common.hpp:258
@ UTF16BE
UTF16, Big-Endian.
Definition: common.hpp:266
@ UTF8
UTF8.
Definition: common.hpp:264
@ UTF16LE
UTF16, Little-Endian.
Definition: common.hpp:265
@ NOBOM
No Byte Order Mark was found.
Definition: common.hpp:263
@ UTF32BE
UTF32, Big-Endian.
Definition: common.hpp:268
@ UTF32LE
UTF32, Little-Endian.
Definition: common.hpp:267
enum c4::yml::Encoding_ Encoding_e
@ NONE
an index to none
Definition: common.hpp:251
(Undefined by default) Use shorter error message from checks/asserts: do not show the check condition...
Definition: common.cpp:14
A c-style callbacks class to customize behavior on errors or allocation.
Definition: common.hpp:511
pfn_error_basic m_error_basic
a pointer to a basic error handler function
Definition: common.hpp:515
pfn_error_parse m_error_parse
a pointer to a parse error handler function
Definition: common.hpp:516
void * m_user_data
data to be forwarded in every call to a callback
Definition: common.hpp:512
pfn_allocate m_allocate
a pointer to an allocate handler function
Definition: common.hpp:513
pfn_error_visit m_error_visit
a pointer to a visit error handler function
Definition: common.hpp:517
pfn_free m_free
a pointer to a free handler function
Definition: common.hpp:514
Data for a basic error.
Definition: common.hpp:312
ErrorDataBasic() noexcept=default
Location location
location where the error was detected (may be from YAML or C++ source code)
Definition: common.hpp:313
Data for a parse error.
Definition: common.hpp:321
Location cpploc
location in the C++ source file where the error was detected.
Definition: common.hpp:322
ErrorDataParse() noexcept=default
Location ymlloc
location in the YAML source buffer where the error was detected.
Definition: common.hpp:323
Data for a visit error.
Definition: common.hpp:331
ErrorDataVisit() noexcept=default
Location cpploc
location in the C++ source file where the error was detected.
Definition: common.hpp:332
Tree const * tree
tree where the error was detected
Definition: common.hpp:333
id_type node
node where the error was detected
Definition: common.hpp:334
holds a source or yaml file position, for example when an error is detected; See also location_format...
Definition: common.hpp:283
Location(const char *n, size_t l) noexcept
Definition: common.hpp:298
size_t col
column
Definition: common.hpp:286
size_t line
line
Definition: common.hpp:285
Location(csubstr n, size_t l) noexcept
Definition: common.hpp:295
Location(const char *n, size_t l, size_t c) noexcept
Definition: common.hpp:299
Location(csubstr n, size_t l, size_t c) noexcept
Definition: common.hpp:296
Location(size_t l, size_t c) noexcept
Definition: common.hpp:293
size_t offset
number of bytes from the beginning of the source buffer
Definition: common.hpp:284
Location(size_t b, size_t l, size_t c) noexcept
Definition: common.hpp:294
csubstr name
name of the file
Definition: common.hpp:287
Location(csubstr n, size_t b, size_t l, size_t c) noexcept
Definition: common.hpp:297
Location(const char *n, size_t b, size_t l, size_t c) noexcept
Definition: common.hpp:300
Location(size_t l) noexcept
Definition: common.hpp:292
Location() noexcept
Definition: common.hpp:291
Options to give to the parser to control its behavior.
Definition: common.hpp:347
ParserOptions & scalar_filtering(bool enabled) noexcept
enable/disable scalar filtering while parsing
Definition: common.hpp:410
bool scalar_filtering() const noexcept
query scalar filtering status
Definition: common.hpp:419
bool locations() const noexcept
query source location tracking status
Definition: common.hpp:378
bool detect_flow_ml() const noexcept
query status of detection of FLOW_ML container style.
Definition: common.hpp:400
ParserOptions & locations(bool enabled) noexcept
enable/disable source location tracking
Definition: common.hpp:369
ParserOptions & detect_flow_ml(bool enabled) noexcept
enable/disable detection of FLOW_ML container style.
Definition: common.hpp:391
read+write string views