PtrListI.H 4.43 KB
Newer Older
1
2
3
4
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
OpenFOAM bot's avatar
OpenFOAM bot committed
5
    \\  /    A nd           | www.openfoam.com
OpenFOAM bot's avatar
OpenFOAM bot committed
6
7
     \\/     M anipulation  |
-------------------------------------------------------------------------------
OpenFOAM bot's avatar
OpenFOAM bot committed
8
9
    Copyright (C) 2011-2016 OpenFOAM Foundation
    Copyright (C) 2018-2019 OpenCFD Ltd.
10
11
12
13
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

14
15
16
17
    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 3 of the License, or
    (at your option) any later version.
18
19
20
21
22
23
24

    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
25
    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
26
27
28
29
30
31

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

#include "autoPtr.H"
#include "tmp.H"

32
33
34
35
36
// * * * * * * * * * * * * Protected Member Functions  * * * * * * * * * * * //

template<class T>
inline void Foam::PtrList<T>::free()
{
37
    (this->ptrs_).free(); // free old pointers
38
39
40
}


Mark Olesen's avatar
Mark Olesen committed
41
// * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * * //
42

43
44
45
46
47
48
49
template<class T>
inline constexpr Foam::PtrList<T>::PtrList() noexcept
:
    UPtrList<T>()
{}


50
template<class T>
51
52
53
54
55
56
57
58
inline Foam::PtrList<T>::PtrList(const label len)
:
    UPtrList<T>(len)
{}


template<class T>
inline Foam::PtrList<T>::PtrList(const PtrList<T>& list)
Mark Olesen's avatar
Mark Olesen committed
59
:
60
    UPtrList<T>(list.ptrs_.clone())
Mark Olesen's avatar
Mark Olesen committed
61
{}
62
63


mattijs's avatar
mattijs committed
64
template<class T>
65
inline Foam::PtrList<T>::PtrList(PtrList<T>&& list)
Mark Olesen's avatar
Mark Olesen committed
66
:
67
    UPtrList<T>(std::move(list))
Mark Olesen's avatar
Mark Olesen committed
68
69
70
{}


71
72
73
74
75
76
77
78
79
80
81
82
83
84
template<class T>
inline Foam::PtrList<T>::PtrList(UList<T*>& list)
:
    UPtrList<T>(list.size())
{
    // Take ownership of the pointer
    forAll(list, i)
    {
        set(i, list[i]);
        list[i] = nullptr;
    }
}


85
86
87
88
89
90
91
92
93
94
95
96
template<class T>
template<class CloneArg>
inline Foam::PtrList<T>::PtrList
(
    const PtrList<T>& list,
    const CloneArg& cloneArg
)
:
    UPtrList<T>(list.clone(cloneArg)())
{}


Mark Olesen's avatar
Mark Olesen committed
97
98
// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //

99
100
101
template<class T>
inline void Foam::PtrList<T>::clear()
{
102
    (this->ptrs_).free(); // free old pointers
103
104
105
106
    UPtrList<T>::clear();
}


Mark Olesen's avatar
Mark Olesen committed
107
template<class T>
108
inline void Foam::PtrList<T>::setSize(const label newLen)
mattijs's avatar
mattijs committed
109
{
110
    this->resize(newLen);
mattijs's avatar
mattijs committed
111
112
113
114
}


template<class T>
115
inline void Foam::PtrList<T>::append(T* ptr)
mattijs's avatar
mattijs committed
116
{
117
118
119
120
121
122
123
    UPtrList<T>::append(ptr);
}


template<class T>
inline void Foam::PtrList<T>::append(autoPtr<T>& aptr)
{
124
    UPtrList<T>::append(aptr.release());
125
126
127
128
129
130
}


template<class T>
inline void Foam::PtrList<T>::append(autoPtr<T>&& aptr)
{
131
    UPtrList<T>::append(aptr.release());
mattijs's avatar
mattijs committed
132
133
134
135
}


template<class T>
Mark Olesen's avatar
Mark Olesen committed
136
inline void Foam::PtrList<T>::append(const tmp<T>& tptr)
mattijs's avatar
mattijs committed
137
{
138
    UPtrList<T>::append(tptr.ptr());
mattijs's avatar
mattijs committed
139
140
141
}


142
template<class T>
143
inline const T* Foam::PtrList<T>::set(const label i) const
144
{
145
    return UPtrList<T>::set(i);
146
147
148
149
}


template<class T>
150
inline Foam::autoPtr<T> Foam::PtrList<T>::set(const label i, T* ptr)
151
{
152
    return autoPtr<T>(UPtrList<T>::set(i, ptr));
153
154
155
156
}


template<class T>
157
inline Foam::autoPtr<T> Foam::PtrList<T>::set(const label i, autoPtr<T>& aptr)
158
{
159
    return set(i, aptr.release());
160
161
162
163
}


template<class T>
164
inline Foam::autoPtr<T> Foam::PtrList<T>::set(const label i, autoPtr<T>&& aptr)
165
166
167
168
169
170
{
    return set(i, aptr.release());
}


template<class T>
171
inline Foam::autoPtr<T> Foam::PtrList<T>::set(const label i, const tmp<T>& tptr)
172
{
173
    return set(i, tptr.ptr());
Mark Olesen's avatar
Mark Olesen committed
174
175
176
}


177
178
179
180
181
182
183
184
185
186
187
188
template<class T>
inline Foam::autoPtr<T> Foam::PtrList<T>::release(const label i)
{
    if (i < 0 || i >= this->size())
    {
        return nullptr;
    }

    return autoPtr<T>(UPtrList<T>::set(i, nullptr));
}


Mark Olesen's avatar
Mark Olesen committed
189
template<class T>
190
inline void Foam::PtrList<T>::transfer(PtrList<T>& list)
Mark Olesen's avatar
Mark Olesen committed
191
{
192
    (this->ptrs_).free(); // free old pointers
193
    UPtrList<T>::transfer(list);
194
195
196
}


Mark Olesen's avatar
Mark Olesen committed
197
198
199
// * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //

template<class T>
200
inline void Foam::PtrList<T>::operator=(PtrList<T>&& list)
Mark Olesen's avatar
Mark Olesen committed
201
{
202
    this->transfer(list);
Mark Olesen's avatar
Mark Olesen committed
203
204
205
}


206
// ************************************************************************* //