1#ifndef _C4_YML_COMMON_HPP_
2#define _C4_YML_COMMON_HPP_
11#ifndef _C4_CHARCONV_HPP_
14#ifndef _C4_YML_EXPORT_HPP_
21#ifndef RYML_DEFAULT_TREE_CAPACITY
23#define RYML_DEFAULT_TREE_CAPACITY (16)
26#ifndef RYML_DEFAULT_TREE_ARENA_CAPACITY
28#define RYML_DEFAULT_TREE_ARENA_CAPACITY (0)
32#ifndef RYML_LOCATIONS_SMALL_THRESHOLD
35#define RYML_LOCATIONS_SMALL_THRESHOLD (30)
39#ifndef RYML_ERRMSG_SIZE
41#define RYML_ERRMSG_SIZE (1024)
45#ifndef RYML_LOGBUF_SIZE
51#define RYML_LOGBUF_SIZE (256)
55#ifndef RYML_LOGBUF_SIZE
61#define RYML_LOGBUF_SIZE (256)
66#ifndef RYML_LOGBUF_SIZE_MAX
73#define RYML_LOGBUF_SIZE_MAX (1024)
191# define RYML_USE_ASSERT
195# define RYML_NO_DEFAULT_CALLBACKS
200# define RYML_DEFAULT_CALLBACK_USES_EXCEPTIONS
204# define RYML_NOEXCEPT
209# defined RYML_SHORT_CHECK_MSG
218#ifndef RYML_USE_ASSERT
219# define RYML_USE_ASSERT C4_USE_ASSERT
223# define RYML_NOEXCEPT
225# define RYML_NOEXCEPT noexcept
228#define RYML_DEPRECATED(msg) C4_DEPRECATED(msg)
240C4_SUPPRESS_WARNING_GCC_CLANG_WITH_PUSH(
"-Wold-style-cast")
249#define RYML_ID_TYPE size_t
257static_assert(std::is_integral<id_type>::value,
"id_type must be an integer type");
260C4_SUPPRESS_WARNING_GCC_WITH_PUSH(
"-Wuseless-cast")
265C4_SUPPRESS_WARNING_GCC_CLANG_POP
288C4_SUPPRESS_WARNING_MSVC_WITH_PUSH(4251)
315static_assert(std::is_standard_layout<Location>::value,
"Location not trivial");
317C4_SUPPRESS_WARNING_MSVC_POP
320#define RYML_LOC_HERE() (::c4::yml::Location(__FILE__, static_cast<size_t>(__LINE__)))
390using pfn_allocate =
void* (*)(
size_t len,
void* hint,
void *user_data);
395using pfn_free = void (*)(
void* mem,
size_t size,
void *user_data);
433using pfn_error RYML_DEPRECATED(
"use a more specific error type: `basic`, `parse` or `visit`") = void (*) (
const char* msg,
size_t msg_len,
Location const& cpploc,
void *user_data);
456 RYML_DEPRECATED(
"use the default constructor, followed by the appropriate setters")
514#define _RYML_CB_ALLOC_HINT(cb, T, num, hint) (T*) (cb).m_allocate((num) * sizeof(T), (hint), (cb).m_user_data)
515#define _RYML_CB_ALLOC(cb, T, num) _RYML_CB_ALLOC_HINT((cb), T, (num), nullptr)
516#define _RYML_CB_FREE(cb, buf, T, num) \
518 (cb).m_free((buf), (num) * sizeof(T), (cb).m_user_data); \
523template<
int8_t
signedval, u
int8_t
unsignedval>
524struct _charconstant_t
525 :
public std::conditional<std::is_signed<char>::value,
526 std::integral_constant<int8_t, static_cast<int8_t>(unsignedval)>,
527 std::integral_constant<uint8_t, unsignedval>>::type
529#define _RYML_CHCONST(signedval, unsignedval) ::c4::yml::detail::_charconstant_t<INT8_C(signedval), UINT8_C(unsignedval)>::value
532inline csubstr _c4prc(
const char &C4_RESTRICT c)
536 case '\n':
return csubstr(
"\\n");
537 case '\t':
return csubstr(
"\\t");
538 case '\0':
return csubstr(
"\\0");
539 case '\r':
return csubstr(
"\\r");
540 case '\f':
return csubstr(
"\\f");
541 case '\b':
return csubstr(
"\\b");
542 case '\v':
return csubstr(
"\\v");
543 case '\a':
return csubstr(
"\\a");
544 default:
return csubstr(&c, 1);
550C4_SUPPRESS_WARNING_GCC_POP
Lightweight generic type-safe wrappers for converting individual values to/from strings.
#define RYML_ID_TYPE
The type of a node id in the YAML tree.
#define RYML_ERRMSG_SIZE
size for the error message buffer
#define RYML_LOGBUF_SIZE
size for the buffer used to format individual values to string while preparing an error message....
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...
void(*)(csubstr msg, ErrorDataVisit const &errdata, void *user_data) pfn_error_visit
the type of the function used to report visit errors.
void reset_callbacks()
set the global callbacks back to their defaults.
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 set_callbacks(Callbacks const &c)
set the global callbacks for the library; after a call to this function, these callbacks will be used...
void(*)(csubstr msg, ErrorDataParse const &errdata, void *user_data) pfn_error_parse
the type of the function used to report parse errors.
Callbacks const & get_callbacks()
get the global callbacks
void(*)(csubstr msg, ErrorDataBasic const &errdata, void *user_data) pfn_error_basic
the type of the function used to report basic errors.
csubstr to_csubstr(const char(&s)[N]) noexcept
basic_substring< const char > csubstr
an immutable string view
@ npos
a null string position
RYML_ID_TYPE id_type
The type of a node id in the YAML tree; to override the default type, define the macro RYML_ID_TYPE t...
@ UTF16BE
UTF16, Big-Endian.
@ UTF16LE
UTF16, Little-Endian.
@ NOBOM
No Byte Order Mark was found.
@ UTF32BE
UTF32, Big-Endian.
@ UTF32LE
UTF32, Little-Endian.
enum c4::yml::Encoding_ Encoding_e
(Undefined by default) Use shorter error message from checks/asserts: do not show the check condition...
pfn_error_basic m_error_basic
a pointer to a basic error handler function
pfn_error_parse m_error_parse
a pointer to a parse error handler function
Callbacks & set_error_visit(pfn_error_visit error_visit=nullptr)
Set or reset the error_visit callback.
Callbacks & set_free(pfn_free free=nullptr)
Set or reset the free callback.
void * m_user_data
data to be forwarded in every call to a callback
pfn_allocate m_allocate
a pointer to an allocate handler function
bool operator==(Callbacks const &that) const
Callbacks() noexcept
Construct an object with the default callbacks.
Callbacks & set_error_parse(pfn_error_parse error_parse=nullptr)
Set or reset the error_parse callback.
Callbacks & set_allocate(pfn_allocate allocate=nullptr)
Set or reset the allocate callback.
Callbacks & set_error_basic(pfn_error_basic error_basic=nullptr)
Set or reset the error_basic callback.
pfn_error_visit m_error_visit
a pointer to a visit error handler function
pfn_free m_free
a pointer to a free handler function
Callbacks & set_user_data(void *user_data)
Set the user data.
ErrorDataBasic() noexcept=default
Location location
location where the error was detected (may be from YAML or C++ source code)
Location cpploc
location in the C++ source file where the error was detected.
ErrorDataParse() noexcept=default
Location ymlloc
location in the YAML source buffer where the error was detected.
ErrorDataVisit() noexcept=default
Location cpploc
location in the C++ source file where the error was detected.
Tree const * tree
tree where the error was detected
id_type node
node where the error was detected
holds a source or yaml file position, for example when an error is detected; See also location_format...
Location(const char *n, size_t l) noexcept
Location(csubstr n, size_t l) noexcept
Location(const char *n, size_t l, size_t c) noexcept
Location(csubstr n, size_t l, size_t c) noexcept
Location(size_t l, size_t c) noexcept
size_t offset
number of bytes from the beginning of the source buffer
Location(size_t b, size_t l, size_t c) noexcept
csubstr name
name of the file
Location(csubstr n, size_t b, size_t l, size_t c) noexcept
Location(const char *n, size_t b, size_t l, size_t c) noexcept
Location(size_t l) noexcept