Main Page Class List Class Members

vhacdCircularList.h
Go to the documentation of this file.
1 /* Copyright (c) 2011 Khaled Mamou (kmamou at gmail dot com)
2 All rights reserved.
3
4
5 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6
7 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
8
9 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
10
11 3. The names of the contributors may not be used to endorse or promote products derived from this software without specific prior written permission.
12
13 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14 */
15 #pragma once
16 #ifndef VHACD_CIRCULAR_LIST_H
17 #define VHACD_CIRCULAR_LIST_H
18 #include <stdlib.h>
19 namespace VHACD {
21 template <typename T>
22 class CircularListElement {
23 public:
24 T& GetData() { return m_data; }
25 const T& GetData() const { return m_data; }
26 CircularListElement<T>*& GetNext() { return m_next; }
27 CircularListElement<T>*& GetPrev() { return m_prev; }
28 const CircularListElement<T>*& GetNext() const { return m_next; }
29 const CircularListElement<T>*& GetPrev() const { return m_prev; }
31 CircularListElement(const T& data) { m_data = data; }
32 CircularListElement(void) {}
34 ~CircularListElement(void) {}
35 private:
36 T m_data;
37 CircularListElement<T>* m_next;
38 CircularListElement<T>* m_prev;
39
40 CircularListElement(const CircularListElement& rhs);
41 };
43 template <typename T>
44 class CircularList {
45 public:
46 CircularListElement<T>*& GetHead() { return m_head; }
47 const CircularListElement<T>* GetHead() const { return m_head; }
48 bool IsEmpty() const { return (m_size == 0); }
49 size_t GetSize() const { return m_size; }
50 const T& GetData() const { return m_head->GetData(); }
51 T& GetData() { return m_head->GetData(); }
52 bool Delete();
53 bool Delete(CircularListElement<T>* element);
54 CircularListElement<T>* Add(const T* data = 0);
55 CircularListElement<T>* Add(const T& data);
56 bool Next();
57 bool Prev();
58 void Clear()
59 {
60 while (Delete())
61 ;
62 };
63 const CircularList& operator=(const CircularList& rhs);
65 CircularList()
66 {
67 m_head = 0;
68 m_size = 0;
69 }
70 CircularList(const CircularList& rhs);
72 ~CircularList(void) { Clear(); };
73 private:
74 CircularListElement<T>* m_head;
75 size_t m_size;
76 };
77 }
78 #include "vhacdCircularList.inl"
79 #endif // VHACD_CIRCULAR_LIST_H
VHACD::CircularList::CircularList
CircularList()
Constructor.
Definition: vhacdCircularList.h:65
VHACD::CircularList::GetHead
const CircularListElement< T > * GetHead() const
Definition: vhacdCircularList.h:47
VHACD::CircularListElement::GetNext
const CircularListElement< T > *& GetNext() const
Definition: vhacdCircularList.h:28
VHACD::CircularListElement::GetPrev
CircularListElement< T > *& GetPrev()
Definition: vhacdCircularList.h:27
VHACD::CircularListElement::GetData
T & GetData()
Definition: vhacdCircularList.h:24
VHACD::CircularListElement::~CircularListElement
~CircularListElement(void)
Destructor.
Definition: vhacdCircularList.h:34
VHACD::CircularListElement::CircularListElement
CircularListElement(void)
Definition: vhacdCircularList.h:32
VHACD::CircularListElement
CircularListElement class.
Definition: vhacdCircularList.h:22
VHACD::CircularListElement::GetPrev
const CircularListElement< T > *& GetPrev() const
Definition: vhacdCircularList.h:29
VHACD::CircularListElement::CircularListElement
CircularListElement(const T &data)
Constructor.
Definition: vhacdCircularList.h:31
VHACD::CircularListElement::GetNext
CircularListElement< T > *& GetNext()
Definition: vhacdCircularList.h:26
VHACD::CircularList::GetData
T & GetData()
Definition: vhacdCircularList.h:51
VHACD
Definition: vhacdCircularList.h:19
VHACD::CircularList::~CircularList
~CircularList(void)
Destructor.
Definition: vhacdCircularList.h:72
VHACD::CircularList::GetData
const T & GetData() const
Definition: vhacdCircularList.h:50
VHACD::CircularList::IsEmpty
bool IsEmpty() const
Definition: vhacdCircularList.h:48
VHACD::CircularList::GetHead
CircularListElement< T > *& GetHead()
Definition: vhacdCircularList.h:46
VHACD::CircularList
CircularList class.
Definition: vhacdCircularList.h:44
VHACD::CircularList::GetSize
size_t GetSize() const
Definition: vhacdCircularList.h:49
VHACD::CircularListElement::GetData
const T & GetData() const
Definition: vhacdCircularList.h:25
VHACD::CircularList::Clear
void Clear()
Definition: vhacdCircularList.h:58