rapidyaml  0.9.0
parse and emit YAML, and do it fast
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. More...
 

Typedefs

using c4::yml::pfn_error = void(*)(const char *msg, size_t msg_len, Location location, void *user_data)
 the type of the function used to report errors More...
 
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...
 

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::sample_error_handler
sample::sample_global_allocator
sample::sample_per_tree_allocator

Typedef Documentation

◆ pfn_error

using c4::yml::pfn_error = typedef void (*) (const char* msg, size_t msg_len, Location location, void *user_data)

the type of the function used to report errors

Warning
When given by the user, this function MUST interrupt execution, typically by either throwing an exception, or using std::longjmp() (see documentation) or by calling std::abort(). If the function returned, the parser would enter into an infinite loop, or the program may crash.

Definition at line 360 of file common.hpp.

◆ pfn_allocate

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 365 of file common.hpp.

◆ pfn_free

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 370 of file common.hpp.

Function Documentation

◆ set_callbacks()

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.
the error callback must never return: see pfn_error for more details

Definition at line 113 of file common.cpp.

114 {
115  s_default_callbacks = c;
116 }

Referenced by sample::ScopedErrorHandlerExample::ScopedErrorHandlerExample(), sample::ScopedErrorHandlerExample::~ScopedErrorHandlerExample(), c4::yml::reset_callbacks(), sample::sample_error_handler(), and sample::sample_global_allocator().

◆ get_callbacks()

Callbacks const & c4::yml::get_callbacks ( )

get the global callbacks

Warning
This function is not thread-safe.

Definition at line 118 of file common.cpp.

119 {
120  return s_default_callbacks;
121 }

Referenced by sample::ErrorHandlerExample::check_effect(), and sample::sample_global_allocator().

◆ reset_callbacks()

void c4::yml::reset_callbacks ( )

set the global callbacks back to their defaults ()

Warning
This function is not thread-safe.

Definition at line 123 of file common.cpp.

124 {
125  set_callbacks(Callbacks());
126 }
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:113

References c4::yml::set_callbacks().