DynamicVector.hpp
Go to the documentation of this file.
1/*
2 Copyright 2013 Statoil ASA.
3
4 This file is part of the Open Porous Media project (OPM).
5
6 OPM is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 OPM is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with OPM. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#ifndef DYNAMICVECTOR_HPP_
21#define DYNAMICVECTOR_HPP_
22
23
24#include <stdexcept>
26
27namespace Opm {
28
29 /*
30 The DynamicVector<T> class is a thin wrapper around
31 std::vector<T> with the following twists:
32
33 - Default-sized to the size of a time map, pre-populated by the default
34 value.
35 */
36
37 template <class T>
39 public:
40 DynamicVector() = default;
41
42 DynamicVector(const TimeMap& timeMap, T defaultValue) :
43 m_data( timeMap.size(), defaultValue )
44 {}
45
46 explicit DynamicVector(const std::vector<T>& data) :
47 m_data(data)
48 {}
49
50 const T& operator[](size_t index) const {
51 return this->m_data.at( index );
52 }
53
54
55 const T& iget(size_t index) const {
56 return (*this)[index];
57 }
58
59 T& operator[](size_t index) {
60 return this->m_data.at( index );
61 }
62
63 void iset(size_t index, T value) {
64 (*this)[index] = std::move( value );
65 }
66
67 bool operator==(const DynamicVector<T>& data) const {
68 return this->m_data == data.m_data;
69 }
70
71 template<class Serializer, bool complexType = true>
72 void serializeOp(Serializer& serializer)
73 {
74 serializer.template vector<T, complexType>(m_data);
75 }
76
77 private:
78 std::vector<T> m_data;
79 };
80}
81
82#endif
int index
Definition: cJSON.h:168
Definition: DynamicVector.hpp:38
DynamicVector(const TimeMap &timeMap, T defaultValue)
Definition: DynamicVector.hpp:42
DynamicVector(const std::vector< T > &data)
Definition: DynamicVector.hpp:46
DynamicVector()=default
bool operator==(const DynamicVector< T > &data) const
Definition: DynamicVector.hpp:67
const T & iget(size_t index) const
Definition: DynamicVector.hpp:55
void serializeOp(Serializer &serializer)
Definition: DynamicVector.hpp:72
T & operator[](size_t index)
Definition: DynamicVector.hpp:59
const T & operator[](size_t index) const
Definition: DynamicVector.hpp:50
void iset(size_t index, T value)
Definition: DynamicVector.hpp:63
Definition: Serializer.hpp:38
Definition: TimeMap.hpp:40
Definition: A.hpp:4
T value(details::expression_node< T > *n)
Definition: exprtk.hpp:12955
static std::string data()
Definition: exprtk.hpp:40022