| | |
| | | #pragma once |
| | | #include "BaseDataFilter.h" |
| | | #include "Engine/DataTable.h" |
| | | |
| | | template <typename T> |
| | | class BaseReader |
| | | { |
| | | public: |
| | | virtual ~BaseReader() = default; |
| | | void AddElementDynamic_Impl(const FName id,const T& t); |
| | | void Init_Impl(const TMap<FName,T>& mapping); |
| | | int32 Num_Impl() const; |
| | | TArray<T> GetArray_Impl() const; |
| | | TMap<FName,T> GetMapping_Impl() const; |
| | | bool Check_Impl(FName id); |
| | | bool Get_Impl(FName id,T& element) const; |
| | | bool GetFromIndex_Impl(const int32& index,T& element)const; |
| | | TArray<T> Filter_Impl(BaseDataFilter<T>* filter) const; |
| | | TArray<T> FilterCPP_Impl(const TFunction<bool(const T& t)>& action) const; |
| | | void ForeachCPP_Impl(const TFunction<bool(const FName& id,const T& t)>& action) const; |
| | | virtual ~BaseReader() = default; |
| | | |
| | | virtual void AddElementDynamic_Impl(const FName id,const T& t); |
| | | virtual void Init_Impl(const TMap<FName,T>& mapping); |
| | | virtual void Init_Impl(const UDataTable* table); |
| | | virtual int32 Num_Impl() const; |
| | | virtual TArray<T> GetArray_Impl() const; |
| | | virtual TMap<FName,T> GetMapping_Impl() const; |
| | | virtual bool Check_Impl(FName id); |
| | | virtual bool Get_Impl(FName id,T& element) const; |
| | | virtual bool GetFromIndex_Impl(const int32& index,T& element)const; |
| | | virtual TArray<T> Filter_Impl(BaseDataFilter<T>* filter) const; |
| | | virtual TArray<T> FilterCPP_Impl(const TFunction<bool(const T& t)>& action) const; |
| | | virtual void ForeachCPP_Impl(const TFunction<bool(const FName& id,const T& t)>& action) const; |
| | | virtual bool IsValidIndex_Impl(int32 index); |
| | | virtual bool IsValidID_Impl(FName id); |
| | | |
| | | TMap<FName,T> Mapping; |
| | | TArray<T> Array; |
| | | }; |
| | |
| | | Mapping = mapping; |
| | | Array.Empty(); |
| | | Mapping.GenerateValueArray(Array); |
| | | } |
| | | |
| | | template <typename T> |
| | | void BaseReader<T>::Init_Impl(const UDataTable* table) |
| | | { |
| | | Mapping.Empty(); |
| | | Array.Empty(); |
| | | for (const auto row : table->GetRowMap()) |
| | | { |
| | | auto element = (T*)row.Value; |
| | | Mapping.Add(row.Key,*element); |
| | | Array.Add(*element); |
| | | } |
| | | } |
| | | |
| | | template <typename T> |
| | |
| | | } |
| | | } |
| | | |
| | | template <typename T> |
| | | bool BaseReader<T>::IsValidIndex_Impl(int32 index) |
| | | { |
| | | return Array.IsValidIndex(index); |
| | | } |
| | | |
| | | template <typename T> |
| | | bool BaseReader<T>::IsValidID_Impl(FName id) |
| | | { |
| | | return Mapping.Contains(id); |
| | | } |
| | | |