voxelTerrain
 All Classes Functions Variables Typedefs Enumerations Pages
list.hpp
1 #ifndef BLUB_LIST_HPP
2 #define BLUB_LIST_HPP
3 
4 #include "blub/core/globals.hpp"
5 
6 #include <boost/container/list.hpp>
7 
8 
9 namespace blub
10 {
11 
12 template <class T>
13 class list : public boost::container::list<T>
14 {
15 public:
16  typedef boost::container::list<T> t_base;
17 
18  list<T>() : boost::container::list<T>() {;}
19  list<T>(const uint32 &num) : boost::container::list<T>() {this->reserve(num);}
20  list<T>(boost::container::list<T> lst) : boost::container::list<T>(lst) {;}
21 
22  T& at(const uint32& ind)
23  {
24  BASSERT(ind < t_base::size());
25  typename t_base::iterator it(t_base::begin());
26  for (uint32 index = 0; index < ind; ++index)
27  {
28  ++it;
29  }
30  return *it;
31  }
32 
33  const T& at(const uint32& ind) const
34  {
35  BASSERT(ind < t_base::size());
36  typename t_base::const_iterator it(t_base::cbegin());
37  for (uint32 index = 0; index < ind; ++index)
38  {
39  ++it;
40  }
41  return *it;
42  }
43 
44  void reserve(uint32 size)
45  {
46  if (t_base::size() > size)
47  {
48  size = t_base::size();
49  }
50  t_base::resize(size);
51  }
52 
53  bool isEmpty(void) const
54  {
55  return t_base::empty();
56  }
57 
58  void insertAt(const uint32& ind, const T& toInsert)
59  {
60  BASSERT(ind < t_base::size());
61  t_base::insert(t_base::cbegin()+ind, toInsert);
62  }
63 
64  void removeAt(const uint32& ind)
65  {
66  BASSERT(ind < t_base::size());
67  typename t_base::const_iterator it(t_base::cbegin());
68  for (uint32 index = 0; index < ind; ++index)
69  {
70  ++it;
71  }
72  t_base::erase(it);
73  }
74 
75  int32 indexOf(const T& toFind)
76  {
77  typename t_base::const_iterator it(t_base::cbegin());
78  for (uint32 index = 0; index < t_base::size(); ++index)
79  {
80  if (*it == toFind)
81  {
82  return index;
83  }
84  ++it;
85  }
86  return -1;
87  }
88 
89  /*
90  T takeAt(uint32 ind)
91  {
92  T result = *(this->begin()+ind);
93  removeAt(ind);
94  return result;
95  }
96 
97  T takeFirst()
98  {
99  T result = *this->begin();
100  removeAt(0);
101  return result;
102  }*/
103 
104  bool push_back_distinct(const T & ins)
105  {
106  if (t_base::indexOf(ins) == -1)
107  {
108  t_base::push_back(ins);
109  return true;
110  }
111  else
112  return false;
113  }
114 };
115 
116 }
117 
118 #endif // BLUB_LIST_HPP
Definition: deadlineTimer.hpp:10
Definition: list.hpp:13