aboutsummaryrefslogtreecommitdiff
path: root/thirdparty/ryml/test/callbacks_tester.hpp
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2026-02-23 11:19:52 +0100
committerGitHub Enterprise <[email protected]>2026-02-23 11:19:52 +0100
commit9aac0fd369b87e965fb34b5168646387de7ea1cd (patch)
tree367a820685a829adbab31cd1374b1af2cece4b7e /thirdparty/ryml/test/callbacks_tester.hpp
parentchanged command names and descriptions to use class members instead of string... (diff)
downloadzen-9aac0fd369b87e965fb34b5168646387de7ea1cd.tar.xz
zen-9aac0fd369b87e965fb34b5168646387de7ea1cd.zip
implement yaml generation (#774)
this implements a yaml generation strategy similar to the JSON generation where we just build a string instead of building a ryml tree. This also removes the dependency on ryml for reduced binary/build times.
Diffstat (limited to 'thirdparty/ryml/test/callbacks_tester.hpp')
-rw-r--r--thirdparty/ryml/test/callbacks_tester.hpp77
1 files changed, 0 insertions, 77 deletions
diff --git a/thirdparty/ryml/test/callbacks_tester.hpp b/thirdparty/ryml/test/callbacks_tester.hpp
deleted file mode 100644
index 5286e0c34..000000000
--- a/thirdparty/ryml/test/callbacks_tester.hpp
+++ /dev/null
@@ -1,77 +0,0 @@
-#ifndef C4_TEST_CALLBACKS_TESTER_HPP_
-#define C4_TEST_CALLBACKS_TESTER_HPP_
-
-#ifndef RYML_SINGLE_HEADER
-#include "c4/yml/common.hpp"
-#endif
-#include <vector>
-#include <iostream>
-
-namespace c4 {
-namespace yml {
-
-struct CallbacksTester
-{
- std::vector<char> memory_pool;
- const char *id;
- size_t num_allocs, alloc_size;
- size_t num_deallocs, dealloc_size;
-
- CallbacksTester(const char *id_="notset", size_t sz=10u * 1024u) // 10KB
- : memory_pool(sz)
- , id(id_)
- , num_allocs()
- , alloc_size()
- , num_deallocs()
- , dealloc_size()
- {
- }
-
- // checking
- ~CallbacksTester()
- {
- check();
- }
-
- void check()
- {
- std::cout << "size: alloc=" << alloc_size << " dealloc=" << dealloc_size << std::endl;
- std::cout << "count: #allocs=" << num_allocs << " #deallocs=" << num_deallocs << std::endl;
- RYML_CHECK(num_allocs == num_deallocs);
- RYML_CHECK(alloc_size == dealloc_size);
- }
-
- Callbacks callbacks() const
- {
- Callbacks cb = get_callbacks();
- cb.m_user_data = (void*) this;
- cb.m_allocate = [](size_t len, void *, void *data){ return ((CallbacksTester*) data)->allocate(len); };
- cb.m_free = [](void *mem, size_t len, void *data){ return ((CallbacksTester*) data)->free(mem, len); };
- return cb;
- }
-
- void *allocate(size_t len)
- {
- std::cout << "alloc[" << num_allocs << "]=" << len << "B\n";
- void *ptr = &memory_pool[alloc_size];
- alloc_size += len;
- ++num_allocs;
- RYML_CHECK(alloc_size < memory_pool.size());
- return ptr;
- }
-
- void free(void *mem, size_t len)
- {
- RYML_CHECK((char*)mem >= &memory_pool.front() && (char*)mem < &memory_pool.back());
- RYML_CHECK((char*)mem+len >= &memory_pool.front() && (char*)mem+len <= &memory_pool.back());
- std::cout << "free[" << num_deallocs << "]=" << len << "B\n";
- dealloc_size += len;
- ++num_deallocs;
- // no need to free here
- }
-};
-
-} // namespace yml
-} // namespace c4
-
-#endif /* C4_TEST_CALLBACKS_TESTER_HPP_ */