rapidyaml  0.16.0
parseandemitYAML,anddoitfast
Callbacks for errors and allocation

Functions called by ryml to allocate/free memory and to report errors. More...

Classes

struct  c4::yml::Callbacks
 A c-style callbacks class to customize behavior on errors or allocation. More...
 

Typedefs

using c4::yml::pfn_allocate = void *(*)(size_t len, void *hint, void *user_data)
 the type of the function used to allocate memory; ryml will only allocate memory through this callback. More...
 
using c4::yml::pfn_free = void(*)(void *mem, size_t size, void *user_data)
 the type of the function used to free memory; ryml will only free memory through this callback. More...
 
using c4::yml::pfn_error_basic = void(*)(csubstr msg, ErrorDataBasic const &errdata, void *user_data)
 the type of the function used to report basic errors. More...
 
using c4::yml::pfn_error_parse = void(*)(csubstr msg, ErrorDataParse const &errdata, void *user_data)
 the type of the function used to report parse errors. More...
 
using c4::yml::pfn_error_visit = void(*)(csubstr msg, ErrorDataVisit const &errdata, void *user_data)
 the type of the function used to report visit errors. More...
 

Functions

void c4::yml::set_callbacks (Callbacks const &c)
 set the global callbacks for the library; after a call to this function, these callbacks will be used by newly created objects (unless they are copying older objects with different callbacks). More...
 
Callbacks const & c4::yml::get_callbacks ()
 get the global callbacks More...
 
void c4::yml::reset_callbacks ()
 set the global callbacks back to their defaults. More...
 

Detailed Description

Functions called by ryml to allocate/free memory and to report errors.

See also
sample_error_handler()
sample_global_allocator()
sample_per_tree_allocator()

Typedef Documentation

using c4::yml::pfn_allocate = typedef void* (*)(size_t len, void* hint, void *user_data)

the type of the function used to allocate memory; ryml will only allocate memory through this callback.

Definition at line 323 of file common.hpp.

using c4::yml::pfn_free = typedef void (*)(void* mem, size_t size, void *user_data)

the type of the function used to free memory; ryml will only free memory through this callback.

Definition at line 328 of file common.hpp.

using c4::yml::pfn_error_basic = typedef void (*) (csubstr msg, ErrorDataBasic const& errdata, void *user_data)

the type of the function used to report basic errors.

Warning
Must not return. When implemented by the user, this function MUST interrupt execution (and ideally be marked with [[noreturn]]). If the function returned, the caller could enter into an infinite loop, or the program may crash. It is up to the user to choose the interruption mechanism; typically by either throwing an exception, or using std::longjmp() (see documentation) or ultimately by calling std::abort().

Definition at line 341 of file common.hpp.

using c4::yml::pfn_error_parse = typedef void (*) (csubstr msg, ErrorDataParse const& errdata, void *user_data)

the type of the function used to report parse errors.

Warning
Must not return. When implemented by the user, this function MUST interrupt execution (and ideally be marked with [[noreturn]]). If the function returned, the caller could enter into an infinite loop, or the program may crash. It is up to the user to choose the interruption mechanism; typically by either throwing an exception, or using std::longjmp() (see documentation) or ultimately by calling std::abort().

Definition at line 352 of file common.hpp.

using c4::yml::pfn_error_visit = typedef void (*) (csubstr msg, ErrorDataVisit const& errdata, void *user_data)

the type of the function used to report visit errors.

Warning
Must not return. When implemented by the user, this function MUST interrupt execution (and ideally be marked with [[noreturn]]). If the function returned, the caller could enter into an infinite loop, or the program may crash. It is up to the user to choose the interruption mechanism; typically by either throwing an exception, or using std::longjmp() (see documentation) or ultimately by calling std::abort().

Definition at line 363 of file common.hpp.

Function Documentation

void c4::yml::set_callbacks ( Callbacks const &  c)

set the global callbacks for the library; after a call to this function, these callbacks will be used by newly created objects (unless they are copying older objects with different callbacks).

If RYML_NO_DEFAULT_CALLBACKS is defined, it is mandatory to call this function prior to using any other library facility.

Warning
This function is NOT thread-safe, because it sets global static data

Definition at line 89 of file common.cpp.

Referenced by ensure_callbacks(), c4::yml::reset_callbacks(), sample_error_handler(), sample_error_parse(), sample_error_visit(), sample_global_allocator(), ScopedErrorHandlerExample::ScopedErrorHandlerExample(), and ScopedErrorHandlerExample::~ScopedErrorHandlerExample().

90 {
91  s_default_callbacks = c;
92 }
Callbacks const & c4::yml::get_callbacks ( )

get the global callbacks

Warning
This function is NOT thread-safe, because it reads global static data

Definition at line 94 of file common.cpp.

Referenced by ErrorHandlerExample::check_disabled(), ErrorHandlerExample::check_enabled(), c4::yml::err_basic(), c4::yml::err_parse(), c4::yml::err_visit(), sample_error_parse(), sample_error_visit(), and sample_global_allocator().

95 {
96  return s_default_callbacks;
97 }
void c4::yml::reset_callbacks ( )

set the global callbacks back to their defaults.

Warning
This function is NOT thread-safe, because it sets global static data

Definition at line 99 of file common.cpp.

100 {
101  set_callbacks(Callbacks());
102 }
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