CompactListListI.H 5.18 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
32

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

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


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


template<class T>
53
inline Foam::CompactListList<T>::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
66
    m_(nData, t)
{}


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


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

76
77
78
79
80
81
82
template<class T>
inline const Foam::CompactListList<T>& Foam::CompactListList<T>::null()
{
    return *reinterpret_cast< CompactListList<T>* >(0);
}


83
template<class T>
84
inline Foam::label Foam::CompactListList<T>::size() const
85
{
86
    return size_;
87
88
}

89

90
91
92
template<class T>
inline bool Foam::CompactListList<T>::empty() const
{
93
    return !size_;
94
95
96
}


97
template<class T>
98
inline const Foam::List<Foam::label>& Foam::CompactListList<T>::offsets() const
99
100
101
102
{
    return offsets_;
}

103

104
template<class T>
Mark Olesen's avatar
Mark Olesen committed
105
inline Foam::List<Foam::label>& Foam::CompactListList<T>::offsets()
106
107
108
109
{
    return offsets_;
}

110

111
template<class T>
112
inline const Foam::List<T>& Foam::CompactListList<T>::m() const
113
114
115
116
{
    return m_;
}

117

118
template<class T>
119
inline Foam::List<T>& Foam::CompactListList<T>::m()
120
121
122
123
124
125
{
    return m_;
}


template<class T>
126
127
128
129
130
inline Foam::label Foam::CompactListList<T>::index
(
    const label i,
    const label j
) const
131
{
132
    return offsets_[i] + j;
133
134
}

135

136
template<class T>
137
inline Foam::label Foam::CompactListList<T>::whichRow(const label i) const
138
139
140
141
142
{
    if (i < 0 || i >= m_.size())
    {
        FatalErrorIn
        (
Mark Olesen's avatar
Mark Olesen committed
143
            "CompactListList<T>::whichRow(const label) const"
144
145
146
147
        )   << "Index " << i << " outside 0.." << m_.size()
            << abort(FatalError);
    }

148
    return findLower(offsets_, i+1);
149
150
}

151

152
template<class T>
153
154
155
156
157
inline Foam::label Foam::CompactListList<T>::whichColumn
(
    const label row,
    const label i
) const
158
159
160
161
{
    return i - index(row, 0);
}

162
163

template<class T>
Mark Olesen's avatar
Mark Olesen committed
164
inline Foam::Xfer<Foam::CompactListList<T> > Foam::CompactListList<T>::xfer()
165
{
Mark Olesen's avatar
Mark Olesen committed
166
    return xferMove(*this);
167
168
169
}


170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
template<class T>
inline void Foam::CompactListList<T>::resize(const label nRows)
{
    this->setSize(nRows);
}


template<class T>
inline void Foam::CompactListList<T>::resize
(
    const label nRows,
    const label nData
)
{
    this->setSize(nRows, nData);
}


template<class T>
inline void Foam::CompactListList<T>::resize
(
    const label nRows,
    const label nData,
    const T& t
)
{
    this->setSize(nRows, nData, t);
}


template<class T>
inline void Foam::CompactListList<T>::resize(const UList<label>& rowSizes)
{
    this->setSize(rowSizes);
}


207
208
209
// * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //

template<class T>
210
211
212
213
inline Foam::UList<T> Foam::CompactListList<T>::operator[]
(
    const label i
)
214
{
215
216
217
    //return SubList<T>(m_, offsets_[i+1]-start, start);
    label start = offsets_[i];
    return UList<T>(&m_[start], offsets_[i+1] - start);
218
219
}

220

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


template<class T>
234
235
236
237
238
inline T& Foam::CompactListList<T>::operator()
(
    const label i,
    const label j
)
239
240
241
242
{
    return m_[index(i, j)];
}

243

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


template<class T>
256
inline void Foam::CompactListList<T>::operator=(const T& t)
257
258
259
260
261
262
{
    m_ = t;
}


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