Add main function for testing BinaryTable functionality
This commit is contained in:
@@ -415,3 +415,63 @@ inline std::vector<BT_FreeListEntry> decodeFreeList(const std::vector<uint8_t>&
|
|||||||
}
|
}
|
||||||
return freeList;
|
return freeList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --- Main function for testing ---
|
||||||
|
#ifdef BINARY_TABLE_MAIN
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
const std::string filename = "example.bin";
|
||||||
|
// Remove file if it exists
|
||||||
|
std::remove(filename.c_str());
|
||||||
|
// Create file
|
||||||
|
std::ofstream(filename).close();
|
||||||
|
BinaryTable table(filename);
|
||||||
|
// No explicit initialise needed, but could be added if desired
|
||||||
|
|
||||||
|
std::cout << "File dump:" << std::endl;
|
||||||
|
{
|
||||||
|
std::ifstream f(filename, std::ios::binary);
|
||||||
|
std::vector<uint8_t> data((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());
|
||||||
|
std::cout << binaryDump(data) << std::endl;
|
||||||
|
std::cout << "File size: " << data.size() << " bytes\n" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Insert arrays
|
||||||
|
table.set("int_array", std::vector<int>{6, 3, 9, 2, 5});
|
||||||
|
table.set("float_array", std::vector<double>{1.5, 2.5, 3.5});
|
||||||
|
table.set("empty", std::vector<int>{});
|
||||||
|
|
||||||
|
// Modify arrays
|
||||||
|
BT_UniformArray intArr = std::get<BT_UniformArray>(table.get("int_array"));
|
||||||
|
BT_UniformArray floatArr = std::get<BT_UniformArray>(table.get("float_array"));
|
||||||
|
intArr.set(0, 1);
|
||||||
|
floatArr.set(1, 4.5);
|
||||||
|
|
||||||
|
std::cout << "int_array pointer: " << intArr._pointer.to_string() << std::endl;
|
||||||
|
std::cout << "float_array pointer: " << floatArr._pointer.to_string() << std::endl;
|
||||||
|
|
||||||
|
intArr.add(10);
|
||||||
|
floatArr.add(5.5);
|
||||||
|
intArr.addAll({420, 69, 1337, 1738});
|
||||||
|
floatArr.addAll({6.5, 7.5, 8.5});
|
||||||
|
|
||||||
|
auto readback1 = intArr.to_string(true);
|
||||||
|
auto readback2 = floatArr.to_string(true);
|
||||||
|
BT_UniformArray emptyArr = std::get<BT_UniformArray>(table.get("empty"));
|
||||||
|
auto readback3 = emptyArr.to_string(true);
|
||||||
|
std::cout << "Readback1: " << readback1 << std::endl;
|
||||||
|
std::cout << "Readback2: " << readback2 << std::endl;
|
||||||
|
std::cout << "Readback3: " << readback3 << std::endl;
|
||||||
|
|
||||||
|
std::cout << "\nFile dump:" << std::endl;
|
||||||
|
{
|
||||||
|
std::ifstream f(filename, std::ios::binary);
|
||||||
|
std::vector<uint8_t> data((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());
|
||||||
|
std::cout << binaryDump(data) << std::endl;
|
||||||
|
std::cout << "File size: " << data.size() << " bytes" << std::endl;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user