rapidyaml  0.12.1
parse and emit YAML, and do it fast
GlobalAllocatorExample Struct Reference

Public Member Functions

void * allocate (size_t len)
 
void free (void *mem, size_t len)
 
ryml::Callbacks callbacks ()
 
 ~GlobalAllocatorExample ()
 
void check_and_reset ()
 

Static Public Member Functions

static void * s_allocate (size_t len, void *, void *this_)
 
static void s_free (void *mem, size_t len, void *this_)
 

Public Attributes

std::vector< char > memory_pool = std::vector<char>(10u * 1024u)
 
size_t num_allocs = 0
 
size_t alloc_size = 0
 
size_t corr_size = 0
 
size_t num_deallocs = 0
 
size_t dealloc_size = 0
 

Detailed Description

Definition at line 5569 of file quickstart.cpp.

Constructor & Destructor Documentation

◆ ~GlobalAllocatorExample()

GlobalAllocatorExample::~GlobalAllocatorExample ( )
inline

Definition at line 5624 of file quickstart.cpp.

Member Function Documentation

◆ allocate()

void* GlobalAllocatorExample::allocate ( size_t  len)
inline

Definition at line 5575 of file quickstart.cpp.

5575  {
5576  const ryml::Tree tree = ryml::parse_in_arena(ymlfile, ymlsrc);
5577  bool gotit = false;
5578  try
5579  {
5580  int intval = 0;
5581  tree["float"] >> intval; // cannot deserialize 123.456 to int
5582  }
5583  catch(ryml::ExceptionVisit const& exc)
5584  {
5585  gotit = true;
5586  ryml::csubstr msg = ryml::to_csubstr(exc.what());
5587  CHECK(!exc.errdata_visit.cpploc.name.empty());
5588  CHECK(exc.errdata_visit.tree == &tree);
5589  CHECK(exc.errdata_visit.node == tree["float"].id());
5590  CHECK(!msg.empty());
5591  }
5592  CHECK(gotit);
5593  }
5594  // you can also catch the exception as its base,
5595  // ryml::ExceptionBasic:
void parse_in_arena(Parser *parser, csubstr filename, csubstr yaml, Tree *t, id_type node_id)
(1) parse YAML into an existing tree node. The filename will be used in any error messages arising du...
Definition: parse.cpp:91
#define CHECK(predicate)
a quick'n'dirty assertion to verify a predicate
Definition: quickstart.cpp:294
csubstr to_csubstr(substr s) noexcept
neutral version for use in generic code
Definition: substr.hpp:2210
Location cpploc
location in the C++ source file where the error was detected.
Definition: common.hpp:332
Tree const * tree
tree where the error was detected
Definition: common.hpp:333
id_type node
node where the error was detected
Definition: common.hpp:334
const char * what() const noexcept override
Definition: error.hpp:478
Exception thrown by the default visit error implementation.
Definition: error.hpp:512
ErrorDataVisit errdata_visit
Definition: error.hpp:514
csubstr name
name of the file
Definition: common.hpp:287

References CHECK, c4::yml::ErrorDataVisit::cpploc, c4::yml::ExceptionVisit::errdata_visit, c4::yml::Tree::id(), c4::yml::Location::name, c4::yml::ErrorDataVisit::node, c4::yml::parse_in_arena(), c4::to_csubstr(), c4::yml::ErrorDataVisit::tree, and c4::yml::ExceptionBasic::what().

◆ free()

void GlobalAllocatorExample::free ( void *  mem,
size_t  len 
)
inline

Definition at line 5597 of file quickstart.cpp.

5600  {
5601  int intval = 0;
5602  tree["float"] >> intval; // cannot deserialize 123.456 to int
5603  }
5604  catch(ryml::ExceptionBasic const& exc) // use references! don't slice the exception
Exception thrown by the default basic error implementation.
Definition: error.hpp:476

◆ callbacks()

ryml::Callbacks GlobalAllocatorExample::callbacks ( )
inline

Definition at line 5607 of file quickstart.cpp.

5623 {

◆ s_allocate()

static void* GlobalAllocatorExample::s_allocate ( size_t  len,
void *  ,
void *  this_ 
)
inlinestatic

Definition at line 5614 of file quickstart.cpp.

5623 {

◆ s_free()

static void GlobalAllocatorExample::s_free ( void *  mem,
size_t  len,
void *  this_ 
)
inlinestatic

Definition at line 5618 of file quickstart.cpp.

5618  : when the tree is obtained from parsing YAML, the messages
5619  * may be enriched by using a parser set to track the locations. See
5620  * @ref sample_location_tracking() for more details on how to use
5621  * locations. */
void sample_location_tracking()
demonstrates how to obtain the (zero-based) location of a node from a recently parsed tree
@ YAML
yaml directive: \YAML <version>

◆ check_and_reset()

void GlobalAllocatorExample::check_and_reset ( )
inline

Definition at line 5628 of file quickstart.cpp.

5631  {}.locations(true);
5632  ryml::EventHandlerTree evt_handler{};
5633  ryml::Parser parser(&evt_handler, opts);
5634  ryml::csubstr ymlfile = "file.yml";
5635  ryml::csubstr ymlsrc = R"(foo: bar
5636 char: a
5637 int: a
5638 float: 123.456
5639 )";
This is the main driver of parsing logic: it scans the YAML or JSON source for tokens,...
The event handler to create a ryml Tree.

Member Data Documentation

◆ memory_pool

std::vector<char> GlobalAllocatorExample::memory_pool = std::vector<char>(10u * 1024u)

Definition at line 5571 of file quickstart.cpp.

◆ num_allocs

size_t GlobalAllocatorExample::num_allocs = 0

Definition at line 5572 of file quickstart.cpp.

◆ alloc_size

size_t GlobalAllocatorExample::alloc_size = 0

Definition at line 5572 of file quickstart.cpp.

◆ corr_size

size_t GlobalAllocatorExample::corr_size = 0

Definition at line 5572 of file quickstart.cpp.

◆ num_deallocs

size_t GlobalAllocatorExample::num_deallocs = 0

Definition at line 5573 of file quickstart.cpp.

◆ dealloc_size

size_t GlobalAllocatorExample::dealloc_size = 0

Definition at line 5573 of file quickstart.cpp.


The documentation for this struct was generated from the following file: