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
276 C4_SUPPRESS_WARNING_MSVC_WITH_PUSH(4251)
290 operator bool () const noexcept {
return !name.empty() || line !=
npos || offset !=
npos || col !=
npos; }
294 C4_NO_INLINE
Location(
size_t l,
size_t c) noexcept : offset(
npos), line(l), col(c ), name() {}
295 C4_NO_INLINE
Location(
size_t b,
size_t l,
size_t c) noexcept : offset(b ), line(l), col(c ), name() {}
296 C4_NO_INLINE
Location( csubstr n,
size_t l ) noexcept : offset(
npos), line(l), col(
npos), name(n) {}
297 C4_NO_INLINE
Location( csubstr n,
size_t l,
size_t c) noexcept : offset(
npos), line(l), col(c ), name(n) {}
298 C4_NO_INLINE
Location( csubstr n,
size_t b,
size_t l,
size_t c) noexcept : offset(b ), line(l), col(c ), name(n) {}
300 C4_NO_INLINE
Location(
const char *n,
size_t l,
size_t c) noexcept : offset(
npos), line(l), col(c ), name(
to_csubstr(n)) {}
301 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)) {}
303 static_assert(std::is_standard_layout<Location>::value,
"Location not trivial");
305 C4_SUPPRESS_WARNING_MSVC_POP
308 #define RYML_LOC_HERE() (::c4::yml::Location(__FILE__, static_cast<size_t>(__LINE__)))
353 typedef enum : uint32_t {
354 DETECT_FLOW_ML = (1u << 0u),
355 RESOLVE_TAGS = (1u << 1u),
356 RESOLVE_TAGS_ALL = (1u << 2u),
357 SCALAR_FILTERING = (1u << 3u),
358 LOCATIONS = (1u << 4u),
359 DEFAULTS = SCALAR_FILTERING|DETECT_FLOW_ML,
362 uint32_t flags = DEFAULTS;
388 return set_flags_(enabled, DETECT_FLOW_ML);
391 C4_ALWAYS_INLINE
bool detect_flow_ml() const noexcept {
return (flags & DETECT_FLOW_ML); }
406 return set_flags_(enabled, RESOLVE_TAGS);
409 C4_ALWAYS_INLINE
bool resolve_tags() const noexcept {
return (flags & RESOLVE_TAGS); }
416 return set_flags_(enabled, RESOLVE_TAGS_ALL);
419 C4_ALWAYS_INLINE
bool resolve_tags_all() const noexcept {
return (flags & RESOLVE_TAGS_ALL); }
431 return set_flags_(enabled, LOCATIONS);
434 C4_ALWAYS_INLINE
bool locations() const noexcept {
return (flags & LOCATIONS); }
446 return set_flags_(enabled, SCALAR_FILTERING);
449 C4_ALWAYS_INLINE
bool scalar_filtering() const noexcept {
return (flags & SCALAR_FILTERING); }
490 using pfn_allocate =
void* (*)(
size_t len,
void* hint,
void *user_data);
495 using pfn_free = void (*)(
void* mem,
size_t size,
void *user_data);
533 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);
556 RYML_DEPRECATED("use the default constructor, followed by the appropriate setters")
562 Callbacks& set_user_data(
void* user_data);
614 #define _RYML_CB_ALLOC_HINT(cb, T, num, hint) (T*) (cb).m_allocate((num) * sizeof(T), (hint), (cb).m_user_data)
615 #define _RYML_CB_ALLOC(cb, T, num) _RYML_CB_ALLOC_HINT((cb), T, (num), nullptr)
616 #define _RYML_CB_FREE(cb, buf, T, num) \
618 (cb).m_free((buf), (num) * sizeof(T), (cb).m_user_data); \
623 template<
int8_t
signedval, u
int8_t
unsignedval>
624 struct _charconstant_t
625 :
public std::conditional<std::is_signed<char>::value,
626 std::integral_constant<int8_t, static_cast<int8_t>(unsignedval)>,
627 std::integral_constant<uint8_t, unsignedval>>::type
629 #define _RYML_CHCONST(signedval, unsignedval) ::c4::yml::detail::_charconstant_t<INT8_C(signedval), UINT8_C(unsignedval)>::value
632 inline csubstr _c4prc(
const char &C4_RESTRICT c)
636 case '\n':
return csubstr(
"\\n");
637 case '\t':
return csubstr(
"\\t");
638 case '\0':
return csubstr(
"\\0");
639 case '\r':
return csubstr(
"\\r");
640 case '\f':
return csubstr(
"\\f");
641 case '\b':
return csubstr(
"\\b");
642 case '\v':
return csubstr(
"\\v");
643 case '\a':
return csubstr(
"\\a");
644 default:
return csubstr(&c, 1);
650 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
ParserOptions & resolve_tags_all(bool enabled) noexcept
When resolve_tags() is enabled, resolve not just prefixed tags of the form.
bool scalar_filtering() const noexcept
query scalar filtering status
ParserOptions & resolve_tags(bool enabled) noexcept
enable/disable resolution of YAML tags during parsing.
bool resolve_tags_all() const noexcept
query status of non-prefixed tag resolution setting.
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
bool resolve_tags() const noexcept
query status of tag resolution setting.
ParserOptions & detect_flow_ml(bool enabled) noexcept
enable/disable detection of FLOW_ML container style.