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)
179 # define RYML_USE_ASSERT
183 # define RYML_NO_DEFAULT_CALLBACKS
188 # define RYML_DEFAULT_CALLBACK_USES_EXCEPTIONS
192 # define RYML_NOEXCEPT
197 # defined RYML_SHORT_CHECK_MSG
206 #ifndef RYML_USE_ASSERT
207 # define RYML_USE_ASSERT C4_USE_ASSERT
211 # define RYML_NOEXCEPT
213 # define RYML_NOEXCEPT noexcept
216 #define RYML_DEPRECATED(msg) C4_DEPRECATED(msg)
228 C4_SUPPRESS_WARNING_GCC_CLANG_WITH_PUSH(
"-Wold-style-cast")
237 #define RYML_ID_TYPE size_t
245 static_assert(std::is_integral<id_type>::value,
"id_type must be an integer type");
248 C4_SUPPRESS_WARNING_GCC_WITH_PUSH(
"-Wuseless-cast")
253 C4_SUPPRESS_WARNING_GCC_CLANG_POP
289 operator bool () const noexcept {
return !name.empty() || line !=
npos || offset !=
npos || col !=
npos; }
293 C4_NO_INLINE
Location(
size_t l,
size_t c) noexcept : offset(
npos), line(l), col(c ), name() {}
294 C4_NO_INLINE
Location(
size_t b,
size_t l,
size_t c) noexcept : offset(b ), line(l), col(c ), name() {}
295 C4_NO_INLINE
Location( csubstr n,
size_t l ) noexcept : offset(
npos), line(l), col(
npos), name(n) {}
296 C4_NO_INLINE
Location( csubstr n,
size_t l,
size_t c) noexcept : offset(
npos), line(l), col(c ), name(n) {}
297 C4_NO_INLINE
Location( csubstr n,
size_t b,
size_t l,
size_t c) noexcept : offset(b ), line(l), col(c ), name(n) {}
299 C4_NO_INLINE
Location(
const char *n,
size_t l,
size_t c) noexcept : offset(
npos), line(l), col(c ), name(
to_csubstr(n)) {}
300 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)) {}
302 static_assert(std::is_standard_layout<Location>::value,
"Location not trivial");
305 #define RYML_LOC_HERE() (::c4::yml::Location(__FILE__, static_cast<size_t>(__LINE__)))
350 typedef enum : uint32_t {
351 SCALAR_FILTERING = (1u << 0u),
352 LOCATIONS = (1u << 1u),
353 DETECT_FLOW_ML = (1u << 2u),
354 DEFAULTS = SCALAR_FILTERING|DETECT_FLOW_ML,
357 uint32_t flags = DEFAULTS;
378 C4_ALWAYS_INLINE
bool locations() const noexcept {
return (flags & LOCATIONS); }
394 flags |= DETECT_FLOW_ML;
396 flags &= ~DETECT_FLOW_ML;
400 C4_ALWAYS_INLINE
bool detect_flow_ml() const noexcept {
return (flags & DETECT_FLOW_ML); }
413 flags |= SCALAR_FILTERING;
415 flags &= ~SCALAR_FILTERING;
419 C4_ALWAYS_INLINE
bool scalar_filtering() const noexcept {
return (flags & SCALAR_FILTERING); }
460 using pfn_allocate =
void* (*)(
size_t len,
void* hint,
void *user_data);
465 using pfn_free = void (*)(
void* mem,
size_t size,
void *user_data);
503 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);
526 RYML_DEPRECATED("use the default constructor, followed by the appropriate setters")
532 Callbacks& set_user_data(
void* user_data);
584 #define _RYML_CB_ALLOC_HINT(cb, T, num, hint) (T*) (cb).m_allocate((num) * sizeof(T), (hint), (cb).m_user_data)
585 #define _RYML_CB_ALLOC(cb, T, num) _RYML_CB_ALLOC_HINT((cb), T, (num), nullptr)
586 #define _RYML_CB_FREE(cb, buf, T, num) \
588 (cb).m_free((buf), (num) * sizeof(T), (cb).m_user_data); \
593 template<
int8_t
signedval, u
int8_t
unsignedval>
594 struct _charconstant_t
595 :
public std::conditional<std::is_signed<char>::value,
596 std::integral_constant<int8_t, static_cast<int8_t>(unsignedval)>,
597 std::integral_constant<uint8_t, unsignedval>>::type
599 #define _RYML_CHCONST(signedval, unsignedval) ::c4::yml::detail::_charconstant_t<INT8_C(signedval), UINT8_C(unsignedval)>::value
602 inline csubstr _c4prc(
const char &C4_RESTRICT c)
606 case '\n':
return csubstr(
"\\n");
607 case '\t':
return csubstr(
"\\t");
608 case '\0':
return csubstr(
"\\0");
609 case '\r':
return csubstr(
"\\r");
610 case '\f':
return csubstr(
"\\f");
611 case '\b':
return csubstr(
"\\b");
612 case '\v':
return csubstr(
"\\v");
613 case '\a':
return csubstr(
"\\a");
614 default:
return csubstr(&c, 1);
620 C4_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 reset_callbacks()
set the global callbacks back to their defaults.
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, ErrorDataVisit const &errdata, void *user_data) pfn_error_visit
the type of the function used to report visit errors.
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, 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.
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.
csubstr to_csubstr(substr s) noexcept
neutral version for use in generic code
bool operator==(const char(&s)[N], basic_substring< C > const that) noexcept
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...
A c-style callbacks class to customize behavior on errors or allocation.
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
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
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
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
Options to give to the parser to control its behavior.
ParserOptions & scalar_filtering(bool enabled) noexcept
enable/disable scalar filtering while parsing
bool scalar_filtering() const noexcept
query scalar filtering status
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 & locations(bool enabled) noexcept
enable/disable source location tracking
ParserOptions & detect_flow_ml(bool enabled) noexcept
enable/disable detection of FLOW_ML container style.