OROCHI
 
Loading...
Searching...
No Matches
GxTree.h
Go to the documentation of this file.
1//===========================================================================
10//===========================================================================
11#pragma once
12
13GX_CORE_NAMESPACE_BEGIN()
14
15//===========================================================================
17//===========================================================================
18class GxTreeBase : public GxClassBase
19{
20 //-----------------------------------------------------------
22 //-----------------------------------------------------------
24public:
25 // RTTI定義
26 GX_RTTI_CLASS(GxTreeBase, GxClassBase)
27 // GxClassBase継承クラス用禁止宣言
29
30 // NEW DELETE 定義
31 GX_OPERATOR_NEW_DELETE(GxAllocatorList::ALLOCATOR_TYPE::TEMPORARY)
32
33 // クラス宣言
34 class GxNodeBase;
35
36 // イテレータ宣言
37 template <class T> class GxIteratorBase;
38
40 //-----------------------------------------------------------
42 //-----------------------------------------------------------
44public:
47 : _pRoot(nullptr)
48 {}
50 ~GxTreeBase(void) { erase(); }
51
53 //-----------------------------------------------------------
55 //-----------------------------------------------------------
57public:
59 GxTreeBase::GxNodeBase* addRootNode(void* pObject);
61 GxTreeBase::GxNodeBase* addNextNode(GxTreeBase::GxNodeBase* pBase, void* pObject);
63 GxTreeBase::GxNodeBase* addChildNode(GxTreeBase::GxNodeBase* pBase, void* pObject);
64
66 void erase(GxTreeBase::GxNodeBase* pNode = nullptr);
67
69 void eraseAll(GxTreeBase::GxNodeBase* pNode);
70
72 GxTreeBase::GxNodeBase* find(const void* pObject);
73
74protected:
76 virtual GxNodeBase* allocateNode(void);
77
79 //-----------------------------------------------------------
81 //-----------------------------------------------------------
83public:
85 constexpr void setRootNode(GxTreeBase::GxNodeBase* pNode) { _pRoot = pNode; }
87 constexpr GxTreeBase::GxNodeBase* getRootNode(void) const { return _pRoot; }
88
90 //-----------------------------------------------------------
92 //-----------------------------------------------------------
94protected:
96
98};
99
100//===========================================================================
102//===========================================================================
104{
105 //-----------------------------------------------------------
107 //-----------------------------------------------------------
109public:
110 // RTTI定義
111 GX_RTTI_CLASS(GxTreeBase::GxNodeBase, GxClassBase)
112 // GxClassBase継承クラス用禁止宣言
114
115 // NEW DELETE 定義
116 GX_OPERATOR_NEW_DELETE(GxAllocatorList::ALLOCATOR_TYPE::TEMPORARY)
117
118
119 //-----------------------------------------------------------
121 //-----------------------------------------------------------
123public:
126 : _pTree(nullptr)
127 , _pObject(nullptr)
128 , _pParent(nullptr)
129 , _pChild(nullptr)
130 , _pPrevious(nullptr)
131 , _pNext(nullptr)
132 {}
133
137 : _pTree(pTree)
138 , _pObject(nullptr)
139 , _pParent(nullptr)
140 , _pChild(nullptr)
141 , _pPrevious(nullptr)
142 , _pNext(nullptr)
143 {}
144
146 ~GxNodeBase(void) { erase(); }
147
149 //-------------------------------
151 //-------------------------------
153
154public:
156 GX_FORCE_INLINE virtual void setObject(void* pObject) { _pObject = pObject; }
158 constexpr void* getObject(void) const { return _pObject; }
160 GX_FORCE_INLINE GxTreeBase::GxNodeBase* getParent(void){ return getPreviousTop()->_pParent; }
162 constexpr GxTreeBase::GxNodeBase* getChild(void) const { return _pChild; }
164 constexpr GxTreeBase::GxNodeBase* getPrevious(void) const { return _pPrevious; }
166 constexpr GxTreeBase::GxNodeBase* getNext(void) const { return _pNext; }
171
173 b32 isRoot(void) const;
175 b32 isChild(const GxTreeBase::GxNodeBase* pNode) const;
177 b32 isBrother(const GxTreeBase::GxNodeBase* pNode) const;
178
180 //-----------------------------------------------------------
182 //-----------------------------------------------------------
184public:
186 virtual void erase(void);
187
189 GxTreeBase::GxNodeBase* find(const void* pObject);
190
197
199 void detach(void);
201 void detachParentPrevious(void);
203 void detachExceptChild(void);
204
206 //-----------------------------------------------------------
208 //-----------------------------------------------------------
210protected:
212 void* _pObject;
217
219};
220
221//===========================================================================
223//===========================================================================
224template<class T> class GxTreeBase::GxIteratorBase
225{
226 //-----------------------------------------------------------
228 //-----------------------------------------------------------
230protected:
233
234public:
238 virtual ~GxIteratorBase(void){}
239
244
246 //-----------------------------------------------------------
248 //-----------------------------------------------------------
250
252 T getTop(void);
254 T getNext(void);
256 T getCurrent(void);
259
261 //-----------------------------------------------------------
263 //-----------------------------------------------------------
265
266protected:
269
271};
272
273//===========================================================================
275//===========================================================================
276class GxTree : public GxTreeBase
277{
278 //-----------------------------------------------------------
280 //-----------------------------------------------------------
282public:
283 // RTTI定義
284 GX_RTTI_CLASS(GxTree, GxTreeBase)
285 // GxClassBase継承クラス用禁止宣言
287
288
293
294 // クラス宣言
295 class GxNode;
296
297 // イテレータ宣言
298 template <class T> class GxIterator;
299
301 //-----------------------------------------------------------
303 //-----------------------------------------------------------
305public:
307 GxTree(u32 attribute = 0)
308 : _attribute(attribute)
309 {}
310
312 ~GxTree(void) {}
313
315 //-----------------------------------------------------------
317 //-----------------------------------------------------------
319public:
321 GX_FORCE_INLINE GxTree::GxNode* addRootNode(GxClassBaseReference* pObject) { return reinterpret_cast<GxTree::GxNode*>(GxTreeBase::addRootNode(static_cast<void*>(pObject))); }
323 GX_FORCE_INLINE GxTree::GxNode* addNextNode(GxTree::GxNode* pBase, GxClassBaseReference* pObject) { return reinterpret_cast<GxTree::GxNode*>(GxTreeBase::addNextNode(reinterpret_cast<GxTreeBase::GxNodeBase*>(pBase), static_cast<void*>(pObject))); }
325 GX_FORCE_INLINE GxTree::GxNode* addChildNode(GxTree::GxNode* pBase, GxClassBaseReference* pObject) { return reinterpret_cast<GxTree::GxNode*>(GxTreeBase::addChildNode(reinterpret_cast<GxTreeBase::GxNodeBase*>(pBase), static_cast<void*>(pObject))); }
326
327protected:
329 GxNodeBase* allocateNode(void) override;
330
332 //-----------------------------------------------------------
334 //-----------------------------------------------------------
336public:
338 GX_FORCE_INLINE GxTree::GxNode* getRootNode(void) const { return reinterpret_cast<GxTree::GxNode*>(_pRoot); }
339
341 constexpr u32 getAttribute(void) const { return _attribute; }
343 constexpr void setAttribute(ATTRIBUTE attribute) { _attribute |= attribute; }
345 constexpr void clearAttribute(ATTRIBUTE attribute) { _attribute &= ~attribute; }
347 GX_FORCE_INLINE b32 isAttribute(ATTRIBUTE attribute) const { return (_attribute & attribute) ? true : false; }
348
350 //-----------------------------------------------------------
352 //-----------------------------------------------------------
354protected:
356
358};
359
360//===========================================================================
362//===========================================================================
364{
365 //-----------------------------------------------------------
367 //-----------------------------------------------------------
369public:
370 // RTTI定義
372 // GxClassBase継承クラス用禁止宣言
374
375
376 //-----------------------------------------------------------
378 //-----------------------------------------------------------
380protected:
382 GxNode(void) {}
383
384public:
388 : GxTreeBase::GxNodeBase(pTree)
389 {}
390
392 ~GxNode(void) {}
393
394 //-------------------------------
396 //-------------------------------
398public:
400 void setObject(void* pObject) override;
402 constexpr GxClassBaseReference* getObject(void) const { return static_cast<GxClassBaseReference*>(_pObject); }
404 GX_FORCE_INLINE GxTree::GxNode* getParent(void){ return static_cast<GxTree::GxNode*>(getPreviousTop()->getParent()); }
406 constexpr GxTree::GxNode* getChild(void) const { return static_cast<GxTree::GxNode*>(_pChild); }
408 constexpr GxTree::GxNode* getPrevious(void) const { return static_cast<GxTree::GxNode*>(_pPrevious); }
410 constexpr GxTree::GxNode* getNext(void) const { return static_cast<GxTree::GxNode*>(_pNext); }
411
413 //-----------------------------------------------------------
415 //-----------------------------------------------------------
417public:
419 void erase(void) override;
420
422};
423
424//===========================================================================
426//===========================================================================
427template<class T> class GxTree::GxIterator : public GxTreeBase::GxIteratorBase<T>
428{
429 //-----------------------------------------------------------
431 //-----------------------------------------------------------
433protected:
435 GxIterator(void) {}
436
437public:
439 GxIterator(GxTreeBase* pTreeBase) : GxTreeBase::GxIteratorBase<T>(pTreeBase) {}
441 ~GxIterator(void) override {}
442
444 //-----------------------------------------------------------
446 //-----------------------------------------------------------
448
450 GX_FORCE_INLINE GxTree::GxNode* getCurrentNode(void) { return static_cast<GxTree::GxNode*>(GxIteratorBase<T>::getCurrentNode()); }
451
453};
454
455//===========================================================================
456// ツリー構造イテレータクラス
457//===========================================================================
458//---------------------------------------------------------------------------
459// 先頭オブジェクト取得
461//---------------------------------------------------------------------------
463{
464 _pCurrent = _pTreeBase->getRootNode();
465 return getCurrent();
466}
467
468//---------------------------------------------------------------------------
469// 次オブジェクト取得
472//---------------------------------------------------------------------------
474{
475 if( _pCurrent )
476 {
477 // 子ノード判定
478 auto* pChild = _pCurrent->getChild();
479 if( pChild )
480 {
481 // 子ノードある → 子ノードをカレントに設定
482 _pCurrent = pChild;
483 }
484 else
485 {
486 // 子ノードない → 兄弟ノード判定
487 auto* pNext = _pCurrent->getNext();
488 if( pNext )
489 {
490 // 兄弟ノードある → 兄弟ノードをカレントに設定
491 _pCurrent = pNext;
492 }
493 else
494 {
495 // 兄弟ノードない → 親ノードの兄弟判定
496 auto* pParent = _pCurrent->getParent();
497 for( ; pParent; pParent = pParent->getParent() )
498 {
499 if( pParent->getNext() )
500 {
501 // 親ノードの兄弟がある → カレントに設定
502 _pCurrent = pParent->getNext();
503 break;
504 }
505 }
506 // 未発見 → nullptr設定
507 if( !pParent )
508 {
509 _pCurrent = nullptr;
510 }
511 }
512 }
513 return getCurrent();
514 }
515 return nullptr;
516}
517
518//---------------------------------------------------------------------------
519// 現在オブジェクト取得
521//---------------------------------------------------------------------------
523{
524 if( _pCurrent )
525 {
526 return static_cast<T>(_pCurrent->getObject());
527 }
528 return nullptr;
529}
530
531//---------------------------------------------------------------------------
532// 現在のノードを取得
534//---------------------------------------------------------------------------
536{
537 return _pCurrent;
538}
539
540GX_CORE_NAMESPACE_END()
#define GX_PROHIBIT_CLASS_BASE(__CLASS__)
GxClassBase継承の禁止宣言
Definition GxBase.h:240
オブジェクト基底クラス
Definition GxBase.h:88
参照オブジェクト基底クラス
Definition GxBase.h:122
ツリー構造イテレータクラス
Definition GxTree.h:428
GX_FORCE_INLINE GxTree::GxNode * getCurrentNode(void)
現在のノードを取得
Definition GxTree.h:450
GxIterator(GxTreeBase *pTreeBase)
コンストラクタ
Definition GxTree.h:439
~GxIterator(void) override
デストラクタ
Definition GxTree.h:441
GxIterator(void)
ディフォルトコンストラクタ (使用禁止)
Definition GxTree.h:435
ツリーノードクラス
Definition GxTree.h:364
~GxNode(void)
デストラクタ
Definition GxTree.h:392
void setObject(void *pObject) override
登録オブジェクト設定
Definition GxTree.cpp:591
constexpr GxTree::GxNode * getChild(void) const
子ノード取得
Definition GxTree.h:406
void erase(void) override
ノード削除
Definition GxTree.cpp:609
constexpr GxClassBaseReference * getObject(void) const
登録オブジェクト取得
Definition GxTree.h:402
GxNode(void)
ディフォルトコンストラクタ (使用禁止)
Definition GxTree.h:382
GxNode(GxTree *pTree)
Definition GxTree.h:387
GX_FORCE_INLINE GxTree::GxNode * getParent(void)
親ノード取得
Definition GxTree.h:404
constexpr GxTree::GxNode * getPrevious(void) const
同一階層前ノード取得
Definition GxTree.h:408
constexpr GxTree::GxNode * getNext(void) const
同一階層次ノード取得
Definition GxTree.h:410
ツリー構造イテレータクラス (任意オブジェクト用)
Definition GxTree.h:225
GxTreeBase::GxNodeBase * getCurrentNode(void)
現在のノードを取得
Definition GxTree.h:535
GxNodeBase * _pCurrent
カレントノード
Definition GxTree.h:268
GxIteratorBase(void)
ディフォルトコンストラクタ (使用禁止)
Definition GxTree.h:232
T getCurrent(void)
現在のオブジェクトを取得
Definition GxTree.h:522
GxTreeBase * _pTreeBase
操作ツリー
Definition GxTree.h:267
GxIteratorBase(const GxTreeBase::GxIteratorBase< T > &iterator)
コピーコンストラクタ
Definition GxTree.h:241
T getNext(void)
次を取得
Definition GxTree.h:473
const GxTreeBase::GxIteratorBase< T > & operator=(GxTreeBase::GxIteratorBase< T > &iterator)
代入
Definition GxTree.h:243
T getTop(void)
先頭を取得
Definition GxTree.h:462
GxIteratorBase(GxTreeBase *pTreeBase)
コンストラクタ
Definition GxTree.h:236
virtual ~GxIteratorBase(void)
デストラクタ
Definition GxTree.h:238
ツリーノードクラス (任意オブジェクト用)
Definition GxTree.h:104
constexpr GxTreeBase::GxNodeBase * getChild(void) const
子ノード取得
Definition GxTree.h:162
void attachNextEnd(GxTreeBase::GxNodeBase *pNode)
指定ノードの末弟に接続
Definition GxTree.cpp:412
GxTreeBase::GxNodeBase * _pPrevious
同一階層前ノード
Definition GxTree.h:215
GxTreeBase::GxNodeBase * _pParent
親ノード
Definition GxTree.h:213
void * _pObject
登録オブジェクト
Definition GxTree.h:212
constexpr GxTreeBase::GxNodeBase * getNext(void) const
同一階層次ノード取得
Definition GxTree.h:166
~GxNodeBase(void)
デストラクタ
Definition GxTree.h:146
b32 isBrother(const GxTreeBase::GxNodeBase *pNode) const
同一階層ノード判定
Definition GxTree.cpp:279
GxTreeBase::GxNodeBase * _pNext
同一階層次ノード
Definition GxTree.h:216
GxTreeBase::GxNodeBase * getPreviousTop(void)
同一階層先頭(長兄)ノード取得
Definition GxTree.cpp:218
GxTreeBase::GxNodeBase * _pChild
子ノード
Definition GxTree.h:214
b32 isChild(const GxTreeBase::GxNodeBase *pNode) const
子ノード判定
Definition GxTree.cpp:258
void detach(void)
ノードの接続分離
Definition GxTree.cpp:437
GxNodeBase(GxTreeBase *pTree)
Definition GxTree.h:136
GxTreeBase * _pTree
所属ツリー
Definition GxTree.h:211
void attachChild(GxTreeBase::GxNodeBase *pNode)
指定ノードのChildに接続
Definition GxTree.cpp:366
void detachExceptChild(void)
子以外のノードの接続分離
Definition GxTree.cpp:520
void detachParentPrevious(void)
親、兄のノードの接続分離
Definition GxTree.cpp:482
GxNodeBase(void)
ディフォルトコンストラクタ (使用禁止)
Definition GxTree.h:125
GxTreeBase::GxNodeBase * getNextEnd(void)
同一階層終端(末弟)ノード取得
Definition GxTree.cpp:233
virtual void erase(void)
ノード削除
Definition GxTree.cpp:320
void attachNext(GxTreeBase::GxNodeBase *pNode)
指定ノードのNextに接続
Definition GxTree.cpp:389
virtual GX_FORCE_INLINE void setObject(void *pObject)
登録オブジェクト設定
Definition GxTree.h:156
GxTreeBase::GxNodeBase * find(const void *pObject)
ノードの探索
Definition GxTree.cpp:335
b32 isRoot(void) const
ルートノード判定
Definition GxTree.cpp:248
GX_FORCE_INLINE GxTreeBase::GxNodeBase * getParent(void)
親ノード取得
Definition GxTree.h:160
constexpr void * getObject(void) const
登録オブジェクト取得
Definition GxTree.h:158
constexpr GxTreeBase::GxNodeBase * getPrevious(void) const
同一階層前ノード取得
Definition GxTree.h:164
ツリー構造クラス (任意オブジェクト用)
Definition GxTree.h:19
GxTreeBase::GxNodeBase * addNextNode(GxTreeBase::GxNodeBase *pBase, void *pObject)
Nextノード追加
Definition GxTree.cpp:65
GxTreeBase(void)
コンストラクタ
Definition GxTree.h:46
constexpr GxTreeBase::GxNodeBase * getRootNode(void) const
ルートノードの取得
Definition GxTree.h:87
GxTreeBase::GxNodeBase * addChildNode(GxTreeBase::GxNodeBase *pBase, void *pObject)
Childノード追加
Definition GxTree.cpp:92
GxTreeBase::GxNodeBase * _pRoot
ルートノード
Definition GxTree.h:95
constexpr void setRootNode(GxTreeBase::GxNodeBase *pNode)
ルートノードの設定
Definition GxTree.h:85
~GxTreeBase(void)
デストラクタ
Definition GxTree.h:50
GxTreeBase::GxNodeBase * addRootNode(void *pObject)
Rootノード追加
Definition GxTree.cpp:38
ツリー構造クラス (クラスオブジェクト)
Definition GxTree.h:277
GX_FORCE_INLINE GxTree::GxNode * getRootNode(void) const
ルートノードの取得
Definition GxTree.h:338
constexpr void setAttribute(ATTRIBUTE attribute)
属性の設定
Definition GxTree.h:343
constexpr void clearAttribute(ATTRIBUTE attribute)
属性の解除
Definition GxTree.h:345
~GxTree(void)
デストラクタ
Definition GxTree.h:312
GX_FORCE_INLINE GxTree::GxNode * addNextNode(GxTree::GxNode *pBase, GxClassBaseReference *pObject)
Nextノード追加
Definition GxTree.h:323
u32 _attribute
属性
Definition GxTree.h:355
GX_FORCE_INLINE GxTree::GxNode * addRootNode(GxClassBaseReference *pObject)
Rootノード追加
Definition GxTree.h:321
ATTRIBUTE
属性
Definition GxTree.h:290
@ ATTRIBUTE_USE_REFERENCE_COUNT
属性:参照カウンタ使用フラグ
Definition GxTree.h:291
GX_FORCE_INLINE GxTree::GxNode * addChildNode(GxTree::GxNode *pBase, GxClassBaseReference *pObject)
Childノード追加
Definition GxTree.h:325
GX_FORCE_INLINE b32 isAttribute(ATTRIBUTE attribute) const
属性の判定
Definition GxTree.h:347
constexpr u32 getAttribute(void) const
属性の取得
Definition GxTree.h:341
GxTree(u32 attribute=0)
コンストラクタ
Definition GxTree.h:307
GxNodeBase * allocateNode(void) override
Nodeのメモリ確保
Definition GxTree.cpp:573
32bitブーリアン
Definition GxDefine.h:173