rapidyaml  0.10.0
parse and emit YAML, and do it fast
Sample helpers

Functions and classes used in the examples of this sample. More...

Modules

 Serialize/deserialize scalar types
 
 Serialize/deserialize container types
 To serialize/deserialize container types to a tree, implement the appropriate functions:
 

Classes

struct  sample::ErrorHandlerExample
 this is an example error handler, required for some of the quickstart examples. More...
 
struct  sample::ScopedErrorHandlerExample
 Shows how to easily create a scoped error handler. More...
 
struct  sample::GlobalAllocatorExample
 
struct  sample::PerTreeMemoryExample
 an example for a per-tree memory allocator More...
 

Macros

#define CHECK(predicate)   assert(predicate)
 

Functions

bool sample::report_check (int line, const char *predicate, bool result)
 
template<class CharContainer >
CharContainer sample::file_get_contents (const char *filename)
 load a file from disk and return a newly created CharContainer More...
 
template<class CharContainer >
size_t sample::file_get_contents (const char *filename, CharContainer *v)
 load a file from disk into an existing CharContainer More...
 
template<class CharContainer >
void sample::file_put_contents (const char *filename, CharContainer const &v, const char *access)
 save a buffer into a file More...
 
void sample::file_put_contents (const char *filename, const char *buf, size_t sz, const char *access)
 save a buffer into a file More...
 
int sample::report_checks ()
 
 sample::C4_IF_EXCEPTIONS_ (, static std::jmp_buf s_jmp_env;static std::string s_jmp_msg;) template< class Fn > bool ErrorHandlerExample
 this C-style callback is the one stored and used by ryml. More...
 
void sample::ErrorHandlerExample::on_error (const char *msg, size_t len, ryml::Location loc)
 this is the where the callback implementation goes. More...
 

Detailed Description

Functions and classes used in the examples of this sample.

Macro Definition Documentation

◆ CHECK

#define CHECK (   predicate)    assert(predicate)

Definition at line 234 of file quickstart.cpp.

Function Documentation

◆ report_check()

bool sample::report_check ( int  line,
const char *  predicate,
bool  result 
)

Definition at line 5365 of file quickstart.cpp.

5420  : "));

◆ file_get_contents() [1/2]

template<class CharContainer >
CharContainer sample::file_get_contents ( const char *  filename)

load a file from disk and return a newly created CharContainer

Definition at line 5493 of file quickstart.cpp.

5494 {
5495 #if RYML_USE_ASSERT
5496  return check_error_occurs(fn);
5497 #else
5498  (void)fn; // do nothing otherwise, as there would be undefined behavior

References sample::ErrorHandlerExample::check_error_occurs().

◆ file_get_contents() [2/2]

template<class CharContainer >
size_t sample::file_get_contents ( const char *  filename,
CharContainer *  v 
)

load a file from disk into an existing CharContainer

Definition at line 5474 of file quickstart.cpp.

5480 {
5481  bool expected_error_occurred = false;
5482  C4_IF_EXCEPTIONS_(try, if(setjmp(s_jmp_env) == 0)) // selectively picks based on availability of exceptions
5483  {
5484  fn();
5485  }
5486  C4_IF_EXCEPTIONS_(catch(...), else)
5487  {
5488  expected_error_occurred = true;
5489  }
C4_IF_EXCEPTIONS_(, static std::jmp_buf s_jmp_env;static std::string s_jmp_msg;) template< class Fn > bool ErrorHandlerExample
this C-style callback is the one stored and used by ryml.

References sample::C4_IF_EXCEPTIONS_().

◆ file_put_contents() [1/2]

template<class CharContainer >
void sample::file_put_contents ( const char *  filename,
CharContainer const &  v,
const char *  access = "wb" 
)

save a buffer into a file

Definition at line 5502 of file quickstart.cpp.

5506 {

Referenced by sample::sample_parse_file().

◆ file_put_contents() [2/2]

void sample::file_put_contents ( const char *  filename,
const char *  buf,
size_t  sz,
const char *  access 
)

save a buffer into a file

Definition at line 5508 of file quickstart.cpp.

5511 {
5512  std::string full_msg = ryml::formatrs<std::string>(
5513  "{}:{}:{} ({}B): ERROR: {}",
5514  loc.name, loc.line, loc.col, loc.offset, ryml::csubstr(msg, len));

◆ report_checks()

int sample::report_checks ( )

Definition at line 5379 of file quickstart.cpp.

5420  : "));

◆ C4_IF_EXCEPTIONS_()

sample::C4_IF_EXCEPTIONS_ ( static std::jmp_buf s_jmp_env;static std::string s_jmp_msg;  )

this C-style callback is the one stored and used by ryml.

It is a trampoline function calling on_error()

Definition at line 5392 of file quickstart.cpp.

5420  : "));
5421  CHECK(loc.line == 13u);
5422  CHECK(loc.col == 4u);
5423  loc = tree2["seq with key"][3][0].location(parser);
5424  CHECK(parser.location_contents(loc).begins_with("nested first: "));
5425  CHECK(loc.line == 13u);
5426  CHECK(loc.col == 4u);
5427 }
5428 
5429 
Key< K > key(K &k)
Definition: node.hpp:43

Referenced by sample::file_get_contents().

◆ on_error()

void sample::ErrorHandlerExample::on_error ( const char *  msg,
size_t  len,
ryml::Location  loc 
)

this is the where the callback implementation goes.

Remember that it must not return.

Definition at line 5431 of file quickstart.cpp.

5438  {
5439 static int num_checks = 0;
5440 static int num_failed_checks = 0;
5441 } // namespace /*anon*/
5442 
5443 
5444 bool report_check(int line, const char *predicate, bool result)
5445 {
bool report_check(int line, const char *predicate, bool result)