CompactListListI.H 5.85 KB
Newer Older
1
2
3
4
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
Mark Olesen's avatar
Mark Olesen committed
5
    \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
     \\/     M anipulation  |
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

    OpenFOAM is free software; you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by the
    Free Software Foundation; either version 2 of the License, or (at your
    option) any later version.

    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    for more details.

    You should have received a copy of the GNU General Public License
    along with OpenFOAM; if not, write to the Free Software Foundation,
    Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

\*---------------------------------------------------------------------------*/

27
28
#include "ListOps.H"
#include "SubList.H"
29
30
31

// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //

32
33
template<class T, class Container>
inline Foam::CompactListList<T, Container>::CompactListList()
34
35
:
    size_(0)
36
37
38
{}


39
40
template<class T, class Container>
inline Foam::CompactListList<T, Container>::CompactListList
41
42
43
44
(
    const label nRows,
    const label nData
)
45
:
46
47
    size_(nRows),
    offsets_(nRows+1, 0),
48
49
50
51
    m_(nData)
{}


52
53
template<class T, class Container>
inline Foam::CompactListList<T, Container>::CompactListList
54
55
56
57
58
59
(
    const label nRows,
    const label nData,
    const T& t
)
:
60
61
    size_(nRows),
    offsets_(nRows+1, 0),
62
63
64
65
    m_(nData, t)
{}


66
67
68
template<class T, class Container>
inline Foam::autoPtr<Foam::CompactListList<T, Container> >
Foam::CompactListList<T, Container>::clone() const
69
{
70
71
72
73
    return autoPtr<CompactListList<T, Container> >
    (
        new CompactListList<T, Container>(*this)
    );
74
75
76
77
78
}


// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //

79
80
81
template<class T, class Container>
inline const Foam::CompactListList<T, Container>&
Foam::CompactListList<T, Container>::null()
82
{
83
    return *reinterpret_cast< CompactListList<T, Container>* >(0);
84
85
86
}


87
88
template<class T, class Container>
inline Foam::label Foam::CompactListList<T, Container>::size() const
89
{
90
    return size_;
91
92
}

93

94
95
template<class T, class Container>
inline bool Foam::CompactListList<T, Container>::empty() const
96
{
97
    return !size_;
98
99
100
}


101
102
103
template<class T, class Container>
inline const Foam::List<Foam::label>&
Foam::CompactListList<T, Container>::offsets() const
104
105
106
107
{
    return offsets_;
}

108

109
110
template<class T, class Container>
inline Foam::List<Foam::label>& Foam::CompactListList<T, Container>::offsets()
111
112
113
114
{
    return offsets_;
}

115

116
117
118
template<class T, class Container>
inline const Foam::List<T>& Foam::CompactListList<T, Container>::m()
const
119
120
121
122
{
    return m_;
}

123

124
125
template<class T, class Container>
inline Foam::List<T>& Foam::CompactListList<T, Container>::m()
126
127
128
129
130
{
    return m_;
}


131
132
template<class T, class Container>
inline Foam::label Foam::CompactListList<T, Container>::index
133
134
135
136
(
    const label i,
    const label j
) const
137
{
138
    return offsets_[i] + j;
139
140
}

141

142
143
144
template<class T, class Container>
inline Foam::label Foam::CompactListList<T, Container>::whichRow(const label i)
const
145
146
147
148
149
{
    if (i < 0 || i >= m_.size())
    {
        FatalErrorIn
        (
150
            "CompactListList<T, Container>::whichRow(const label) const"
151
152
153
154
        )   << "Index " << i << " outside 0.." << m_.size()
            << abort(FatalError);
    }

155
    return findLower(offsets_, i+1);
156
157
}

158

159
160
template<class T, class Container>
inline Foam::label Foam::CompactListList<T, Container>::whichColumn
161
162
163
164
(
    const label row,
    const label i
) const
165
166
167
168
{
    return i - index(row, 0);
}

169

170
171
172
template<class T, class Container>
inline Foam::Xfer<Foam::CompactListList<T, Container> >
Foam::CompactListList<T, Container>::xfer()
173
{
Mark Olesen's avatar
Mark Olesen committed
174
    return xferMove(*this);
175
176
177
}


178
179
template<class T, class Container>
inline void Foam::CompactListList<T, Container>::resize(const label nRows)
180
181
182
183
184
{
    this->setSize(nRows);
}


185
186
template<class T, class Container>
inline void Foam::CompactListList<T, Container>::resize
187
188
189
190
191
192
193
194
195
(
    const label nRows,
    const label nData
)
{
    this->setSize(nRows, nData);
}


196
197
template<class T, class Container>
inline void Foam::CompactListList<T, Container>::resize
198
199
200
201
202
203
204
205
206
207
(
    const label nRows,
    const label nData,
    const T& t
)
{
    this->setSize(nRows, nData, t);
}


208
209
210
211
212
template<class T, class Container>
inline void Foam::CompactListList<T, Container>::resize
(
    const UList<label>& rowSizes
)
213
214
215
216
217
{
    this->setSize(rowSizes);
}


218
219
// * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //

220
221
template<class T, class Container>
inline Foam::UList<T> Foam::CompactListList<T, Container>::operator[]
222
223
224
(
    const label i
)
225
{
226
227
    label start = offsets_[i];
    return UList<T>(&m_[start], offsets_[i+1] - start);
228
229
}

230

231
232
233
template<class T, class Container>
inline const Foam::UList<T>
Foam::CompactListList<T, Container>::operator[]
234
235
236
(
    const label i
) const
237
{
238
    label start = offsets_[i];
239
240
241
242
243
    return UList<T>
    (
        const_cast<T*>(&m_[start]),
        offsets_[i+1] - start
    );
244
245
246
}


247
248
template<class T, class Container>
inline T& Foam::CompactListList<T, Container>::operator()
249
250
251
252
(
    const label i,
    const label j
)
253
254
255
256
{
    return m_[index(i, j)];
}

257

258
259
template<class T, class Container>
inline const T& Foam::CompactListList<T, Container>::operator()
260
261
262
263
264
265
266
267
268
(
    const label i,
    const label j
) const
{
    return m_[index(i, j)];
}


269
270
template<class T, class Container>
inline void Foam::CompactListList<T, Container>::operator=(const T& t)
271
272
273
274
275
276
{
    m_ = t;
}


// ************************************************************************* //