CSEngine
Loading...
Searching...
No Matches
SContainerList.h
1#pragma once
2
3#include <algorithm>
4#include <list>
5#include "SIContainer.h"
6
7namespace CSE {
8
9 template <class T>
10 class SContainerList : public SIContainer<std::list<T>, T, int> {
11 public:
12 SContainerList() = default;
13 ~SContainerList() override = default;
14
15 void Register(T object) override {
16 m_objects.push_back(object);
17 m_size++;
18 }
19
20 void Remove(T object) override {
21// auto iObj = std::find(m_objects.begin(), m_objects.end(), object);
22// if (iObj != m_objects.end()) {
23 m_objects.remove(object);
24// }
25 }
26
27 T Get(int index) const override {
28 if (index < 0 || index > m_size || m_size < 1) return nullptr;
29 auto iter = m_objects.begin();
30 std::advance(iter, index);
31 return *iter;
32 }
33
34 std::list<T> GetAll() const override {
35 return m_objects;
36 }
37
38 int GetID(T object) const override {
39 auto it = std::find(m_objects.begin(), m_objects.end(), object);
40 if (it == m_objects.end())
41 return -1;
42 else
43 return std::distance(m_objects.begin(), it);
44 }
45
46 int GetSize() const override {
47 return m_size;
48 }
49
50
51 protected:
52 std::list<T> m_objects;
53 int m_size = 0;
54 };
55
56}