rapidyaml  0.8.0
parse and emit YAML, and do it fast
c4::yml::Callbacks Struct Reference

a c-style callbacks class. More...

#include <common.hpp>

Public Member Functions

 Callbacks () noexcept
 Construct an object with the default callbacks. More...
 
 Callbacks (void *user_data, pfn_allocate alloc, pfn_free free, pfn_error error)
 Construct an object with the given callbacks. More...
 
bool operator!= (Callbacks const &that) const
 
bool operator== (Callbacks const &that) const
 

Public Attributes

void * m_user_data
 
pfn_allocate m_allocate
 
pfn_free m_free
 
pfn_error m_error
 

Detailed Description

a c-style callbacks class.

Can be used globally by the library and/or locally by Tree and Parser objects.

Definition at line 375 of file common.hpp.

Constructor & Destructor Documentation

◆ Callbacks() [1/2]

c4::yml::Callbacks::Callbacks ( )
noexcept

Construct an object with the default callbacks.

If RYML_NO_DEFAULT_CALLBACKS is defined, the object will have null members.

Definition at line 79 of file common.cpp.

80  :
81  m_user_data(nullptr),
82  #ifndef RYML_NO_DEFAULT_CALLBACKS
86  #else
87  m_allocate(nullptr),
88  m_free(nullptr),
89  m_error(nullptr)
90  #endif
91 {
92 }
void free_impl(void *mem, size_t, void *)
Definition: common.cpp:71
void error_impl(const char *msg, size_t length, Location loc, void *)
Definition: common.cpp:49
void * allocate_impl(size_t length, void *, void *)
Definition: common.cpp:60
void * m_user_data
Definition: common.hpp:377
pfn_allocate m_allocate
Definition: common.hpp:378
pfn_free m_free
Definition: common.hpp:379
pfn_error m_error
Definition: common.hpp:380

◆ Callbacks() [2/2]

c4::yml::Callbacks::Callbacks ( void *  user_data,
pfn_allocate  alloc,
pfn_free  free,
pfn_error  error 
)

Construct an object with the given callbacks.

Parameters
user_dataData to be forwarded in every call to a callback.
allocA pointer to an allocate function. Unless RYML_NO_DEFAULT_CALLBACKS is defined, when this parameter is null, will fall back to ryml's default alloc implementation.
freeA pointer to a free function. Unless RYML_NO_DEFAULT_CALLBACKS is defined, when this parameter is null, will fall back to ryml's default free implementation.
errorA pointer to an error function, which must never return (see pfn_error). Unless RYML_NO_DEFAULT_CALLBACKS is defined, when this parameter is null, will fall back to ryml's default error implementation.

Definition at line 94 of file common.cpp.

95  :
96  m_user_data(user_data),
97  #ifndef RYML_NO_DEFAULT_CALLBACKS
98  m_allocate(alloc_ ? alloc_ : allocate_impl),
99  m_free(free_ ? free_ : free_impl),
100  m_error((error_ ? error_ : error_impl))
101  #else
102  m_allocate(alloc_),
103  m_free(free_),
104  m_error(error_)
105  #endif
106 {
107  RYML_CHECK(m_allocate);
108  RYML_CHECK(m_free);
109  RYML_CHECK(m_error);
110 }

References m_allocate, m_error, and m_free.

Member Function Documentation

◆ operator!=()

bool c4::yml::Callbacks::operator!= ( Callbacks const &  that) const
inline

Definition at line 409 of file common.hpp.

409 { return !operator==(that); }
bool operator==(Callbacks const &that) const
Definition: common.hpp:410

References c4::operator==().

◆ operator==()

bool c4::yml::Callbacks::operator== ( Callbacks const &  that) const
inline

Definition at line 410 of file common.hpp.

411  {
412  return (m_user_data == that.m_user_data &&
413  m_allocate == that.m_allocate &&
414  m_free == that.m_free &&
415  m_error == that.m_error);
416  }

References m_allocate, m_error, m_free, and m_user_data.

Member Data Documentation

◆ m_user_data

void* c4::yml::Callbacks::m_user_data

Definition at line 377 of file common.hpp.

Referenced by sample::PerTreeMemoryExample::callbacks(), c4::yml::error(), and operator==().

◆ m_allocate

◆ m_free

◆ m_error

pfn_error c4::yml::Callbacks::m_error

The documentation for this struct was generated from the following files: