/src/List.hpp
C++ Header | 88 lines | 55 code | 11 blank | 22 comment | 3 complexity | 732e9316d1159c939976a97f37f0e982 MD5 | raw file
- //------------------------------------//
- //
- // List.hpp
- //
- // Author: ayufan (ayufan[at]o2.pl)
- // Project: ayuine2
- // Date: 2006-9-2
- //
- //------------------------------------//
-
- #pragma once
-
- namespace ayuine
- {
- template<typename Type>
- class List
- {
- ValueType(List<Type>, 0);
-
- // Fields
- public:
- Type* Object;
- List<Type>* Next;
- List<Type>* Prev;
-
- // Constructor
- public:
- List(Type *object) {
- // Ustaw domyślną listę
- Object = object;
- Next = this;
- Prev = this;
- }
-
- // Destructor
- public:
- ~List() {
- // Odepnij listę
- unlink();
- }
-
- // Properties
- public:
- bool empty() const {
- return Next == Prev;
- }
- u32 count() const {
- u32 index = 0;
- for(List<Type>* curr = Next; curr != this; curr = curr->Next) {
- index++;
- }
- return index;
- }
-
- // Methods
- public:
- void linkFront(List<Type> &list) {
- // Podepnij listę z przodu
- Next = list.Next;
- Prev = &list;
-
- // Uaktualnij wskaźniki
- Next->Prev = this;
- Prev->Next = this;
- }
- void linkBack(List<Type> &list) {
- // Podepnij listę z tyłu
- Prev = list.Prev;
- Next = &list;
-
- // Uaktualnij wskaźniki
- Next->Prev = this;
- Prev->Next = this;
- }
- void unlink() {
- Assert(Next);
- Assert(Prev);
-
- // Odepnij listę
- Next->Prev = Prev;
- Prev->Next = Next;
-
- // Ustaw wartości domyślne
- Next = this;
- Prev = this;
- }
- };
- };