Imported Upstream version 2.81
[platform/upstream/libbullet.git] / Extras / HACD / hacdCircularList.h
1 /* Copyright (c) 2011 Khaled Mamou (kmamou at gmail dot com)\r
2  All rights reserved.\r
3  \r
4  \r
5  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:\r
6  \r
7  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.\r
8  \r
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.\r
10  \r
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.\r
12  \r
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.\r
14  */\r
15 #pragma once\r
16 #ifndef HACD_CIRCULAR_LIST_H\r
17 #define HACD_CIRCULAR_LIST_H\r
18 #include<stdlib.h>\r
19 #include "hacdVersion.h"\r
20 namespace HACD\r
21 {\r
22         //!     CircularListElement class.\r
23         template < typename T > class CircularListElement\r
24         {\r
25     public:\r
26         T &                                     GetData() { return m_data; }\r
27         const T &                               GetData() const { return m_data; }\r
28         CircularListElement<T> * &                              GetNext() { return m_next; }\r
29         CircularListElement<T> * &                              GetPrev() { return m_prev; }\r
30         const CircularListElement<T> * &                GetNext() const { return m_next; }\r
31         const CircularListElement<T> * &                GetPrev() const { return m_prev; }        \r
32         //!     Constructor\r
33                                                                                                 CircularListElement(const T & data) {m_data = data;}\r
34                                                                                                 CircularListElement(void){}\r
35         //! Destructor\r
36                                                                                                 ~CircularListElement(void){}\r
37     private:\r
38         T                                                                               m_data;\r
39         CircularListElement<T> *                                m_next; \r
40         CircularListElement<T> *                                m_prev;\r
41 \r
42                                                                                                 CircularListElement(const CircularListElement & rhs);\r
43         };\r
44     \r
45     \r
46         //!     CircularList class.\r
47         template < typename T > class CircularList\r
48         {\r
49         public:\r
50         CircularListElement<T> *  &             GetHead() { return m_head;}        \r
51                 const CircularListElement<T> *          GetHead() const { return m_head;}\r
52                 bool                                    IsEmpty() const { return (m_size == 0);}\r
53                 size_t                                  GetSize() const { return m_size; }\r
54                 const T &                               GetData() const { return m_head->GetData(); }        \r
55                 T &                                     GetData() { return m_head->GetData();}\r
56                 bool                                    Delete() ;\r
57         bool                                    Delete(CircularListElement<T> * element);\r
58                 CircularListElement<T> *                Add(const T * data = 0);\r
59                 CircularListElement<T> *                Add(const T & data);\r
60                 bool                                    Next();\r
61                 bool                                    Prev();\r
62                 void                                                                    Clear() { while(Delete());};\r
63         const CircularList&                                             operator=(const CircularList& rhs);\r
64                 //!     Constructor                                                                                     \r
65                                                                                                 CircularList()\r
66                                                                                                 { \r
67                                                                                                         m_head = 0; \r
68                                                                                                         m_size = 0;\r
69                                                                                                 }\r
70                                                                                                 CircularList(const CircularList& rhs);\r
71                 //! Destructor\r
72                 virtual                                                             ~CircularList(void) {Clear();};\r
73         private:\r
74                 CircularListElement<T> *                                m_head;         //!< a pointer to the head of the circular list\r
75                 size_t                                                                  m_size;         //!< number of element in the circular list\r
76         \r
77         };\r
78 }\r
79 #include "hacdCircularList.inl"\r
80 #endif\r