1#ifndef C4_YML_COMMON_HPP_
2#define C4_YML_COMMON_HPP_
12#ifndef C4_YML_EXPORT_HPP_
19#ifndef RYML_DEFAULT_TREE_CAPACITY
21#define RYML_DEFAULT_TREE_CAPACITY (16)
24#ifndef RYML_DEFAULT_TREE_ARENA_CAPACITY
26#define RYML_DEFAULT_TREE_ARENA_CAPACITY (0)
29#ifndef RYML_DEFAULT_TREE_ARENA_CAPACITY_START
32#define RYML_DEFAULT_TREE_ARENA_CAPACITY_START (256)
36#ifndef RYML_LOCATIONS_SMALL_THRESHOLD
39#define RYML_LOCATIONS_SMALL_THRESHOLD (30)
43#ifndef RYML_ERRMSG_SIZE
45#define RYML_ERRMSG_SIZE (1024)
49#ifndef RYML_LOGBUF_SIZE
55#define RYML_LOGBUF_SIZE (256)
60#ifndef RYML_LOGBUF_SIZE_MAX
67#define RYML_LOGBUF_SIZE_MAX (1024)
75#ifndef RYML_USE_ASSERT
76# define RYML_USE_ASSERT C4_USE_ASSERT
82# define RYML_NOEXCEPT noexcept
85#define RYML_DEPRECATED(msg) C4_DEPRECATED(msg)
87#ifdef RYML_WITH_LEGACY_OPERATORS
88# define RYML_LEGACY_OPERATOR(txt)
90# define RYML_LEGACY_OPERATOR(txt) RYML_DEPRECATED(txt ". To enable this legacy operator, define the symbol RYML_WITH_LEGACY_OPERATORS while compiling")
93#define RYML_CHECK_TYPE_IS_WRAPPER_LIKE_(type) \
94 static_assert(!std::is_fundamental<type>::value, \
95 "did you forget to use '&'? " \
96 "This overload is for wrapper types such as c4::fmt::base64()");
108C4_SUPPRESS_WARNING_GCC_CLANG_WITH_PUSH(
"-Wold-style-cast")
117#define RYML_ID_TYPE size_t
125static_assert(std::is_integral<id_type>::value,
"id_type must be an integer type");
128C4_SUPPRESS_WARNING_GCC_WITH_PUSH(
"-Wuseless-cast")
133C4_SUPPRESS_WARNING_GCC_CLANG_POP
169 operator bool() const noexcept {
return node ==
VALID; }
213 :
node(result.node) {}
221C4_SUPPRESS_WARNING_MSVC_WITH_PUSH(4251)
248static_assert(std::is_standard_layout<Location>::value,
"Location not trivial");
250C4_SUPPRESS_WARNING_MSVC_POP
253#define RYML_LOC_HERE() (::c4::yml::Location(__FILE__, static_cast<size_t>(__LINE__)))
323using pfn_allocate =
void* (*)(
size_t len,
void* hint,
void *user_data);
328using pfn_free = void (*)(
void* mem,
size_t size,
void *user_data);
366using 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);
389 RYML_DEPRECATED(
"use the default constructor, followed by the appropriate setters")
446C4_SUPPRESS_WARNING_PUSH
447C4_SUPPRESS_WARNING_GCC_CLANG(
"-Wdeprecated")
448C4_SUPPRESS_WARNING_GCC_CLANG(
"-Wdeprecated-declarations")
449C4_SUPPRESS_WARNING_MSVC(4996)
454struct RYML_LEGACY_OPERATOR(
"prefer .set_key() methods in the Tree and node")
463RYML_LEGACY_OPERATOR(
"prefer .set_key() methods in the Tree and node")
464C4_ALWAYS_INLINE Key<K> key(K && k)
466 return Key<K>{std::forward<K>(k)};
469C4_SUPPRESS_WARNING_POP
479#define RYML_CB_ALLOC_HINT_(cb, T, num, hint) (T*) (cb).m_allocate((num) * sizeof(T), (hint), (cb).m_user_data)
480#define RYML_CB_ALLOC_(cb, T, num) RYML_CB_ALLOC_HINT_((cb), T, (num), nullptr)
481#define RYML_CB_FREE_(cb, buf, T, num) \
483 (cb).m_free((buf), (num) * sizeof(T), (cb).m_user_data); \
488template<
int8_t
signedval, u
int8_t
unsignedval>
489struct _charconstant_t
490 :
public std::conditional<std::is_signed<char>::value,
491 std::integral_constant<int8_t, static_cast<int8_t>(unsignedval)>,
492 std::integral_constant<uint8_t, unsignedval>>::type
494#define RYML_CHCONST_(signedval, unsignedval) ::c4::yml::detail::_charconstant_t<INT8_C(signedval), UINT8_C(unsignedval)>::value
497inline csubstr _c4prc(
const char &C4_RESTRICT c)
501 case '\n':
return csubstr(
"\\n");
502 case '\t':
return csubstr(
"\\t");
503 case '\0':
return csubstr(
"\\0");
504 case '\r':
return csubstr(
"\\r");
505 case '\f':
return csubstr(
"\\f");
506 case '\b':
return csubstr(
"\\b");
507 case '\v':
return csubstr(
"\\v");
508 case '\a':
return csubstr(
"\\a");
509 default:
return csubstr(&c, 1);
514 || (defined(__GNUC__) && __GNUC__ >= 6) \
515 || (defined(_MSC_VER) && !defined(__clang__))
516#define RYML_HAS_DEPRECATED_ENUMS_
521C4_SUPPRESS_WARNING_GCC_POP
#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
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
ReadResult(id_type node_) noexcept
construct as failure on the given node id
ReadResult() noexcept
construct as success
ReadResult(bool ok, id_type node_) noexcept
adapter: will match legacy user code (read() implementations returning bool).
ReadResult(id_type parent_, id_type node_) noexcept
construct as failure on the given parent_, IF node_ is NONE
ReadResult(ReadResult result, id_type) noexcept
adapter: will match up-to-date user code (read() implementations returning ReadResult).