3 #ifndef RYML_NO_DEFAULT_CALLBACKS
6 # ifdef RYML_DEFAULT_CALLBACK_USES_EXCEPTIONS
15 C4_SUPPRESS_WARNING_GCC_CLANG_WITH_PUSH(
"-Wold-style-cast")
16 C4_SUPPRESS_WARNING_MSVC_WITH_PUSH(4702)
22 #ifndef RYML_NO_DEFAULT_CALLBACKS
33 fwrite(loc.
name.str, 1, loc.
name.len, f);
36 fprintf(f,
"%zu:", loc.
line);
38 fprintf(f,
"%zu:", loc.
col);
40 fprintf(f,
" (%zuB):", loc.
offset);
43 RYML_ASSERT(!csubstr(msg, length).ends_with(
'\0'));
44 fwrite(msg, 1, length, f);
51 RYML_ASSERT(!csubstr(msg, length).ends_with(
'\0'));
53 #ifdef RYML_DEFAULT_CALLBACK_USES_EXCEPTIONS
54 throw std::runtime_error(std::string(msg, length));
62 void *mem = ::malloc(length);
65 const char msg[] =
"could not allocate memory";
96 m_user_data(user_data),
115 s_default_callbacks = c;
120 return s_default_callbacks;
141 error(s_default_callbacks, msg, msg_len, loc);
145 C4_SUPPRESS_WARNING_MSVC_POP
146 C4_SUPPRESS_WARNING_GCC_CLANG_POP
Common utilities and infrastructure used by ryml.
#define RYML_NO_DEFAULT_CALLBACKS
(Undefined by default) Define this macro to disable ryml's default implementation of the callback fun...
void reset_callbacks()
set the global callbacks back to their defaults ()
void(*)(const char *msg, size_t msg_len, Location location, void *user_data) pfn_error
the type of the function used to report errors
void set_callbacks(Callbacks const &c)
set the global callbacks for the library; after a call to this function, these callbacks will be used...
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...
Callbacks const & get_callbacks()
get the global callbacks
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.
void free_impl(void *mem, size_t, void *)
void error(Callbacks const &cb, const char *msg, size_t msg_len, Location loc)
void error_impl(const char *msg, size_t length, Location loc, void *)
void * allocate_impl(size_t length, void *, void *)
void report_error_impl(const char *msg, size_t length, Location loc, FILE *f)
a c-style callbacks class.
Callbacks()
Construct an object with the default callbacks.
size_t offset
number of bytes from the beginning of the source buffer