initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / fields / Fields / DynamicField / DynamicFieldI.H
blob8680fbff25a1a81c3562d44f3944cb3f429a95d0
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software; you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "DynamicField.H"
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31 namespace Foam
34 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
36 template<class Type>
37 DynamicField<Type>::DynamicField()
39     Field<Type>(),
40     capacity_(0)
44 template<class Type>
45 DynamicField<Type>::DynamicField(const label size)
47     Field<Type>(size),
48     capacity_(Field<Type>::size())
50     Field<Type>::size(0);
54 template<class Type>
55 inline Foam::DynamicField<Type>::DynamicField
57     const UList<Type>& lst
60     Field<Type>(lst),
61     capacity_(Field<Type>::size())
65 template<class Type>
66 inline Foam::DynamicField<Type>::DynamicField
68     const Xfer<List<Type> >& lst
71     Field<Type>(lst),
72     capacity_(Field<Type>::size())
76 template<class Type>
77 DynamicField<Type>::DynamicField
79     const UList<Type>& mapF,
80     const labelList& mapAddressing
83     Field<Type>(mapF, mapAddressing),
84     capacity_(Field<Type>::size())
88 template<class Type>
89 DynamicField<Type>::DynamicField
91     const UList<Type>& mapF,
92     const labelListList& mapAddressing,
93     const scalarListList& weights
96     Field<Type>(mapF, mapAddressing, weights),
97     capacity_(Field<Type>::size())
101 //- Construct by mapping from the given field
102 template<class Type>
103 DynamicField<Type>::DynamicField
105     const UList<Type>& mapF,
106     const FieldMapper& map
109     DynamicField<Type>(mapF, map),
110     capacity_(Field<Type>::size())
114 template<class Type>
115 DynamicField<Type>::DynamicField(const DynamicField<Type>& f)
117     Field<Type>(f),
118     capacity_(Field<Type>::size())
122 template<class Type>
123 DynamicField<Type>::DynamicField(DynamicField<Type>& f, bool reUse)
125     Field<Type>(f, reUse),
126     capacity_(Field<Type>::size())
130 template<class Type>
131 DynamicField<Type>::DynamicField(const Xfer<DynamicField<Type> >& f)
133     Field<Type>(f),
134     capacity_(Field<Type>::size())
138 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
140 template<class Type>
141 Foam::label DynamicField<Type>::capacity() const
143     return capacity_;
147 template<class Type>
148 void DynamicField<Type>::append(const Type& t)
150     label elemI = Field<Type>::size();
151     setSize(elemI + 1);
153     this->operator[](elemI) = t;
157 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
159 template<class Type>
160 void DynamicField<Type>::operator=(const DynamicField<Type>& rhs)
162     if (this == &rhs)
163     {
164         FatalErrorIn("DynamicField<Type>::operator=(const DynamicField<Type>&)")
165             << "attempted assignment to self"
166             << abort(FatalError);
167     }
169     Field<Type>::operator=(rhs);
170     capacity_ = Field<Type>::size();
174 template<class Type>
175 void DynamicField<Type>::operator=(const UList<Type>& rhs)
177     Field<Type>::operator=(rhs);
178     capacity_ = Field<Type>::size();
182 template<class Type>
183 void DynamicField<Type>::operator=(const tmp<DynamicField>& rhs)
185     if (this == &(rhs()))
186     {
187         FatalErrorIn("DynamicField<Type>::operator=(const tmp<DynamicField>&)")
188             << "attempted assignment to self"
189             << abort(FatalError);
190     }
192     // This is dodgy stuff, don't try it at home.
193     DynamicField* fieldPtr = rhs.ptr();
194     List<Type>::transfer(*fieldPtr);
195     delete fieldPtr;
196     capacity_ = Field<Type>::size();
200 template<class Type>
201 Type& DynamicField<Type>::operator[](const label i)
203     return Field<Type>::operator[](i);
207 template<class Type>
208 const Type& DynamicField<Type>::operator[](const label i) const
210     return Field<Type>::operator[](i);
214 // * * * * * * * * * * * * * * * IOstream Operator * * * * * * * * * * * * * //
217 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
219 } // End namespace Foam
221 // ************************************************************************* //