rebuild zlib {array & vector}
This commit is contained in:
parent
9289182a1b
commit
7ee697a1e2
@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "UTemplate/Type.hpp"
|
#include "UTemplate/Type.hpp"
|
||||||
#include "../std/sarray.h"
|
#include "zstd/sarray.h"
|
||||||
#include "any.h"
|
#include "any.h"
|
||||||
#include <variant>
|
#include <variant>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
@ -10,6 +10,9 @@ consteval Name FName(const char* buf) {
|
|||||||
return Name(buf);
|
return Name(buf);
|
||||||
}
|
}
|
||||||
namespace refl {
|
namespace refl {
|
||||||
|
using zstd::sarray;
|
||||||
|
using zstd::svector;
|
||||||
|
|
||||||
using Offset = uint32_t;
|
using Offset = uint32_t;
|
||||||
using Method = void*;
|
using Method = void*;
|
||||||
struct MemberData {
|
struct MemberData {
|
||||||
|
|||||||
10
engine/3rdparty/zlib/include/refl/detail/type.h
vendored
10
engine/3rdparty/zlib/include/refl/detail/type.h
vendored
@ -11,16 +11,6 @@ namespace refl {
|
|||||||
template <class T>
|
template <class T>
|
||||||
concept _ReflCheck_Ctor_NoUClass = _ReflCheck_Ctor<T> && !_ReflCheck_UClass<T>;
|
concept _ReflCheck_Ctor_NoUClass = _ReflCheck_Ctor<T> && !_ReflCheck_UClass<T>;
|
||||||
|
|
||||||
// 检查类型是否具有特定的静态成员函数
|
|
||||||
template<typename T, typename = void>
|
|
||||||
struct has_init_object : std::false_type {};
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
struct has_init_object<T, std::void_t<decltype(&T::__InitObject)>> : std::true_type {};
|
|
||||||
|
|
||||||
//template<typename T>error::"expected unqualified-id"
|
|
||||||
//using has_init_object_v = has_init_object<T>::value;
|
|
||||||
|
|
||||||
//类型接口
|
//类型接口
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct TypeInfoImpl;
|
struct TypeInfoImpl;
|
||||||
|
|||||||
@ -18,7 +18,8 @@ namespace refl {
|
|||||||
sarray<const UClass*>(*GetParams)(const UClass*);
|
sarray<const UClass*>(*GetParams)(const UClass*);
|
||||||
//function
|
//function
|
||||||
void (*Call)(const FieldPtr*, const sarray<Any>& ArgsList);
|
void (*Call)(const FieldPtr*, const sarray<Any>& ArgsList);
|
||||||
|
//meta
|
||||||
|
const UClass* (*GetMeta)(const Name&);
|
||||||
//object
|
//object
|
||||||
void (*InitObject)(void*);
|
void (*InitObject)(void*);
|
||||||
void (*CopyObject)(void*, const void*);
|
void (*CopyObject)(void*, const void*);
|
||||||
|
|||||||
@ -129,12 +129,15 @@ namespace refl {
|
|||||||
if constexpr (!std::is_same_v<P, void>) {
|
if constexpr (!std::is_same_v<P, void>) {
|
||||||
parent = &TypeInfo<P>::StaticClass;
|
parent = &TypeInfo<P>::StaticClass;
|
||||||
}
|
}
|
||||||
if constexpr (has_init_object<T>::value) {
|
if constexpr (requires(void* ptr) {T::__InitObject(ptr);}) {
|
||||||
vtable.InitObject = &T::__InitObject;
|
vtable.InitObject = &T::__InitObject;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
vtable.InitObject = &UClass::InitObject<T>;
|
vtable.InitObject = &UClass::InitObject<T>;
|
||||||
}
|
}
|
||||||
|
if constexpr (requires(const Name & name) { T::__GetMeta(name); }) {
|
||||||
|
vtable.GetMeta = &T::__GetMeta;
|
||||||
|
}
|
||||||
vtable.GetField = &UClass_Meta::GetField;
|
vtable.GetField = &UClass_Meta::GetField;
|
||||||
}
|
}
|
||||||
const FieldPtr* GetField(int index) const {
|
const FieldPtr* GetField(int index) const {
|
||||||
|
|||||||
1
engine/3rdparty/zlib/include/refl/refl.h
vendored
1
engine/3rdparty/zlib/include/refl/refl.h
vendored
@ -4,7 +4,6 @@
|
|||||||
#include "detail/field.inl"
|
#include "detail/field.inl"
|
||||||
#include "detail/convert.inl"
|
#include "detail/convert.inl"
|
||||||
#include "detail/meta.inl"
|
#include "detail/meta.inl"
|
||||||
#include "std/sarray.h"
|
|
||||||
#include "macro.h"
|
#include "macro.h"
|
||||||
namespace refl {
|
namespace refl {
|
||||||
template<typename T, typename Obj>
|
template<typename T, typename Obj>
|
||||||
|
|||||||
69
engine/3rdparty/zlib/include/refl/std/parray.h
vendored
Normal file
69
engine/3rdparty/zlib/include/refl/std/parray.h
vendored
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
#include "refl/refl.h"
|
||||||
|
namespace refl {
|
||||||
|
template<typename T>
|
||||||
|
void malloc_list(T*& ptr, int count) {
|
||||||
|
ptr = (T*)malloc(count * sizeof(T));
|
||||||
|
for (size_t i = 0; i < count; i++)
|
||||||
|
{
|
||||||
|
std::construct_at(ptr + i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
template<typename T>
|
||||||
|
class parray {
|
||||||
|
protected:
|
||||||
|
const UClass* m_cls;
|
||||||
|
T* m_ptr;
|
||||||
|
int m_count;
|
||||||
|
public:
|
||||||
|
template<typename C>
|
||||||
|
requires std::is_base_of_v<T, C>
|
||||||
|
parray(std::vector<C>& vec) : m_cls(&TypeInfo<C>::StaticClass){
|
||||||
|
m_count = vec.size();
|
||||||
|
if (m_count > 0) {
|
||||||
|
malloc_list(m_ptr, m_count);
|
||||||
|
std::move(vec.begin(), vec.end(), m_ptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
parray(parray<T>& parr) : m_cls(parr.m_cls)
|
||||||
|
, m_ptr(parr.data()), m_count(parr.size()) {
|
||||||
|
parr.reset();
|
||||||
|
}
|
||||||
|
~parray() {
|
||||||
|
if (!m_count || !m_cls)
|
||||||
|
return;
|
||||||
|
auto dest = m_cls->vtable.DestObject;
|
||||||
|
if (dest) {
|
||||||
|
for (int i = 0; i < m_count; i++) {
|
||||||
|
dest((char*)m_ptr + (i * m_cls->size));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_count = 0;
|
||||||
|
m_ptr = nullptr;
|
||||||
|
}
|
||||||
|
T* at(int i)noexcept {
|
||||||
|
if(i < m_count)
|
||||||
|
return (T*)((char*)m_ptr + (i * m_cls->size));
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
T* data() noexcept{
|
||||||
|
return m_ptr;
|
||||||
|
}
|
||||||
|
void reset() noexcept {
|
||||||
|
m_ptr = nullptr;
|
||||||
|
m_count = 0;
|
||||||
|
}
|
||||||
|
int size() const noexcept {
|
||||||
|
return m_count;
|
||||||
|
}
|
||||||
|
int capicty() const noexcept {
|
||||||
|
return m_count * m_cls->size;
|
||||||
|
}
|
||||||
|
const UClass* uclass()const noexcept {
|
||||||
|
return m_cls;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
template<typename T, typename C>
|
||||||
|
parray<T> ToParray(std::vector<C>& vec){
|
||||||
|
return parray<T>{vec};
|
||||||
|
}
|
||||||
|
}
|
||||||
72
engine/3rdparty/zlib/include/refl/std/sarray.h
vendored
72
engine/3rdparty/zlib/include/refl/std/sarray.h
vendored
@ -1,72 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include "svector.h"
|
|
||||||
#include <concepts>
|
|
||||||
template<typename T>
|
|
||||||
class sarray {
|
|
||||||
protected:
|
|
||||||
const T* m_ptr;
|
|
||||||
int m_count;
|
|
||||||
public:
|
|
||||||
constexpr sarray(const T* ptr, int count) : m_ptr(ptr), m_count(count) {}
|
|
||||||
constexpr sarray(const svector<T>& vec) : m_ptr(vec.front()), m_count(vec.size()) {}
|
|
||||||
constexpr sarray() :m_ptr(nullptr), m_count(0) {}
|
|
||||||
constexpr sarray(std::initializer_list<T> list) : m_ptr(list.begin()), m_count(list.size()) {}
|
|
||||||
constexpr const T* front() const noexcept {
|
|
||||||
return m_ptr;
|
|
||||||
}
|
|
||||||
constexpr const T* back()const noexcept {
|
|
||||||
return m_ptr + m_count;
|
|
||||||
}
|
|
||||||
constexpr const T* at(int i) const noexcept {
|
|
||||||
if (i < m_count) {
|
|
||||||
return m_ptr + i;
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
constexpr bool IsValid() const noexcept {
|
|
||||||
return m_count > 0;
|
|
||||||
}
|
|
||||||
constexpr bool empty() const noexcept {
|
|
||||||
return m_count == 0;
|
|
||||||
}
|
|
||||||
constexpr int size() const noexcept {
|
|
||||||
return m_count;
|
|
||||||
}
|
|
||||||
constexpr auto begin()const noexcept {
|
|
||||||
return iterator{ m_ptr };
|
|
||||||
}
|
|
||||||
constexpr auto end() const noexcept {
|
|
||||||
return iterator{ m_ptr + m_count};
|
|
||||||
}
|
|
||||||
// Iterator class
|
|
||||||
class iterator {
|
|
||||||
private:
|
|
||||||
const T* ptr;
|
|
||||||
|
|
||||||
public:
|
|
||||||
constexpr iterator(const T* p) : ptr(p) {}
|
|
||||||
|
|
||||||
// Overload ++ to move to next element
|
|
||||||
constexpr iterator& operator++() noexcept{
|
|
||||||
++ptr;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
//这里其实是--it,而不是it--
|
|
||||||
constexpr iterator& operator--(int) noexcept {
|
|
||||||
--ptr;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
constexpr const T* operator->() const noexcept {
|
|
||||||
return ptr;
|
|
||||||
}
|
|
||||||
// Overload * to dereference iterator
|
|
||||||
constexpr const T& operator*() const noexcept {
|
|
||||||
return *ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Overload != to compare iterators
|
|
||||||
constexpr bool operator!=(const iterator& other) const noexcept {
|
|
||||||
return ptr != other.ptr;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
};
|
|
||||||
71
engine/3rdparty/zlib/include/refl/std/svector.h
vendored
71
engine/3rdparty/zlib/include/refl/std/svector.h
vendored
@ -1,71 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <array>
|
|
||||||
#include <concepts>
|
|
||||||
template<typename T>
|
|
||||||
class svector {
|
|
||||||
protected:
|
|
||||||
T* m_ptr;
|
|
||||||
int m_count;
|
|
||||||
int m_capicty;
|
|
||||||
public:
|
|
||||||
constexpr svector() :m_ptr(nullptr), m_count(0), m_capicty(0){}
|
|
||||||
constexpr svector(T* ptr, int size, int count) : m_ptr(ptr), m_capicty(size), m_count(count){}
|
|
||||||
constexpr T* front()const noexcept {
|
|
||||||
return m_ptr;
|
|
||||||
}
|
|
||||||
constexpr T* back()const noexcept {
|
|
||||||
return m_ptr + m_count;
|
|
||||||
}
|
|
||||||
constexpr void push_back(const T& t) {
|
|
||||||
if (m_count < m_capicty) {
|
|
||||||
*(m_ptr + m_count) = t;
|
|
||||||
m_count++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
constexpr bool IsValid() const noexcept {
|
|
||||||
return m_count > 0;
|
|
||||||
}
|
|
||||||
constexpr bool empty() const noexcept {
|
|
||||||
return m_count == 0;
|
|
||||||
}
|
|
||||||
constexpr int size() const noexcept {
|
|
||||||
return m_count;
|
|
||||||
}
|
|
||||||
constexpr auto begin()const noexcept {
|
|
||||||
return iterator{ m_ptr };
|
|
||||||
}
|
|
||||||
constexpr auto end() const noexcept {
|
|
||||||
return iterator{ m_ptr + m_count };
|
|
||||||
}
|
|
||||||
// Iterator class
|
|
||||||
class iterator {
|
|
||||||
private:
|
|
||||||
const T* ptr;
|
|
||||||
|
|
||||||
public:
|
|
||||||
constexpr iterator(const T* p) : ptr(p) {}
|
|
||||||
|
|
||||||
// Overload ++ to move to next element
|
|
||||||
constexpr iterator& operator++() noexcept {
|
|
||||||
++ptr;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
//这里其实是--it,而不是it--
|
|
||||||
constexpr iterator& operator--(int) noexcept {
|
|
||||||
--ptr;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
constexpr const T* operator->() const noexcept {
|
|
||||||
return ptr;
|
|
||||||
}
|
|
||||||
// Overload * to dereference iterator
|
|
||||||
constexpr const T& operator*() const noexcept {
|
|
||||||
return *ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Overload != to compare iterators
|
|
||||||
constexpr bool operator!=(const iterator& other) const noexcept {
|
|
||||||
return ptr != other.ptr;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
};
|
|
||||||
100
engine/3rdparty/zlib/include/zstd/harray.h
vendored
Normal file
100
engine/3rdparty/zlib/include/zstd/harray.h
vendored
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <concepts>
|
||||||
|
#include <vector>
|
||||||
|
namespace zstd {
|
||||||
|
template<typename T>
|
||||||
|
void malloc_list(T*& ptr, int count) {
|
||||||
|
ptr = (T*)malloc(count * sizeof(T));
|
||||||
|
for (size_t i = 0; i < count; i++)
|
||||||
|
{
|
||||||
|
std::construct_at(ptr + i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
template<typename T>
|
||||||
|
class harray {
|
||||||
|
protected:
|
||||||
|
T* m_ptr{nullptr};
|
||||||
|
int m_count{0};
|
||||||
|
public:
|
||||||
|
constexpr harray() {}
|
||||||
|
harray(const std::vector<T>& vec)noexcept {
|
||||||
|
m_count = vec.size();
|
||||||
|
if (m_count > 0) {
|
||||||
|
malloc_list(m_ptr, m_count);
|
||||||
|
std::move(vec.begin(), vec.end(), m_ptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
~harray() {
|
||||||
|
for (int i = 0; i < m_count; i++) {
|
||||||
|
std::destroy_at(m_ptr + i);
|
||||||
|
}
|
||||||
|
m_ptr = nullptr;
|
||||||
|
m_count = 0;
|
||||||
|
}
|
||||||
|
constexpr void reset() noexcept {
|
||||||
|
m_ptr = nullptr;
|
||||||
|
m_count = 0;
|
||||||
|
}
|
||||||
|
constexpr T* data() noexcept {
|
||||||
|
return m_ptr;
|
||||||
|
}
|
||||||
|
constexpr T* front() noexcept {
|
||||||
|
return m_ptr;
|
||||||
|
}
|
||||||
|
constexpr T* back() noexcept {
|
||||||
|
return m_ptr + m_count;
|
||||||
|
}
|
||||||
|
constexpr T* at(int i) noexcept {
|
||||||
|
if (i < m_count) {
|
||||||
|
return m_ptr + i;
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
constexpr bool IsValid() const noexcept {
|
||||||
|
return m_count > 0;
|
||||||
|
}
|
||||||
|
constexpr bool empty() const noexcept {
|
||||||
|
return m_count == 0;
|
||||||
|
}
|
||||||
|
constexpr int size() const noexcept {
|
||||||
|
return m_count;
|
||||||
|
}
|
||||||
|
constexpr auto begin() noexcept {
|
||||||
|
return iterator{ m_ptr };
|
||||||
|
}
|
||||||
|
constexpr auto end() noexcept {
|
||||||
|
return iterator{ m_ptr + m_count };
|
||||||
|
}
|
||||||
|
// Iterator class
|
||||||
|
class iterator {
|
||||||
|
private:
|
||||||
|
const T* ptr;
|
||||||
|
|
||||||
|
public:
|
||||||
|
constexpr iterator(const T* p) : ptr(p) {}
|
||||||
|
|
||||||
|
// Overload ++ to move to next element
|
||||||
|
constexpr iterator& operator++() noexcept {
|
||||||
|
++ptr;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
//ÕâÀïÆäʵÊÇ--it,¶ø²»ÊÇit--
|
||||||
|
constexpr iterator& operator--(int) noexcept {
|
||||||
|
--ptr;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
constexpr const T* operator->() const noexcept {
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
// Overload * to dereference iterator
|
||||||
|
constexpr const T& operator*() const noexcept {
|
||||||
|
return *ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Overload != to compare iterators
|
||||||
|
constexpr bool operator!=(const iterator& other) const noexcept {
|
||||||
|
return ptr != other.ptr;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
50
engine/3rdparty/zlib/include/zstd/parray.h
vendored
50
engine/3rdparty/zlib/include/zstd/parray.h
vendored
@ -1,50 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <concepts>
|
|
||||||
namespace zstd {
|
|
||||||
template<typename T>
|
|
||||||
class parray {
|
|
||||||
protected:
|
|
||||||
uint32_t m_size;
|
|
||||||
uint32_t m_head{0};
|
|
||||||
uint32_t m_tsize;
|
|
||||||
char* m_buf;
|
|
||||||
public:
|
|
||||||
~parray() {
|
|
||||||
if (m_buf) {
|
|
||||||
free(m_buf);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
parray(uint32_t size = 1, uint32_t tsize = sizeof(T)) : m_buf((char*)malloc(tsize * size)), m_size(size) , m_tsize(tsize){}
|
|
||||||
parray(parray& other) noexcept{
|
|
||||||
m_size = other.m_size;
|
|
||||||
m_head = other.m_head;
|
|
||||||
m_tsize = other.m_tsize;
|
|
||||||
m_buf = other.m_buf;
|
|
||||||
other.m_buf = nullptr;
|
|
||||||
}
|
|
||||||
uint32_t size() {
|
|
||||||
return m_head;
|
|
||||||
}
|
|
||||||
uint32_t data_size() {
|
|
||||||
return m_tsize * m_head;
|
|
||||||
}
|
|
||||||
void* data() {
|
|
||||||
return m_buf;
|
|
||||||
}
|
|
||||||
template<typename S>
|
|
||||||
requires std::is_base_of<T, S>::value
|
|
||||||
void push_back(S& s) {
|
|
||||||
if (m_head >= m_size) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
*(S*)(m_buf + m_head * m_tsize) = s;
|
|
||||||
m_head++;
|
|
||||||
};
|
|
||||||
T* at(int i) {
|
|
||||||
if (i >= m_head) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
return (T*)(m_buf + i * m_tsize);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
74
engine/3rdparty/zlib/include/zstd/sarray.h
vendored
Normal file
74
engine/3rdparty/zlib/include/zstd/sarray.h
vendored
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "svector.h"
|
||||||
|
#include <concepts>
|
||||||
|
namespace zstd {
|
||||||
|
template<typename T>
|
||||||
|
class sarray {
|
||||||
|
protected:
|
||||||
|
const T* m_ptr;
|
||||||
|
int m_count;
|
||||||
|
public:
|
||||||
|
constexpr sarray(const T* ptr, int count) : m_ptr(ptr), m_count(count) {}
|
||||||
|
constexpr sarray(const svector<T>& vec) : m_ptr(vec.front()), m_count(vec.size()) {}
|
||||||
|
constexpr sarray() : m_ptr(nullptr), m_count(0) {}
|
||||||
|
constexpr sarray(std::initializer_list<T> list) : m_ptr(list.begin()), m_count(list.size()) {}
|
||||||
|
constexpr const T* front() const noexcept {
|
||||||
|
return m_ptr;
|
||||||
|
}
|
||||||
|
constexpr const T* back()const noexcept {
|
||||||
|
return m_ptr + m_count;
|
||||||
|
}
|
||||||
|
constexpr const T* at(int i) const noexcept {
|
||||||
|
if (i < m_count) {
|
||||||
|
return m_ptr + i;
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
constexpr bool IsValid() const noexcept {
|
||||||
|
return m_count > 0;
|
||||||
|
}
|
||||||
|
constexpr bool empty() const noexcept {
|
||||||
|
return m_count == 0;
|
||||||
|
}
|
||||||
|
constexpr int size() const noexcept {
|
||||||
|
return m_count;
|
||||||
|
}
|
||||||
|
constexpr auto begin()const noexcept {
|
||||||
|
return iterator{ m_ptr };
|
||||||
|
}
|
||||||
|
constexpr auto end() const noexcept {
|
||||||
|
return iterator{ m_ptr + m_count };
|
||||||
|
}
|
||||||
|
// Iterator class
|
||||||
|
class iterator {
|
||||||
|
private:
|
||||||
|
const T* ptr;
|
||||||
|
|
||||||
|
public:
|
||||||
|
constexpr iterator(const T* p) : ptr(p) {}
|
||||||
|
|
||||||
|
// Overload ++ to move to next element
|
||||||
|
constexpr iterator& operator++() noexcept {
|
||||||
|
++ptr;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
//这里其实是--it,而不是it--
|
||||||
|
constexpr iterator& operator--(int) noexcept {
|
||||||
|
--ptr;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
constexpr const T* operator->() const noexcept {
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
// Overload * to dereference iterator
|
||||||
|
constexpr const T& operator*() const noexcept {
|
||||||
|
return *ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Overload != to compare iterators
|
||||||
|
constexpr bool operator!=(const iterator& other) const noexcept {
|
||||||
|
return ptr != other.ptr;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
75
engine/3rdparty/zlib/include/zstd/svector.h
vendored
Normal file
75
engine/3rdparty/zlib/include/zstd/svector.h
vendored
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <array>
|
||||||
|
#include <concepts>
|
||||||
|
namespace zstd {
|
||||||
|
//栈容器,大小可变,只能从std::array安全构造
|
||||||
|
template<typename T>
|
||||||
|
class svector {
|
||||||
|
protected:
|
||||||
|
T* m_ptr;
|
||||||
|
int m_count;
|
||||||
|
int m_capicty;
|
||||||
|
public:
|
||||||
|
constexpr svector() :m_ptr(nullptr), m_count(0), m_capicty(0) {}
|
||||||
|
template<auto N>
|
||||||
|
constexpr svector(std::array<T, N>& arr, int count) : m_ptr(arr.data()), m_capicty(N), m_count(count) {}
|
||||||
|
constexpr T* front()const noexcept {
|
||||||
|
return m_ptr;
|
||||||
|
}
|
||||||
|
constexpr T* back()const noexcept {
|
||||||
|
return m_ptr + m_count;
|
||||||
|
}
|
||||||
|
constexpr void push_back(const T& t) {
|
||||||
|
if (m_count < m_capicty) {
|
||||||
|
*(m_ptr + m_count) = t;
|
||||||
|
m_count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
constexpr bool IsValid() const noexcept {
|
||||||
|
return m_count > 0;
|
||||||
|
}
|
||||||
|
constexpr bool empty() const noexcept {
|
||||||
|
return m_count == 0;
|
||||||
|
}
|
||||||
|
constexpr int size() const noexcept {
|
||||||
|
return m_count;
|
||||||
|
}
|
||||||
|
constexpr auto begin()const noexcept {
|
||||||
|
return iterator{ m_ptr };
|
||||||
|
}
|
||||||
|
constexpr auto end() const noexcept {
|
||||||
|
return iterator{ m_ptr + m_count };
|
||||||
|
}
|
||||||
|
// Iterator class
|
||||||
|
class iterator {
|
||||||
|
private:
|
||||||
|
const T* ptr;
|
||||||
|
|
||||||
|
public:
|
||||||
|
constexpr iterator(const T* p) : ptr(p) {}
|
||||||
|
|
||||||
|
// Overload ++ to move to next element
|
||||||
|
constexpr iterator& operator++() noexcept {
|
||||||
|
++ptr;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
//这里其实是--it,而不是it--
|
||||||
|
constexpr iterator& operator--(int) noexcept {
|
||||||
|
--ptr;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
constexpr const T* operator->() const noexcept {
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
// Overload * to dereference iterator
|
||||||
|
constexpr const T& operator*() const noexcept {
|
||||||
|
return *ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Overload != to compare iterators
|
||||||
|
constexpr bool operator!=(const iterator& other) const noexcept {
|
||||||
|
return ptr != other.ptr;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
6
engine/3rdparty/zlib/test/refl/vertex.cpp
vendored
Normal file
6
engine/3rdparty/zlib/test/refl/vertex.cpp
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#include "vertex.h"
|
||||||
|
#include "uimeta_vertex_gen.inl"
|
||||||
|
const UClass* vec3::__GetMeta(const Name& name)
|
||||||
|
{
|
||||||
|
return fetch_meta_uclass<vec3>(name);
|
||||||
|
}
|
||||||
11
engine/3rdparty/zlib/test/refl/vertex.h
vendored
11
engine/3rdparty/zlib/test/refl/vertex.h
vendored
@ -12,10 +12,14 @@ struct vec3_parent {
|
|||||||
struct vec4 {
|
struct vec4 {
|
||||||
string name{ "hello" };
|
string name{ "hello" };
|
||||||
};
|
};
|
||||||
class vec3_Meta;
|
template<typename T>
|
||||||
|
const UClass* fetch_meta_uclass(const Name& name) {
|
||||||
|
return &TypeInfo<typename T::MyUIMeta>::StaticClass;
|
||||||
|
};
|
||||||
struct vec3 : public vec3_parent {
|
struct vec3 : public vec3_parent {
|
||||||
using MyMeta = vec3_Meta;
|
using MyMeta = class vec3_Meta;
|
||||||
__cppast(Meta = { 1.f})
|
using MyUIMeta = class vec3_UIMeta;
|
||||||
|
__cppast(UIMeta = { 1.f})
|
||||||
float x = 1;
|
float x = 1;
|
||||||
__cppast(Meta = { 2.f})
|
__cppast(Meta = { 2.f})
|
||||||
float y = 2;
|
float y = 2;
|
||||||
@ -49,5 +53,6 @@ struct vec3 : public vec3_parent {
|
|||||||
x1 = x1 * 10;
|
x1 = x1 * 10;
|
||||||
cout << x1 << "::norm3" << endl;
|
cout << x1 << "::norm3" << endl;
|
||||||
}
|
}
|
||||||
|
static const UClass* __GetMeta(const Name& name);
|
||||||
};
|
};
|
||||||
#include "meta_vertex_gen.inl"
|
#include "meta_vertex_gen.inl"
|
||||||
7
engine/3rdparty/zlib/test/refl_01.cpp
vendored
7
engine/3rdparty/zlib/test/refl_01.cpp
vendored
@ -2,12 +2,9 @@
|
|||||||
#include <benchmark/benchmark.h>
|
#include <benchmark/benchmark.h>
|
||||||
auto cls = &TypeInfo<vec3>::StaticClass;
|
auto cls = &TypeInfo<vec3>::StaticClass;
|
||||||
vec3 v;
|
vec3 v;
|
||||||
constexpr int smeta = sizeof(vec3_Meta);
|
|
||||||
constexpr int scls = sizeof(decltype(*cls));
|
|
||||||
auto ov = cls->New((void*)&v);
|
auto ov = cls->New((void*)&v);
|
||||||
void TestRefl1(benchmark::State& state) {
|
void TestRefl1(benchmark::State& state) {
|
||||||
int x = 1, y = 2;
|
int x = 1, y = 2;
|
||||||
auto rx = &vec3_Meta::s_data[0];
|
|
||||||
auto f = cls->GetField(GetStaticFieldID<vec3_Meta>(FName("name")));
|
auto f = cls->GetField(GetStaticFieldID<vec3_Meta>(FName("name")));
|
||||||
string hello;
|
string hello;
|
||||||
ov.Get(FName("name"), hello);
|
ov.Get(FName("name"), hello);
|
||||||
@ -16,7 +13,7 @@ void TestRefl1(benchmark::State& state) {
|
|||||||
constexpr auto r = StaticMemberField(&vec3::name, FName("name"), { ("hello meta")});
|
constexpr auto r = StaticMemberField(&vec3::name, FName("name"), { ("hello meta")});
|
||||||
for (auto _ : state) {
|
for (auto _ : state) {
|
||||||
std::array<Any, 4> arr{&x, ov.ptr};
|
std::array<Any, 4> arr{&x, ov.ptr};
|
||||||
svector<Any> svec(&arr.front(), arr.size(), 2);
|
svector<Any> svec(arr, 2);
|
||||||
ov.Invoke(FName("norm"), svec);
|
ov.Invoke(FName("norm"), svec);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -27,7 +24,7 @@ void TestRefl2(benchmark::State& state) {
|
|||||||
auto field = cls->GetField(id);
|
auto field = cls->GetField(id);
|
||||||
for (auto _ : state) {
|
for (auto _ : state) {
|
||||||
std::array<Any, 4> arr{&x, ov.ptr};
|
std::array<Any, 4> arr{&x, ov.ptr};
|
||||||
svector<Any> svec(&arr.front(), arr.size(), 2);
|
svector<Any> svec(arr, 2);
|
||||||
field->Invoke(svec);
|
field->Invoke(svec);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
3
engine/3rdparty/zlib/xmake.lua
vendored
3
engine/3rdparty/zlib/xmake.lua
vendored
@ -4,7 +4,6 @@ target("zlib")
|
|||||||
set_kind("static")
|
set_kind("static")
|
||||||
add_packages("UTemplate", {public = true})
|
add_packages("UTemplate", {public = true})
|
||||||
add_includedirs("include", {public = true})
|
add_includedirs("include", {public = true})
|
||||||
add_files("src/**/*.cpp")
|
|
||||||
add_headerfiles("include/**/*.h", "include/**/*.inl")
|
add_headerfiles("include/**/*.h", "include/**/*.inl")
|
||||||
target("zlib_test")
|
target("zlib_test")
|
||||||
set_kind("binary")
|
set_kind("binary")
|
||||||
@ -38,5 +37,5 @@ target("refl_zlib")
|
|||||||
add_deps("zlib")
|
add_deps("zlib")
|
||||||
add_packages("benchmark")
|
add_packages("benchmark")
|
||||||
add_includedirs("test/refl")
|
add_includedirs("test/refl")
|
||||||
add_files("test/refl_01.cpp")
|
add_files("test/refl_01.cpp","test/refl/*.cpp")
|
||||||
add_headerfiles("test/refl/*.h")
|
add_headerfiles("test/refl/*.h")
|
||||||
Loading…
Reference in New Issue
Block a user