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
80 # define RYML_NOEXCEPT
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 avoid this warning, 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()");
108 C4_SUPPRESS_WARNING_GCC_CLANG_WITH_PUSH(
"-Wold-style-cast")
117 #define RYML_ID_TYPE size_t
125 static_assert(std::is_integral<id_type>::value,
"id_type must be an integer type");
128 C4_SUPPRESS_WARNING_GCC_WITH_PUSH(
"-Wuseless-cast")
133 C4_SUPPRESS_WARNING_GCC_CLANG_POP
169 operator bool() const noexcept {
return node == VALID; }
182 : node(node_ !=
NONE ? VALID : parent_) {}
201 : node(ok ? VALID : node_) {}
213 : node(result.node) {}
221 C4_SUPPRESS_WARNING_MSVC_WITH_PUSH(4251)
235 operator bool () const noexcept {
return !name.
empty() || line !=
npos || offset !=
npos || col !=
npos; }
237 C4_NO_INLINE
Location() noexcept : offset(
npos), line(npos), col(npos), name() {}
239 C4_NO_INLINE
Location(
size_t l,
size_t c) noexcept : offset(
npos), line(l), col(c ), name() {}
240 C4_NO_INLINE
Location(
size_t b,
size_t l,
size_t c) noexcept : offset(b ), line(l), col(c ), name() {}
242 C4_NO_INLINE
Location(
csubstr n,
size_t l,
size_t c) noexcept : offset(
npos), line(l), col(c ), name(n) {}
243 C4_NO_INLINE
Location(
csubstr n,
size_t b,
size_t l,
size_t c) noexcept : offset(b ), line(l), col(c ), name(n) {}
245 C4_NO_INLINE
Location(
const char *n,
size_t l,
size_t c) noexcept : offset(
npos), line(l), col(c ), name(
to_csubstr(n)) {}
246 C4_NO_INLINE
Location(
const char *n,
size_t b,
size_t l,
size_t c) noexcept : offset(b ), line(l), col(c ), name(
to_csubstr(n)) {}
248 static_assert(std::is_standard_layout<Location>::value,
"Location not trivial");
250 C4_SUPPRESS_WARNING_MSVC_POP
253 #define RYML_LOC_HERE() (::c4::yml::Location(__FILE__, static_cast<size_t>(__LINE__)))
273 ErrorDataParse(Location const& cpploc_, Location const& ymlloc_) noexcept : cpploc(cpploc_), ymlloc(ymlloc_) {}
323 using pfn_allocate =
void* (*)(
size_t len,
void* hint,
void *user_data);
328 using pfn_free = void (*)(
void* mem,
size_t size,
void *user_data);
366 using 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")
395 Callbacks& set_user_data(
void* user_data);
446 C4_SUPPRESS_WARNING_PUSH
447 C4_SUPPRESS_WARNING_GCC_CLANG(
"-Wdeprecated")
448 C4_SUPPRESS_WARNING_GCC_CLANG("-Wdeprecated-declarations")
449 C4_SUPPRESS_WARNING_MSVC(4996)
454 struct RYML_LEGACY_OPERATOR("prefer .set_key() methods in the Tree and node")
463 RYML_LEGACY_OPERATOR(
"prefer .set_key() methods in the Tree and node")
464 C4_ALWAYS_INLINE Key<K> key(K && k)
466 return Key<K>{std::forward<K>(k)};
469 C4_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); \
488 template<
int8_t
signedval, u
int8_t
unsignedval>
489 struct _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
497 inline 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_
521 C4_SUPPRESS_WARNING_GCC_POP
enum c4::yml::Encoding_ Encoding_e
Location cpploc
location in the C++ source file where the error was detected.
size_t offset
number of bytes from the beginning of the source buffer
A lightweight truthy type, used to enable reporting the offending node when a deserializing error hap...
ReadResult(id_type parent_, id_type node_) noexcept
construct as failure on the given parent_, IF node_ is NONE
Location(csubstr n, size_t l, size_t c) noexcept
Location(const char *n, size_t b, size_t l, size_t c) noexcept
#define RYML_ID_TYPE
The type of a node id in the YAML tree.
void set_callbacks(Callbacks const &c)
set the global callbacks for the library; after a call to this function, these callbacks will be used...
csubstr name
name of the file
A c-style callbacks class to customize behavior on errors or allocation.
ReadResult(id_type node_) noexcept
construct as failure on the given node id
Location ymlloc
location in the YAML source buffer where the error was detected.
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...
Location cpploc
location in the C++ source file where the error was detected.
Tree const * tree
tree where the error was detected
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...
Location(size_t l) noexcept
#define RYML_ERRMSG_SIZE
size for the error message buffer
ReadResult() noexcept
construct as success
Location location
location where the error was detected (may be from YAML or C++ source code)
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...
void(*)(csubstr msg, ErrorDataVisit const &errdata, void *user_data) pfn_error_visit
the type of the function used to report visit errors.
void * m_user_data
data to be forwarded in every call to a callback
Location(const char *n, size_t l) noexcept
pfn_error_parse m_error_parse
a pointer to a parse error handler function
csubstr to_csubstr(const char(&s)[N]) noexcept
basic_substring< const char > csubstr
an immutable string view
void(*)(csubstr msg, ErrorDataParse const &errdata, void *user_data) pfn_error_parse
the type of the function used to report parse errors.
pfn_free m_free
a pointer to a free handler function
holds a source or yaml file position, for example when an error is detected; See also location_format...
No Byte Order Mark was found.
pfn_error_basic m_error_basic
a pointer to a basic error handler function
Location(size_t l, size_t c) noexcept
ReadResult(ReadResult result, id_type) noexcept
adapter: will match up-to-date user code (read() implementations returning ReadResult).
#define RYML_LOGBUF_SIZE
size for the buffer used to format individual values to string while preparing an error message...
pfn_error_visit m_error_visit
a pointer to a visit error handler function
void reset_callbacks()
set the global callbacks back to their defaults.
id_type node
node where the error was detected
pfn_allocate m_allocate
a pointer to an allocate handler function
Location(size_t b, size_t l, size_t c) noexcept
Callbacks const & get_callbacks()
get the global callbacks
bool empty() const noexcept
Location(const char *n, size_t l, size_t c) noexcept
ReadResult(bool ok, id_type node_) noexcept
adapter: will match legacy user code (read() implementations returning bool).
void(*)(csubstr msg, ErrorDataBasic const &errdata, void *user_data) pfn_error_basic
the type of the function used to report basic errors.
Location(csubstr n, size_t l) noexcept
Location(csubstr n, size_t b, size_t l, size_t c) noexcept
bool operator==(const char c, basic_substring< C > const that) noexcept