zengine-old/engine/3rdparty/zlib/test/yaml/main.cpp

54 lines
1.6 KiB
C++
Raw Normal View History

2024-06-14 22:25:34 +08:00
#include "guid.h"
#include "yaml/yaml.h"
#include <iostream>
#include <cassert>
using namespace refl;
using namespace std;
2024-06-22 10:02:48 +08:00
void testGuid() {
Guid guid = Guid::Make();
2024-06-16 22:52:45 +08:00
YAML::TextArchive::Register<Guid>();
2024-06-22 10:02:48 +08:00
string text = YAML::Text_Serialize(guid);
auto res = YAML::Text_Unserialize<Guid>(text);
Guid guid2 = res.value();
assert(guid == guid2);
2024-07-10 22:18:04 +08:00
std::cout << string(guid) << std::endl;
std::cout << string(guid2) << std::endl;
std::cout << string(guid) << std::endl;
2024-06-22 10:02:48 +08:00
}
void testMeta() {
2024-07-10 22:18:04 +08:00
REGISTER_META_TABLE(Guid);
2024-06-22 10:02:48 +08:00
MetaBundle mb1;
2024-07-10 22:18:04 +08:00
Guid guid = Guid::Make();
mb1.metadatas.push_back({ Guid::Make() , "hello1" , "guid", guid});
2024-06-22 10:02:48 +08:00
string rmb1 = YAML::Text_Serialize(mb1);
2024-06-24 00:26:52 +08:00
std::cout << rmb1 << std::endl;
2024-06-22 10:02:48 +08:00
auto rmb2 = YAML::Text_Unserialize<MetaBundle>(rmb1);
if (rmb2) {
MetaBundle aa = rmb2.value();
2024-06-25 22:05:19 +08:00
std::cout << "success!\n" << YAML::Text_Serialize(aa) << std::endl;
2024-06-14 22:25:34 +08:00
}
2024-06-22 10:02:48 +08:00
}
2024-06-24 00:26:52 +08:00
void testTuple() {
std::map<int, string> table;
2024-06-25 22:05:19 +08:00
table.insert(std::make_pair(111,"hello\nworld!!"));
table.insert(std::make_pair(222, "yaml\n????"));
table.insert(std::make_pair(333, YAML::Text_Serialize(table)));
2024-06-24 00:26:52 +08:00
using T = std::map<int, string>;
string rtable = YAML::Text_Serialize(table);
std::cout << rtable << std::endl;
auto table2 = YAML::Text_Unserialize<std::map<int, string>>(rtable);
if (table2) {
std::map<int, string> aa = table2.value();
2024-06-25 22:05:19 +08:00
std::cout << "success!\n" << YAML::Text_Serialize(aa) << std::endl;
2024-06-24 00:26:52 +08:00
}
}
using size_impl = size_t(*)(const void*);
2024-06-22 10:02:48 +08:00
int main() {
constexpr bool m1 = refl::is_map_v<std::vector<int>>;
constexpr bool m2 = refl::is_sequence_v<std::map<int, float>>;
auto cls = &TypeInfo<Guid>::StaticClass;
2024-06-24 22:26:09 +08:00
testGuid();
testMeta();
2024-06-24 00:26:52 +08:00
testTuple();
2024-06-14 22:25:34 +08:00
return 0;
}