1#ifndef _C4_YML_COMMON_HPP_
2#define _C4_YML_COMMON_HPP_
14#ifndef RYML_DEFAULT_TREE_CAPACITY
16#define RYML_DEFAULT_TREE_CAPACITY (16)
19#ifndef RYML_DEFAULT_TREE_ARENA_CAPACITY
21#define RYML_DEFAULT_TREE_ARENA_CAPACITY (0)
25#ifndef RYML_LOCATIONS_SMALL_THRESHOLD
28#define RYML_LOCATIONS_SMALL_THRESHOLD (30)
32#ifndef RYML_ERRMSG_SIZE
34#define RYML_ERRMSG_SIZE (1024)
38#ifndef RYML_LOGBUF_SIZE
44#define RYML_LOGBUF_SIZE (256)
48#ifndef RYML_LOGBUF_SIZE
54#define RYML_LOGBUF_SIZE (256)
59#ifndef RYML_LOGBUF_SIZE_MAX
66#define RYML_LOGBUF_SIZE_MAX (1024)
184# define RYML_USE_ASSERT
188# define RYML_NO_DEFAULT_CALLBACKS
193# define RYML_DEFAULT_CALLBACK_USES_EXCEPTIONS
197# define RYML_NOEXCEPT
202# defined RYML_SHORT_CHECK_MSG
211#ifndef RYML_USE_ASSERT
212# define RYML_USE_ASSERT C4_USE_ASSERT
216# define RYML_NOEXCEPT
218# define RYML_NOEXCEPT noexcept
221#define RYML_DEPRECATED(msg) C4_DEPRECATED(msg)
233C4_SUPPRESS_WARNING_GCC_CLANG_WITH_PUSH(
"-Wold-style-cast")
242#define RYML_ID_TYPE size_t
250static_assert(std::is_integral<id_type>::value,
"id_type must be an integer type");
253C4_SUPPRESS_WARNING_GCC_WITH_PUSH(
"-Wuseless-cast")
258C4_SUPPRESS_WARNING_GCC_CLANG_POP
281C4_SUPPRESS_WARNING_MSVC_WITH_PUSH(4251)
308static_assert(std::is_standard_layout<Location>::value,
"Location not trivial");
310C4_SUPPRESS_WARNING_MSVC_POP
313#define RYML_LOC_HERE() (::c4::yml::Location(__FILE__, static_cast<size_t>(__LINE__)))
358 typedef enum : uint32_t {
359 DETECT_FLOW_ML = (1u << 0u),
360 RESOLVE_TAGS = (1u << 1u),
361 RESOLVE_TAGS_ALL = (1u << 2u),
362 SCALAR_FILTERING = (1u << 3u),
363 LOCATIONS = (1u << 4u),
364 DEFAULTS = SCALAR_FILTERING|DETECT_FLOW_ML,
367 uint32_t flags = DEFAULTS;
393 return set_flags_(enabled, DETECT_FLOW_ML);
396 C4_ALWAYS_INLINE
bool detect_flow_ml() const noexcept {
return (flags & DETECT_FLOW_ML); }
411 return set_flags_(enabled, RESOLVE_TAGS);
414 C4_ALWAYS_INLINE
bool resolve_tags() const noexcept {
return (flags & RESOLVE_TAGS); }
421 return set_flags_(enabled, RESOLVE_TAGS_ALL);
424 C4_ALWAYS_INLINE
bool resolve_tags_all() const noexcept {
return (flags & RESOLVE_TAGS_ALL); }
436 return set_flags_(enabled, LOCATIONS);
439 C4_ALWAYS_INLINE
bool locations() const noexcept {
return (flags & LOCATIONS); }
451 return set_flags_(enabled, SCALAR_FILTERING);
454 C4_ALWAYS_INLINE
bool scalar_filtering() const noexcept {
return (flags & SCALAR_FILTERING); }
495using pfn_allocate =
void* (*)(
size_t len,
void* hint,
void *user_data);
500using pfn_free = void (*)(
void* mem,
size_t size,
void *user_data);
538using 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);
561 RYML_DEPRECATED(
"use the default constructor, followed by the appropriate setters")
619#define _RYML_CB_ALLOC_HINT(cb, T, num, hint) (T*) (cb).m_allocate((num) * sizeof(T), (hint), (cb).m_user_data)
620#define _RYML_CB_ALLOC(cb, T, num) _RYML_CB_ALLOC_HINT((cb), T, (num), nullptr)
621#define _RYML_CB_FREE(cb, buf, T, num) \
623 (cb).m_free((buf), (num) * sizeof(T), (cb).m_user_data); \
628template<
int8_t
signedval, u
int8_t
unsignedval>
629struct _charconstant_t
630 :
public std::conditional<std::is_signed<char>::value,
631 std::integral_constant<int8_t, static_cast<int8_t>(unsignedval)>,
632 std::integral_constant<uint8_t, unsignedval>>::type
634#define _RYML_CHCONST(signedval, unsignedval) ::c4::yml::detail::_charconstant_t<INT8_C(signedval), UINT8_C(unsignedval)>::value
637inline csubstr _c4prc(
const char &C4_RESTRICT c)
641 case '\n':
return csubstr(
"\\n");
642 case '\t':
return csubstr(
"\\t");
643 case '\0':
return csubstr(
"\\0");
644 case '\r':
return csubstr(
"\\r");
645 case '\f':
return csubstr(
"\\f");
646 case '\b':
return csubstr(
"\\b");
647 case '\v':
return csubstr(
"\\v");
648 case '\a':
return csubstr(
"\\a");
649 default:
return csubstr(&c, 1);
655C4_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
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...
@ npos
a null string position
@ 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
ParserOptions & detect_flow_ml(bool enabled) noexcept
enable/disable detection of FLOW_ML container style.
bool scalar_filtering() const noexcept
query scalar filtering status
ParserOptions & locations(bool enabled) noexcept
enable/disable source location tracking
bool resolve_tags_all() const noexcept
query status of non-prefixed tag resolution setting.
ParserOptions & scalar_filtering(bool enabled) noexcept
enable/disable scalar filtering while parsing
bool locations() const noexcept
query source location tracking status
bool detect_flow_ml() const noexcept
query status of detection of FLOW_ML container style.
ParserOptions & resolve_tags(bool enabled) noexcept
enable/disable resolution of YAML tags during parsing.
ParserOptions & resolve_tags_all(bool enabled) noexcept
When resolve_tags() is enabled, resolve not just prefixed tags of the form.
bool resolve_tags() const noexcept
query status of tag resolution setting.