OpenLB 1.7
Loading...
Searching...
No Matches
container.h
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2021 Nicolas Hafen, Mathias J. Krause
4 * E-mail contact: info@openlb.net
5 * The most recent release of OpenLB can be downloaded at
6 * <http://www.openlb.net/>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program; if not, write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22*/
23
24#ifndef CONTAINER_H
25#define CONTAINER_H
26
27namespace olb {
28
40// *INDENT-OFF*
41
42
43template<typename T, typename DESCRIPTOR, typename FIELD_ARRAY_TYPE>
45private:
46 FIELD_ARRAY_TYPE _data;
47 using size_type = std::size_t;
49 size_type _size;
50public:
52 _data(FIELD_ARRAY_TYPE(size_type(0))),_size(size_type(0)) { }
53
54 Container( size_type count ):
55 _data(FIELD_ARRAY_TYPE(count)),_size(count) { }
56
57
59
60 constexpr auto& at(); //TODO: implement
61
62 FIELD_ARRAY_TYPE& data(){ return _data; }
63
65
66 constexpr bool empty(); //TODO: implement
67
68 constexpr size_type size(){ return _size;}
69
70 constexpr size_type max_size(); //TODO: implement
71
72 constexpr void reserve( size_type new_capacity ); //TODO: implement
73
74 constexpr size_type capacity(){ return _data.count(); }
75
76 constexpr void shrink_to_fit(){ _data.resize(_size); }
77
79
80 constexpr void clear(); //TODO: implement
81
82 constexpr void erase(size_type i){ //TODO: own prototype (check common!)
83 _data.swap(i, _size-1);
84 _size--;
85 }
86
87 constexpr void push_back(){
88 if ( this->capacity()==this->size() ){
89 size_type new_capacity = 2*this->capacity();
90 if (this->capacity()==0){ new_capacity=1; }
91 this->resize( new_capacity );
92 }
93 _size++;
94 }
95
96 template<typename COMMUNICATABLE>
97 void push_back( std::uint8_t* buffer ){
98 push_back();
99 const std::vector<unsigned int> indices{(static_cast<unsigned int>(_size)-1)};
100 COMMUNICATABLE(_data).deserialize(indices, buffer);
101 }
102
103 template<typename INTERFACE>
104 void push_back( INTERFACE& interface ){
105 const std::vector<unsigned int> indices{static_cast<unsigned int>(interface.getId())};
106 auto communicatable = interface.getCommunicatable();
107 int serialSize = communicatable.size(indices);
108 std::shared_ptr<std::uint8_t[]> buffer(new std::uint8_t[serialSize]{ });
109 communicatable.serialize(indices, buffer.get());
110 push_back<decltype(communicatable)>( buffer.get() );
111 }
112
113 constexpr void pop_back(){ _size--; }
114
115 void resize( size_type new_capacity ){ _data.resize(new_capacity); }
116
117 void swapElements(size_type i, size_type j)
118 {
119 _data.swap(i, j);
120 }
121
122 constexpr size_type getExtent(){ return _size; } //Analogy to lattice type (necessary for generic iteration)
123
124};
125
126
127
128// *INDENT-ON*
129
130
131}
132
133#endif
Container is a std::vector inspired data wrapper that allows for simple content manipulation of its o...
Definition container.h:44
void resize(size_type new_capacity)
Definition container.h:115
constexpr bool empty()
constexpr auto & at()
constexpr void shrink_to_fit()
Definition container.h:76
constexpr size_type capacity()
Definition container.h:74
constexpr void erase(size_type i)
Definition container.h:82
constexpr size_type max_size()
constexpr void clear()
void swapElements(size_type i, size_type j)
Definition container.h:117
void push_back(INTERFACE &interface)
Definition container.h:104
constexpr void push_back()
Definition container.h:87
void push_back(std::uint8_t *buffer)
Definition container.h:97
FIELD_ARRAY_TYPE & data()
Definition container.h:62
Container(size_type count)
Definition container.h:54
constexpr size_type size()
Definition container.h:68
constexpr size_type getExtent()
Definition container.h:122
constexpr void reserve(size_type new_capacity)
constexpr void pop_back()
Definition container.h:113
Top level namespace for all of OpenLB.