Aeon Engine c550894
AeonGames Open Source Game Engine
Loading...
Searching...
No Matches
Container.hpp
1/*
2Copyright (C) 2018,2025,2026 Rodrigo Jose Hernandez Cordoba
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16#ifndef AEONGAMES_CONTAINER_H
17#define AEONGAMES_CONTAINER_H
18
19#include <vector>
20#include <memory>
21#include <algorithm>
22
23namespace AeonGames
24{
29 template<class T>
31 {
32 public:
39 template <typename... Args>
40 T* Store ( Args... args )
41 {
42 mStorage.emplace_back ( std::make_unique<T> ( args... ) );
43 return mStorage.back().get();
44 }
45
50 T* Store ( std::unique_ptr<T>&& value )
51 {
52 mStorage.emplace_back ( std::move ( value ) );
53 return mStorage.back().get();
54 }
55
60 std::unique_ptr<T> Dispose ( const T* t )
61 {
62 std::unique_ptr<T> result{};
63 auto i = std::find_if ( mStorage.begin(), mStorage.end(), [t] ( const std::unique_ptr<T>& ref )
64 {
65 return t == ref.get();
66 } );
67 if ( i != mStorage.end() )
68 {
69 result = std::move ( *i );
70 mStorage.erase ( std::remove ( i, mStorage.end(), *i ), mStorage.end() );
71 }
72 return result;
73 }
74 private:
75 std::vector<std::unique_ptr<T >> mStorage{};
76 };
77}
78#endif
Owning container that stores uniquely-owned objects of type T.
Definition Container.hpp:31
T * Store(Args... args)
Construct and store a new object in-place.
Definition Container.hpp:40
std::unique_ptr< T > Dispose(const T *t)
Remove an object from the container and return ownership.
Definition Container.hpp:60
T * Store(std::unique_ptr< T > &&value)
Store an existing uniquely-owned object.
Definition Container.hpp:50
<- This is here just for the literals
Definition AABB.hpp:31