Trax3 3.1.0
trax track library
Loading...
Searching...
No Matches
Collection.h
1// Copyright (c) 2013 - 2019 Marc-Michael Horstmann;
2// Copyright (c) 2020 - 2024 Trend Verlag;
3//
4// trax track library
5// AD 2016
6//
7// "If I don't go crazy, I'll loose my mind"
8//
9// Death In Vegas
10
11#pragma once
12
13#include "ObjectIDDecorator.h"
14
15#include <map>
16
17namespace trax{
18
19 template<class Collection_Type,class Value_Type>
20 struct Collection{
21
24 using collection_type = Collection_Type;
25 using value_type = Value_Type;
27
28
29 template<typename _value_type, typename _std_iterator_type>
30 class iterator_imp{
31 public:
35 using iterator_category = std::bidirectional_iterator_tag;
36 using value_type = _value_type;
37 using difference_type = int;
38 using distance_type = int;
39 using pointer = std::shared_ptr<_value_type>;
40 using reference = _value_type&;
42
43
44 inline iterator_imp( const _std_iterator_type& iter ) noexcept
45 : m_Current{iter}
46 {}
47
48
51 inline bool operator==( const iterator_imp& iter ) const noexcept{
52 return m_Current == iter.m_Current;
53 }
54
55 inline bool operator!=( const iterator_imp& iter ) const noexcept{
56 return m_Current != iter.m_Current;
57 }
58
59 inline iterator_imp& operator++() noexcept{
60 ++m_Current;
61 return *this;
62 }
63
64 inline iterator_imp operator++(int) noexcept{
65 iterator_imp retval( *this );
66 ++m_Current;
67 return retval;
68 }
69
70 inline iterator_imp& operator--() noexcept{
71 --m_Current;
72 return *this;
73 }
74
75 inline iterator_imp operator--(int) noexcept{
76 iterator_imp retval( *this );
77 --m_Current;
78 return retval;
79 }
80
81 inline reference operator*() const noexcept{
82 return *m_Current->second;
83 }
84
85 inline pointer operator->() const noexcept{
86 return m_Current->second;
87 }
89 private:
90 _std_iterator_type m_Current;
91 };
92
94
96
97
99 virtual const char* TypeName() const noexcept = 0;
100
101
104 virtual bool IsValid() const noexcept = 0;
105
106
115 virtual IDType Add( std::shared_ptr<Value_Type> pValue_Type ) = 0;
116
117
124 virtual IDType AddRelaxed( std::shared_ptr<Value_Type> pTraxType ) = 0;
125
126
133 virtual bool Remove( Value_Type* pValue_Type, bool zeroIDs = false ) = 0;
134
135
142 virtual int Take( Collection_Type& collection_Type ) = 0;
143
144
146 virtual void Clear() = 0;
147
148
150 virtual int Count() const = 0;
151
152
154 virtual iterator begin() = 0;
155
156
158 virtual const_iterator begin() const = 0;
159
160 virtual const_iterator cbegin() const = 0;
161
162
164 virtual iterator end() = 0;
165
166
168 virtual const_iterator end() const = 0;
169
170 virtual const_iterator cend() const = 0;
171
172
174 virtual std::shared_ptr<Value_Type> GetFirst() const = 0;
175
176
180 virtual std::shared_ptr<Value_Type> GetNext( const std::shared_ptr<Value_Type>& pValue_Type ) const = 0;
181
182
184 virtual std::shared_ptr<Value_Type> GetLast() const = 0;
185
186
190 virtual std::shared_ptr<Value_Type> GetPrevious( const std::shared_ptr<Value_Type>& pValue_Type ) const = 0;
191
192
199 virtual std::shared_ptr<Value_Type> Get( IDType id ) const = 0;
200
201 virtual std::shared_ptr<Value_Type> Get( const std::string& name ) const = 0;
203
204
211 virtual void PushActive( IDType id ) = 0;
212
213
216 virtual void PopActive() = 0;
217
218
220 virtual std::shared_ptr<Value_Type> GetActive() const = 0;
221
222
229 virtual bool IsMember( const value_type& item ) const = 0;
230
231 virtual bool IsMember( IDType id ) const = 0;
233
234
241 virtual void ShiftIDs( int offset ) = 0;
242
243
246 virtual IDType MaxID() const = 0;
247
248
251 virtual IDType MinID() const = 0;
252
253
254 virtual ~Collection() = default;
255 Collection( const Collection& ) = delete;
256 Collection( Collection&& ) = delete;
257 Collection& operator=( const Collection& ) = delete;
258 Collection& operator=( Collection&& ) = delete;
259 protected:
260 Collection() = default;
261
262 friend Decorator<Collection_Type>;
263 virtual void SetDecorator( Collection_Type* pCollection_TypeDecorator ) = 0;
264 };
265
266}
Definition Collection.h:30
The base for decorator implementations. Needed as BaseDecorator to combine other decorator implemente...
Definition ObjectIDDecorator.h:27
STL namespace.
Namespace of all the trax track libraries classes and methods.
Definition Collection.h:17
virtual std::shared_ptr< Value_Type > GetActive() const =0
virtual std::shared_ptr< Value_Type > GetLast() const =0
virtual bool IsValid() const noexcept=0
Checks whether the elements in this collection are valid.
virtual IDType MinID() const =0
virtual std::shared_ptr< Value_Type > GetNext(const std::shared_ptr< Value_Type > &pValue_Type) const =0
virtual iterator begin()=0
virtual IDType AddRelaxed(std::shared_ptr< Value_Type > pTraxType)=0
Adds an element to the container and returns its index in the container. Does not throw.
virtual int Take(Collection_Type &collection_Type)=0
Moves all the items from another container to this container.
virtual void PushActive(IDType id)=0
Pushes an element on the activety stack.
virtual bool Remove(Value_Type *pValue_Type, bool zeroIDs=false)=0
Removes an element from this container.
virtual void PopActive()=0
Pops an element from the activity stack.
virtual iterator end()=0
virtual std::shared_ptr< Value_Type > GetPrevious(const std::shared_ptr< Value_Type > &pValue_Type) const =0
virtual int Count() const =0
virtual IDType MaxID() const =0
virtual void Clear()=0
Removes all the elements from this container.
virtual IDType Add(std::shared_ptr< Value_Type > pValue_Type)=0
Adds an element to the container and returns its index in the container.
virtual const char * TypeName() const noexcept=0
virtual void ShiftIDs(int offset)=0
Adds an offset to all ids.
virtual std::shared_ptr< Value_Type > GetFirst() const =0
Type used for IDs in the trax library.
Definition IDType.h:43