GDevelop Core
Core library for developing platforms and tools compatible with GDevelop.
SPtrList.h
1 /*
2  * GDevelop Core
3  * Copyright 2008-2016 Florian Rival ([email protected])
4  and Victor Levasseur
6  * This project is released under the MIT License.
7  */
8 
9 #ifndef GDCORE_SPTRLIST
10 #define GDCORE_SPTRLIST
11 
12 #include <memory>
13 #include <vector>
14 
15 namespace gd {
16 
17 template <typename T>
18 class SPtrList {
19  public:
20  SPtrList();
21  SPtrList(const SPtrList<T>&);
22  virtual ~SPtrList(){};
23  SPtrList<T>& operator=(const SPtrList<T>& rhs);
24 
33  T& Insert(const T& element, size_t position = (size_t)-1);
34 
42  void Insert(std::shared_ptr<T> element, size_t position = (size_t)-1);
43 
47  void Insert(const SPtrList<T>& otherEvents,
48  size_t begin,
49  size_t end,
50  size_t position = (size_t)-1);
51 
55  size_t GetCount() const { return elements.size(); };
56 
61  std::shared_ptr<T> GetSmartPtr(size_t index) { return elements[index]; };
62 
67  T& Get(size_t index) { return *elements[index]; };
68 
73  const T& Get(size_t index) const { return *elements[index]; };
74 
78  void Remove(const T& element);
79 
83  void Remove(size_t index);
84 
88  bool IsEmpty() const { return elements.empty(); };
89 
93  void Clear() { return elements.clear(); };
94 
99 
103  bool Contains(const T& elementToSearch) const;
105 
111 
116  size_t size() const { return GetCount(); }
117 
122  bool empty() const { return IsEmpty(); }
123 
128  T& operator[](size_t index) { return Get(index); };
129 
134  const T& operator[](size_t index) const { return Get(index); };
135 
140  T& at(size_t index) { return Get(index); };
141 
146  const T& at(size_t index) const { return Get(index); };
148 
149  protected:
150  std::vector<std::shared_ptr<T> > elements;
151 
156  void Init(const SPtrList<T>& other);
157 };
158 
159 } // namespace gd
160 
161 #include "SPtrList.inl"
162 
163 #endif
Definition: SPtrList.h:18
T & at(size_t index)
Alias for Get()
Definition: SPtrList.h:140
const T & operator[](size_t index) const
Alias for Get()
Definition: SPtrList.h:134
void Init(const SPtrList< T > &other)
Definition: SPtrList.inl:90
const T & at(size_t index) const
Alias for Get()
Definition: SPtrList.h:146
T & Insert(const T &element, size_t position=(size_t) -1)
Insert the specified element to the list.
Definition: SPtrList.inl:35
const T & Get(size_t index) const
Return a reference to the element at position index in the elements list.
Definition: SPtrList.h:73
T & operator[](size_t index)
Alias for Get()
Definition: SPtrList.h:128
size_t size() const
Alias for GetCount()
Definition: SPtrList.h:116
void Remove(const T &element)
Remove the specified element.
Definition: SPtrList.inl:59
bool empty() const
Alias for IsEmpty()
Definition: SPtrList.h:122
void Clear()
Clear the list of elements.
Definition: SPtrList.h:93
T & Get(size_t index)
Return a reference to the element at position index in the elements list.
Definition: SPtrList.h:67
size_t GetCount() const
Return the number of elements.
Definition: SPtrList.h:55
bool IsEmpty() const
Return true if there isn't any element in the list.
Definition: SPtrList.h:88
bool Contains(const T &elementToSearch) const
Definition: SPtrList.inl:69
std::shared_ptr< T > GetSmartPtr(size_t index)
Return the smart pointer to the element at position index in the elements list.
Definition: SPtrList.h:61
Definition: CommonTools.h:24