79 lines
2.5 KiB
C++
79 lines
2.5 KiB
C++
#include "guid.h"
|
|
#include "yaml/yaml.h"
|
|
#include <iostream>
|
|
#include <cassert>
|
|
using namespace refl;
|
|
using namespace std;
|
|
void testGuid() {
|
|
Guid guid = Guid::Make();
|
|
YAML::TextArchive::Register<Guid>();
|
|
string text = YAML::Text_Serialize(guid);
|
|
auto res = YAML::Text_Unserialize<Guid>(text);
|
|
Guid guid2 = res.value();
|
|
assert(guid == guid2);
|
|
std::cout << guid << std::endl;
|
|
}
|
|
void testMeta() {
|
|
MetaBundle mb1;
|
|
mb1.metadatas.push_back({ Guid::Make() , "hello1" });
|
|
mb1.metadatas.push_back({ Guid::Make() , "hello2" });
|
|
mb1.metadatas.push_back({ Guid::Make() , "hello3" });
|
|
mb1.metadatas.push_back({ Guid::Make() , "hello4" });
|
|
string rmb1 = YAML::Text_Serialize(mb1);
|
|
std::cout << rmb1 << std::endl;
|
|
auto rmb2 = YAML::Text_Unserialize<MetaBundle>(rmb1);
|
|
if (rmb2) {
|
|
MetaBundle aa = rmb2.value();
|
|
std::cout << "success!" << std::endl;
|
|
}
|
|
}
|
|
void testTuple() {
|
|
std::map<int, string> table;
|
|
table.insert(std::make_pair(111,"hello"));
|
|
table.insert(std::make_pair(222, "world"));
|
|
using T = std::map<int, string>;
|
|
using to_iterator_func = T::iterator(T::*)();
|
|
struct myiterator {
|
|
void* ptr;
|
|
};
|
|
using to_iterator_impl1 = myiterator*(*)(void *);
|
|
using to_iterator_impl2 = myiterator(*)(void*);
|
|
using to_iterator_impl3 = void*(*)(void*);
|
|
using to_iterator_impl4 = T::iterator(*)(T*);
|
|
auto it = table.begin();
|
|
auto t = &*it;
|
|
to_iterator_func func = &T::begin;
|
|
to_iterator_impl1 impl1 = *(to_iterator_impl1*) & func;
|
|
to_iterator_impl2 impl2 = *(to_iterator_impl2*)&func;
|
|
to_iterator_impl3 impl3 = *(to_iterator_impl3*)&func;
|
|
to_iterator_impl4 impl4 = *(to_iterator_impl4*)&func;
|
|
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();
|
|
std::cout << "success!" << std::endl;
|
|
}
|
|
}
|
|
using size_impl = size_t(*)(const void*);
|
|
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;
|
|
std::vector<int> vi;
|
|
using T = std::vector<int>;
|
|
using iterator = T::iterator;
|
|
struct myiterator {
|
|
void* ptr;
|
|
};
|
|
using to_iterator_impl_func = myiterator*(*)(const void*);
|
|
using to_iterator_func = void(T::*)(T::value_type&&);
|
|
to_iterator_func to_iterator = &T::push_back;
|
|
to_iterator_impl_func to_iterator_impl = * (to_iterator_impl_func*) &to_iterator;
|
|
iterator it = vi.begin();
|
|
void* pptr = it._Ptr;
|
|
//testGuid();
|
|
//testMeta();
|
|
testTuple();
|
|
return 0;
|
|
} |