OROCHI
 
Loading...
Searching...
No Matches
GxArray.h
Go to the documentation of this file.
1//===========================================================================
9//===========================================================================
10#pragma once
11
12GX_CORE_NAMESPACE_BEGIN()
13
14//===========================================================================
16//===========================================================================
17class GxArray : public GxClassBase
18{
19 //-----------------------------------------------------------
21 //-----------------------------------------------------------
23public:
24 GX_RTTI_CLASS(GxArray, GxClassBase)
25 // GxClassBase継承クラス用禁止宣言
27
28
29 static constexpr u32 ALLOC_COUNT_FIRST = 8;
30 using __type = void*;
31
33 template<class T>
34 struct Iterator
35 {
36 //-----------------------------------------------------------
38 //-----------------------------------------------------------
40
42 constexpr T& operator*(void) { return *_pCurrent; }
44 constexpr Iterator& operator++(void) { ++_pCurrent; return *this; }
46 GX_FORCE_INLINE b32 operator!=(const Iterator& iterator) { return _pCurrent != iterator._pCurrent; }
47
49 //-----------------------------------------------------------
51 //-----------------------------------------------------------
53
55
57 };
58
60 //-----------------------------------------------------------
62 //-----------------------------------------------------------
64
66 GxArray(void);
70 ~GxArray(void) override;
71
73 //-----------------------------------------------------------
75 //-----------------------------------------------------------
77public:
79 GX_FORCE_INLINE void addTop(void* pObject){ insert(0, pObject); }
81 void addBottom(void* pObject);
83 void insert(u32 index, void* pObject);
85 void erase(void* pObject);
87 virtual void erase(u32 index);
89 void eraseAll(void);
91 void remove(void* pObject);
93 void removeFirst(void* pObject);
95 void remove(u32 index);
97 GX_FORCE_INLINE void removeAll(void){ eraseAll(); }
99 void* pop(void);
101 s32 findIndex(void* pObject, u32 startIndex = 0) const;
102
103protected:
105 virtual void** allocateMemory(u32 size) { return static_cast<void**>(GX_ALLOCATE_MEMORY(getGxAllocatorList(_allocatorType), size)); }
108 virtual u32 expandAllocCount(void) { return _allocCount * 2; }
109private:
111 void addCount(void);
112
114 //-----------------------------------------------------------
116 //-----------------------------------------------------------
118public:
120 constexpr __type& operator[](u32 i) const { GX_ASSERT(i < _count, "count error."); return _ppObject[i]; }
122 constexpr __type& operator[](u32 i) { GX_ASSERT(i < _count, "count error."); return _ppObject[i]; }
124 constexpr Iterator<__type> begin(void) const { return { &_ppObject[0] }; }
126 constexpr Iterator<__type> end(void) const { return { &_ppObject[_count] }; }
128 constexpr void* getObject(u32 index) const { return _ppObject[index]; }
130 virtual void setObject(u32 index, void* pObject);
132 constexpr u32 getCount(void) const { return _count; }
134 void setCount(u32 count);
139 void setAllocCount(u32 count);
141 s32 indexOf(void* pObject) const;
142private:
144 constexpr void getPropertyObject(void* pValue, u32 index) const { *static_cast<void**>(pValue) = (index >= _count) ? nullptr : _ppObject[index]; }
146 constexpr void setPropertyObject(const void* pValue, u32 index){ if(index < _count){ _ppObject[index] = *static_cast<void**>(const_cast<void*>(pValue)); } }
147
149 //-----------------------------------------------------------
151 //-----------------------------------------------------------
153protected:
154 void** _ppObject;
155 u32 _count;
158
160};
161
162GX_CORE_NAMESPACE_END()
#define GX_ALLOCATE_MEMORY(pAllocatorList, size)
Definition GxAllocator.h:536
#define GX_PROHIBIT_CLASS_BASE(__CLASS__)
GxClassBase継承の禁止宣言
Definition GxBase.h:240
ALLOCATOR_TYPE
アロケータ定義
Definition GxAllocator.h:355
配列クラス
Definition GxArray.h:18
constexpr u32 getCount(void) const
配列数を取得
Definition GxArray.h:132
constexpr __type & operator[](u32 i) const
const配列
Definition GxArray.h:120
virtual u32 expandAllocCount(void)
Definition GxArray.h:108
constexpr void * getObject(u32 index) const
オブジェクトの取得
Definition GxArray.h:128
GxAllocatorList::ALLOCATOR_TYPE _allocatorType
アロケータ種別
Definition GxArray.h:157
u32 _allocCount
確保した配列数
Definition GxArray.h:156
GX_FORCE_INLINE void addTop(void *pObject)
先頭に追加
Definition GxArray.h:79
constexpr __type & operator[](u32 i)
配列
Definition GxArray.h:122
constexpr Iterator< __type > end(void) const
終端を取得
Definition GxArray.h:126
u32 _count
配列数
Definition GxArray.h:155
void ** _ppObject
配列データ
Definition GxArray.h:154
virtual void ** allocateMemory(u32 size)
メモリ確保関数
Definition GxArray.h:105
GX_FORCE_INLINE void removeAll(void)
全削除
Definition GxArray.h:97
constexpr Iterator< __type > begin(void) const
先頭を取得
Definition GxArray.h:124
オブジェクト基底クラス
Definition GxBase.h:88
イテレータ
Definition GxArray.h:35
constexpr T & operator*(void)
オブジェクト取得
Definition GxArray.h:42
GX_FORCE_INLINE b32 operator!=(const Iterator &iterator)
不一致判定
Definition GxArray.h:46
constexpr Iterator & operator++(void)
インクリメント
Definition GxArray.h:44
T * _pCurrent
カレントオブジェクト
Definition GxArray.h:54
32bitブーリアン
Definition GxDefine.h:173