rapidyaml  0.16.0
parseandemitYAML,anddoitfast
c4::yml::Callbacks Struct Reference

A c-style callbacks class to customize behavior on errors or allocation. 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_basic error_basic)
 
Callbacks & set_user_data (void *user_data)
 Set the user data. More...
 
Callbacks & set_allocate (pfn_allocate allocate=nullptr)
 Set or reset the allocate callback. More...
 
Callbacks & set_free (pfn_free free=nullptr)
 Set or reset the free callback. More...
 
Callbacks & set_error_basic (pfn_error_basic error_basic=nullptr)
 Set or reset the error_basic callback. More...
 
Callbacks & set_error_parse (pfn_error_parse error_parse=nullptr)
 Set or reset the error_parse callback. More...
 
Callbacks & set_error_visit (pfn_error_visit error_visit=nullptr)
 Set or reset the error_visit callback. More...
 
bool operator!= (Callbacks const &that) const
 
bool operator== (Callbacks const &that) const
 

Public Attributes

void * m_user_data
 data to be forwarded in every call to a callback More...
 
pfn_allocate m_allocate
 a pointer to an allocate handler function More...
 
pfn_free m_free
 a pointer to a free handler function More...
 
pfn_error_basic m_error_basic
 a pointer to a basic error handler function More...
 
pfn_error_parse m_error_parse
 a pointer to a parse error handler function More...
 
pfn_error_visit m_error_visit
 a pointer to a visit error handler function More...
 

Detailed Description

A c-style callbacks class to customize behavior on errors or allocation.

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

Definition at line 373 of file common.hpp.

Constructor & Destructor Documentation

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

Construct an object with the default callbacks.

If RYML_NO_DEFAULT_CALLBACKS is defined, the object will be set with null members.

Definition at line 105 of file common.cpp.

106  :
107  m_user_data(nullptr),
108  #ifndef RYML_NO_DEFAULT_CALLBACKS
109  m_allocate(allocate_impl),
110  m_free(free_impl),
111  m_error_basic(error_basic_impl),
112  m_error_parse(error_parse_impl),
113  m_error_visit(error_visit_impl)
114  #else
115  m_allocate(nullptr),
116  m_free(nullptr),
117  m_error_basic(nullptr),
118  m_error_parse(nullptr),
119  m_error_visit(nullptr)
120  #endif
121 {
122 }
void * m_user_data
data to be forwarded in every call to a callback
Definition: common.hpp:375
pfn_error_parse m_error_parse
a pointer to a parse error handler function
Definition: common.hpp:379
pfn_free m_free
a pointer to a free handler function
Definition: common.hpp:377
pfn_error_basic m_error_basic
a pointer to a basic error handler function
Definition: common.hpp:378
pfn_error_visit m_error_visit
a pointer to a visit error handler function
Definition: common.hpp:380
pfn_allocate m_allocate
a pointer to an allocate handler function
Definition: common.hpp:376
c4::yml::Callbacks::Callbacks ( void *  user_data,
pfn_allocate  alloc,
pfn_free  free,
pfn_error_basic  error_basic 
)

Definition at line 124 of file common.cpp.

125  :
126  m_user_data(user_data),
127  #ifndef RYML_NO_DEFAULT_CALLBACKS
128  m_allocate(alloc_ ? alloc_ : allocate_impl),
129  m_free(free_ ? free_ : free_impl),
130  m_error_basic(error_basic_ ? error_basic_ : error_basic_impl),
131  m_error_parse(error_parse_impl),
132  m_error_visit(error_visit_impl)
133  #else
134  m_allocate(alloc_),
135  m_free(free_),
136  m_error_basic(error_basic_),
137  m_error_parse(nullptr),
138  m_error_visit(nullptr)
139  #endif
140 {
141 }
void * m_user_data
data to be forwarded in every call to a callback
Definition: common.hpp:375
pfn_error_parse m_error_parse
a pointer to a parse error handler function
Definition: common.hpp:379
pfn_free m_free
a pointer to a free handler function
Definition: common.hpp:377
pfn_error_basic m_error_basic
a pointer to a basic error handler function
Definition: common.hpp:378
pfn_error_visit m_error_visit
a pointer to a visit error handler function
Definition: common.hpp:380
pfn_allocate m_allocate
a pointer to an allocate handler function
Definition: common.hpp:376

Member Function Documentation

Callbacks & c4::yml::Callbacks::set_user_data ( void *  user_data)

Set the user data.

Definition at line 144 of file common.cpp.

Referenced by ErrorHandlerExample::callbacks(), and GlobalAllocatorExample::callbacks().

145 {
146  m_user_data = user_data;
147  return *this;
148 }
void * m_user_data
data to be forwarded in every call to a callback
Definition: common.hpp:375
Callbacks & c4::yml::Callbacks::set_allocate ( pfn_allocate  allocate = nullptr)

Set or reset the allocate callback.

When the parameter is null, m_allocate will fall back to ryml's default allocate implementation, unless RYML_NO_DEFAULT_CALLBACKS is defined.

Definition at line 150 of file common.cpp.

Referenced by GlobalAllocatorExample::callbacks(), and default_callbacks().

151 {
152  m_allocate = allocate;
153  #ifndef RYML_NO_DEFAULT_CALLBACKS
154  m_allocate = m_allocate ? m_allocate : allocate_impl;
155  #endif
156  return *this;
157 }
pfn_allocate m_allocate
a pointer to an allocate handler function
Definition: common.hpp:376
Callbacks & c4::yml::Callbacks::set_free ( pfn_free  free = nullptr)

Set or reset the free callback.

When the parameter is null, m_free will fall back to ryml's default free implementation, unless RYML_NO_DEFAULT_CALLBACKS is defined.

Definition at line 159 of file common.cpp.

Referenced by GlobalAllocatorExample::callbacks().

160 {
161  m_free = free;
162  #ifndef RYML_NO_DEFAULT_CALLBACKS
163  m_free = m_free ? m_free : free_impl;
164  #endif
165  return *this;
166 }
pfn_free m_free
a pointer to a free handler function
Definition: common.hpp:377
Callbacks & c4::yml::Callbacks::set_error_basic ( pfn_error_basic  error_basic = nullptr)

Set or reset the error_basic callback.

When the parameter is null, m_error_basic will fall back to ryml's default error_basic implementation, unless RYML_NO_DEFAULT_CALLBACKS is defined.

Definition at line 168 of file common.cpp.

Referenced by ErrorHandlerExample::callbacks().

169 {
170  m_error_basic = error_basic;
171  #ifndef RYML_NO_DEFAULT_CALLBACKS
172  m_error_basic = m_error_basic ? m_error_basic : error_basic_impl;
173  #endif
174  return *this;
175 }
pfn_error_basic m_error_basic
a pointer to a basic error handler function
Definition: common.hpp:378
Callbacks & c4::yml::Callbacks::set_error_parse ( pfn_error_parse  error_parse = nullptr)

Set or reset the error_parse callback.

When the parameter is null, m_error_parse will fall back to ryml's default error_parse implementation, unless RYML_NO_DEFAULT_CALLBACKS is defined.

Definition at line 177 of file common.cpp.

Referenced by ErrorHandlerExample::callbacks().

178 {
179  m_error_parse = error_parse;
180  #ifndef RYML_NO_DEFAULT_CALLBACKS
181  m_error_parse = m_error_parse ? m_error_parse : error_parse_impl;
182  #endif
183  return *this;
184 }
pfn_error_parse m_error_parse
a pointer to a parse error handler function
Definition: common.hpp:379
Callbacks & c4::yml::Callbacks::set_error_visit ( pfn_error_visit  error_visit = nullptr)

Set or reset the error_visit callback.

When the parameter is null, m_error_visit will fall back to ryml's default error_visit implementation, unless RYML_NO_DEFAULT_CALLBACKS is defined.

Definition at line 186 of file common.cpp.

Referenced by ErrorHandlerExample::callbacks().

187 {
188  m_error_visit = error_visit;
189  #ifndef RYML_NO_DEFAULT_CALLBACKS
190  m_error_visit = m_error_visit ? m_error_visit : error_visit_impl;
191  #endif
192  return *this;
193 }
pfn_error_visit m_error_visit
a pointer to a visit error handler function
Definition: common.hpp:380
bool c4::yml::Callbacks::operator!= ( Callbacks const &  that) const
inline

Definition at line 425 of file common.hpp.

425 { return !operator==(that); }
bool operator==(Callbacks const &that) const
Definition: common.hpp:426
bool c4::yml::Callbacks::operator== ( Callbacks const &  that) const
inline

Definition at line 426 of file common.hpp.

427  {
428  return (m_user_data == that.m_user_data &&
429  m_allocate == that.m_allocate &&
430  m_free == that.m_free &&
431  m_error_basic == that.m_error_basic &&
432  m_error_parse == that.m_error_parse &&
433  m_error_visit == that.m_error_visit);
434  }
void * m_user_data
data to be forwarded in every call to a callback
Definition: common.hpp:375
pfn_error_parse m_error_parse
a pointer to a parse error handler function
Definition: common.hpp:379
pfn_free m_free
a pointer to a free handler function
Definition: common.hpp:377
pfn_error_basic m_error_basic
a pointer to a basic error handler function
Definition: common.hpp:378
pfn_error_visit m_error_visit
a pointer to a visit error handler function
Definition: common.hpp:380
pfn_allocate m_allocate
a pointer to an allocate handler function
Definition: common.hpp:376

Member Data Documentation

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

data to be forwarded in every call to a callback

Definition at line 375 of file common.hpp.

Referenced by PerTreeMemoryExample::callbacks(), c4::yml::err_basic(), c4::yml::err_parse(), c4::yml::err_visit(), operator==(), and set_user_data().

pfn_allocate c4::yml::Callbacks::m_allocate

a pointer to an allocate handler function

Definition at line 376 of file common.hpp.

Referenced by PerTreeMemoryExample::callbacks(), ErrorHandlerExample::check_disabled(), ErrorHandlerExample::check_enabled(), operator==(), and set_allocate().

pfn_free c4::yml::Callbacks::m_free

a pointer to a free handler function

Definition at line 377 of file common.hpp.

Referenced by PerTreeMemoryExample::callbacks(), ErrorHandlerExample::check_disabled(), ErrorHandlerExample::check_enabled(), operator==(), and set_free().

pfn_error_basic c4::yml::Callbacks::m_error_basic
pfn_error_parse c4::yml::Callbacks::m_error_parse

a pointer to a parse error handler function

Definition at line 379 of file common.hpp.

Referenced by ErrorHandlerExample::check_disabled(), ErrorHandlerExample::check_enabled(), c4::yml::err_parse(), operator==(), sample_error_parse(), and set_error_parse().

pfn_error_visit c4::yml::Callbacks::m_error_visit

a pointer to a visit error handler function

Definition at line 380 of file common.hpp.

Referenced by ErrorHandlerExample::check_disabled(), ErrorHandlerExample::check_enabled(), c4::yml::err_visit(), operator==(), sample_error_visit(), and set_error_visit().


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