runlen.hpp
Go to the documentation of this file.
1#ifndef OPM_VERTEQ_RUNLEN_HPP_INCLUDED
2#define OPM_VERTEQ_RUNLEN_HPP_INCLUDED
3
4// Copyright (C) 2013 Uni Research AS
5// This file is licensed under the GNU General Public License v3.0
6
7// forward declaration
8struct UnstructuredGrid;
9
10namespace Opm {
11
59template <typename T>
61protected:
70 int* pos;
71
76 T* data;
77
78public:
91 RunLenView (int num_cols, int* pos_ptr, T* values)
92 // store them locally for later use
93 : num_of_cols (num_cols)
94 , pos (pos_ptr)
95 , data (values) {
96 }
97
104 // copy all fields verbatim
106 , pos (rhs.pos)
107 , data (rhs.data) {
108 }
109
116 T* operator [] (int col) const {
117 return &data [pos [col]];
118 }
119
125 int cols () const {
126 return num_of_cols;
127 }
128
135 int size (int col) const {
136 return pos [col + 1] - pos [col];
137 }
138
149 T& last (int col) const {
150 return data [pos [col + 1] - 1];
151 }
152};
153
163template <typename T>
164struct RunLenData : public RunLenView <T> {
175 RunLenData (int number, int* pos_ptr)
176 // allocate a new vector for the data, containing the needed
177 // number of elements. note that there is only one new
178 // operation is the parameter list, so there is no leakage if
179 // an out-of-memory exception is thrown.
180 : RunLenView <T> (number, pos_ptr, new T [pos_ptr [number]]) {
181 }
182
184 // this member is initialized with data allocated in our ctor
185 delete [] RunLenView <T>::data;
186 }
187};
188
189// shorthands for most used types
192
193// access common run-length encoded matrices in a grid structure
194rlw_int grid_cell_facetag (const UnstructuredGrid& g);
195rlw_int grid_cell_faces (const UnstructuredGrid& g);
196
197} /* namespace Opm */
198
199#endif /* OPM_VERTEQ_RUNLEN_HPP_INCLUDED */
Definition: runlen.hpp:60
T & last(int col) const
Definition: runlen.hpp:149
int * pos
Definition: runlen.hpp:70
T * operator[](int col) const
Definition: runlen.hpp:116
int cols() const
Definition: runlen.hpp:125
int size(int col) const
Definition: runlen.hpp:135
RunLenView(const RunLenView &rhs)
Definition: runlen.hpp:103
T * data
Definition: runlen.hpp:76
RunLenView(int num_cols, int *pos_ptr, T *values)
Definition: runlen.hpp:91
int num_of_cols
Definition: runlen.hpp:69
Definition: opmfwd.hpp:15
rlw_int grid_cell_facetag(const UnstructuredGrid &g)
rlw_int grid_cell_faces(const UnstructuredGrid &g)
const RunLenView< double > rlw_double
Definition: runlen.hpp:191
const RunLenView< int > rlw_int
Definition: runlen.hpp:190
Definition: runlen.hpp:164
~RunLenData()
Definition: runlen.hpp:183
RunLenData(int number, int *pos_ptr)
Definition: runlen.hpp:175