MxEngine
ComponentView.h
1 // Copyright(c) 2019 - 2020, #Momo
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are met :
6 //
7 // 1. Redistributions of source code must retain the above copyright notice, this
8 // list of conditions and the following disclaimer.
9 //
10 // 2. Redistributions in binary form must reproduce the above copyright notice,
11 // this list of conditions and the following disclaimer in the documentation
12 // and /or other materials provided with the distribution.
13 //
14 // 3. Neither the name of the copyright holder nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 // DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 // DAMAGES(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 // OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 
29 #pragma once
30 
31 #include "Utilities/AbstractFactory/AbstractFactory.h"
32 #include "Utilities/VectorPool/VectorPool.h"
33 
34 namespace MxEngine
35 {
41  template<typename T>
43  {
44  public:
46 
51  {
52  public:
53  using PoolIterator = typename Pool::PoolIterator;
54  private:
58  PoolIterator it;
59  public:
64  ComponentIterator(PoolIterator it) : it(it) {}
65 
71  {
72  ComponentIterator copy = *this;
73  it++;
74  return copy;
75  }
76 
82  {
83  ++it;
84  return *this;
85  }
86 
92  {
93  ComponentIterator copy = *this;
94  it--;
95  return copy;
96  }
97 
103  {
104  --it;
105  return *this;
106  }
107 
113  {
114  return &it->value;
115  }
116 
121  const T* operator->() const
122  {
123  return &it->value;
124  }
125 
131  {
132  return it->value;
133  }
134 
139  const T& operator*() const
140  {
141  return it->value;
142  }
143 
148  bool operator==(const ComponentIterator& other) const
149  {
150  return it == other.it;
151  }
152 
157  bool operator!=(const ComponentIterator& other) const
158  {
159  return it != other.it;
160  }
161  };
162  private:
166  Pool& ref;
167  public:
172  explicit ComponentView(Pool& ref) : ref(ref) {}
173 
179  {
180  return ComponentIterator{ ref.begin() };
181  }
182 
187  const ComponentIterator begin() const
188  {
189  return ComponentIterator{ ref.begin() };
190  }
191 
197  {
198  return ComponentIterator{ ref.end() };
199  }
200 
205  const ComponentIterator end() const
206  {
207  return ComponentIterator{ ref.end() };
208  }
209  };
210 }
T * operator->()
Definition: ComponentView.h:112
const ComponentIterator end() const
Definition: ComponentView.h:205
bool operator!=(const ComponentIterator &other) const
Definition: ComponentView.h:157
ComponentIterator operator--()
Definition: ComponentView.h:102
Definition: VectorPool.h:49
ComponentIterator operator++()
Definition: ComponentView.h:81
ComponentView(Pool &ref)
Definition: ComponentView.h:172
ComponentIterator operator--(int)
Definition: ComponentView.h:91
Definition: ComponentView.h:50
Definition: ComponentView.h:42
PoolIterator begin()
Definition: VectorPool.h:348
Definition: VectorPool.h:42
ComponentIterator(PoolIterator it)
Definition: ComponentView.h:64
T & operator*()
Definition: ComponentView.h:130
ComponentIterator begin()
Definition: ComponentView.h:178
bool operator==(const ComponentIterator &other) const
Definition: ComponentView.h:148
ComponentIterator end()
Definition: ComponentView.h:196
ComponentIterator operator++(int)
Definition: ComponentView.h:70
Definition: Application.cpp:49
PoolIterator end()
Definition: VectorPool.h:366
const ComponentIterator begin() const
Definition: ComponentView.h:187