diff options
author | Benoit Bolsee <benoit.bolsee@online.be> | 2009-09-25 01:22:24 +0400 |
---|---|---|
committer | Benoit Bolsee <benoit.bolsee@online.be> | 2009-09-25 01:22:24 +0400 |
commit | 1483fafd1372a3d3e025d08634e798adb7da512f (patch) | |
tree | 9191765749e29866339f4c31d892603f5f8b334d /source/gameengine/SceneGraph | |
parent | c995c605f640d8d688e6e58e0fe247ca83f91696 (diff) | |
parent | 222fe6b1a5d49f67177cbb762f55a0e482145f5d (diff) |
Merge of itasc branch. Project files, scons and cmake should be working. Makefile updated but not tested. Comes with Eigen2 2.0.6 C++ matrix library.
Diffstat (limited to 'source/gameengine/SceneGraph')
-rw-r--r-- | source/gameengine/SceneGraph/SG_DList.h | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/source/gameengine/SceneGraph/SG_DList.h b/source/gameengine/SceneGraph/SG_DList.h index 3e17fb55dc0..97951792ab5 100644 --- a/source/gameengine/SceneGraph/SG_DList.h +++ b/source/gameengine/SceneGraph/SG_DList.h @@ -89,6 +89,46 @@ public: } }; + template<typename T> class const_iterator + { + private: + const SG_DList& m_head; + const T* m_current; + public: + typedef const_iterator<T> _myT; + const_iterator(const SG_DList& head) : m_head(head), m_current(NULL) {} + ~const_iterator() {} + + void begin() + { + m_current = (const T*)m_head.Peek(); + } + void back() + { + m_current = (const T*)m_head.Back(); + } + bool end() + { + return (m_current == (const T*)m_head.Self()); + } + const T* operator*() + { + return m_current; + } + _myT& operator++() + { + // no check of NULL! make sure you don't try to increment beyond end + m_current = (const T*)m_current->Peek(); + return *this; + } + _myT& operator--() + { + // no check of NULL! make sure you don't try to increment beyond end + m_current = (const T*)m_current->Back(); + return *this; + } + }; + SG_DList() { m_flink = m_blink = this; @@ -159,6 +199,18 @@ public: { return this; } + inline const SG_DList *Peek() const // Look at front without removing + { + return (const SG_DList*)m_flink; + } + inline const SG_DList *Back() const // Look at front without removing + { + return (const SG_DList*)m_blink; + } + inline const SG_DList *Self() const + { + return this; + } #ifdef WITH_CXX_GUARDEDALLOC @@ -168,5 +220,32 @@ public: #endif }; +/** + * SG_DListHead : Template class that implements copy constructor to duplicate list automatically + * The elements of the list must have themselves a copy constructor. + */ +template<typename T> class SG_DListHead : public SG_DList +{ +public: + typedef SG_DListHead<T> _myT; + SG_DListHead() : SG_DList() {} + SG_DListHead(const _myT& other) : SG_DList() + { + // copy the list, assuming objects of type T + const_iterator<T> eit(other); + T* elem; + for (eit.begin(); !eit.end(); ++eit) { + elem = (*eit)->GetReplica(); + AddBack(elem); + } + } + virtual ~SG_DListHead() {} + T* Remove() + { + return static_cast<T*>(SG_DList::Remove()); + } + +}; + #endif //__SG_DLIST |