GL Studio API
tlist.h
Go to the documentation of this file.
1 /*! \file
2  \brief A templated list, disti::TList.
3 
4  \par Copyright Information
5 
6  Copyright (c) 2015 by The DiSTI Corporation.<br>
7  11301 Corporate Blvd; Suite 100<br>
8  Orlando, Florida 32817<br>
9  USA<br>
10  <br>
11  All rights reserved.<br>
12 
13  This Software contains proprietary trade secrets of DiSTI and may not be
14 reproduced, in whole or part, in any form, or by any means of electronic,
15 mechanical, or otherwise, without the written permission of DiSTI. Said
16 permission may be derived through the purchase of applicable DiSTI product
17 licenses which detail the distribution rights of this content and any
18 Derivative Works based on this or other copyrighted DiSTI Software.
19 
20  NO WARRANTY. THE SOFTWARE IS PROVIDED "AS-IS," WITHOUT WARRANTY OF ANY KIND,
21 AND ANY USE OF THIS SOFTWARE PRODUCT IS AT YOUR OWN RISK. TO THE MAXIMUM EXTENT
22 PERMITTED BY APPLICABLE LAW, DISTI AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES
23 AND CONDITIONS, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
24 IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY AND/OR FITNESS FOR A
25 PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT, WITH REGARD TO THE SOFTWARE.
26 
27  LIMITATION OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW,
28 IN NO EVENT SHALL DISTI OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
29 INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION,
30 DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS
31 INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR
32 INABILITY TO USE THE SOFTWARE, EVEN IF DISTI HAS BEEN ADVISED OF THE POSSIBILITY
33 OF SUCH DAMAGES. DISTI'S ENTIRE LIABILITY AND YOUR EXCLUSIVE REMEDY SHALL NOT
34 EXCEED FIVE DOLLARS (US$5.00).
35 
36  The aforementioned terms and restrictions are governed by the laws of the
37 State of Florida and the United States of America.
38 
39 */
40 #ifndef _TLIST_H
41 #define _TLIST_H
42 
43 #include "disti_include.h"
44 
45 namespace disti
46 {
47 
48 /** A templated list class */
49 template <class T, const int deleteOnRemove = 0>
50 class TList
51 {
52 
53 public:
54  /** List Item */
55  class ListItem
56  {
57  public:
58  ListItem *_next;
59  ListItem *_prev;
60  T _data;
61  public:
62  ListItem( T &data) :
63  _next(0),
64  _prev(0),
65  _data(data)
66  {
67  }
68  virtual ~ListItem()
69  {
70  //FIXTHIS if (deleteOnRemove)
71  // We need to cleanup delete _data;
72  }
73  ListItem *Next()
74  {
75  return _next;
76  }
77  ListItem *Prev()
78  {
79  return _prev;
80  }
81  void Next(ListItem *next)
82  {
83  _next = next;
84  }
85  void Prev(ListItem *prev)
86  {
87  _prev = prev;
88  }
89 
90  T &Data()
91  {
92  return _data;
93  }
94 
95  void Data( T &data )
96  {
97  _data = data;
98  }
99  };
100 
101 private:
102  ListItem *_head;
103  ListItem *_tail;
104  int _count;
105 public:
106 
107  TList() :
108  _head(0),
109  _tail(0),
110  _count(0)
111  {
112  }
113  virtual ~TList()
114  {
115  while(_head)
116  Remove(_head);
117  }
118 
119  void InsertAfter( ListItem *where, T &val )
120  {
121  ListItem *newItem = new ListItem(val);
122 
123  // List is empty, where doesn't matter
124  if (_tail == 0 &&
125  _head == 0)
126  {
127  _tail = _head = newItem;
128  }
129  else
130  {
131  if (where == _tail)
132  {
133  _tail = newItem;
134  }
135  newItem->Prev(where);
136  newItem->Next(where->Next());
137  if (where->Next())
138  where->Next()->Prev(newItem);
139  where->Next(newItem);
140  }
141 
142  _count++;
143  }
144 
145  /*void Add( T &val )
146  {
147  InsertAfter(_tail, val);
148  }
149  */
150  void Add( T val )
151  {
152  InsertAfter(_tail, val);
153  }
154 
155  void InsertBefore( ListItem *where, T &val )
156  {
157  ListItem *newItem = new ListItem(val);
158 
159  // List is empty, where doesn't matter
160  if (_tail == 0 &&
161  _head == 0)
162  {
163  _tail = _head = newItem;
164  }
165  else
166  {
167  if (where == _head)
168  {
169  _head = newItem;
170  }
171  newItem->Next(where);
172  newItem->Prev(where->Prev());
173  if (where->Prev())
174  where->Prev()->Next(newItem);
175  where->Prev(newItem);
176  }
177  _count++;
178  }
179  ListItem *First()
180  {
181  return _head;
182  }
183  ListItem *Last()
184  {
185  return _tail;
186  }
187  int Count()
188  {
189  return _count;
190  }
191  void Remove(ListItem *where)
192  {
193  if (!where || _count <= 0)
194  return;
195 
196  if (where == _head)
197  {
198  _head = where->Next();
199 
200  }
201  if (where == _tail)
202  {
203  _tail = where->Prev();
204  }
205 
206  if (where->Prev())
207  where->Prev()->Next(where->Next());
208  if (where->Next())
209  where->Next()->Prev(where->Prev());
210 
211  delete where;
212  _count--;
213  }
214 
215 };
216 
217 }
218 #endif
219 
A file for all GL Studio files to include.
Definition: tlist.h:50
Definition: bmpimage.h:46
Definition: tlist.h:55