rapidyaml  0.11.0
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 5540 of file quickstart.cpp.

Constructor & Destructor Documentation

◆ ~GlobalAllocatorExample()

GlobalAllocatorExample::~GlobalAllocatorExample ( )
inline

Definition at line 5595 of file quickstart.cpp.

Member Function Documentation

◆ allocate()

void* GlobalAllocatorExample::allocate ( size_t  len)
inline

Definition at line 5546 of file quickstart.cpp.

5546  {
5547  const ryml::Tree tree = ryml::parse_in_arena(ymlfile, ymlsrc);
5548  bool gotit = false;
5549  try
5550  {
5551  int intval = 0;
5552  tree["float"] >> intval; // cannot deserialize 123.456 to int
5553  }
5554  catch(ryml::ExceptionVisit const& exc)
5555  {
5556  gotit = true;
5557  ryml::csubstr msg = ryml::to_csubstr(exc.what());
5558  CHECK(!exc.errdata_visit.cpploc.name.empty());
5559  CHECK(exc.errdata_visit.tree == &tree);
5560  CHECK(exc.errdata_visit.node == tree["float"].id());
5561  CHECK(!msg.empty());
5562  }
5563  CHECK(gotit);
5564  }
5565  // you can also catch the exception as its base,
5566  // 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:278
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:458
Exception thrown by the default visit error implementation.
Definition: error.hpp:492
ErrorDataVisit errdata_visit
Definition: error.hpp:494
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 5568 of file quickstart.cpp.

5571  {
5572  int intval = 0;
5573  tree["float"] >> intval; // cannot deserialize 123.456 to int
5574  }
5575  catch(ryml::ExceptionBasic const& exc) // use references! don't slice the exception
Exception thrown by the default basic error implementation.
Definition: error.hpp:456

◆ callbacks()

ryml::Callbacks GlobalAllocatorExample::callbacks ( )
inline

Definition at line 5578 of file quickstart.cpp.

5594 {

◆ s_allocate()

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

Definition at line 5585 of file quickstart.cpp.

5594 {

◆ s_free()

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

Definition at line 5589 of file quickstart.cpp.

5589  : when the tree is obtained from parsing YAML, the messages
5590  * may be enriched by using a parser set to track the locations. See
5591  * @ref sample_location_tracking() for more details on how to use
5592  * 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 5599 of file quickstart.cpp.

5602  {}.locations(true);
5603  ryml::EventHandlerTree evt_handler{};
5604  ryml::Parser parser(&evt_handler, opts);
5605  ryml::csubstr ymlfile = "file.yml";
5606  ryml::csubstr ymlsrc = R"(foo: bar
5607 char: a
5608 int: a
5609 float: 123.456
5610 )";
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 5542 of file quickstart.cpp.

◆ num_allocs

size_t GlobalAllocatorExample::num_allocs = 0

Definition at line 5543 of file quickstart.cpp.

◆ alloc_size

size_t GlobalAllocatorExample::alloc_size = 0

Definition at line 5543 of file quickstart.cpp.

◆ corr_size

size_t GlobalAllocatorExample::corr_size = 0

Definition at line 5543 of file quickstart.cpp.

◆ num_deallocs

size_t GlobalAllocatorExample::num_deallocs = 0

Definition at line 5544 of file quickstart.cpp.

◆ dealloc_size

size_t GlobalAllocatorExample::dealloc_size = 0

Definition at line 5544 of file quickstart.cpp.


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