initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / fields / Fields / Field / FieldReuseFunctions.H
blobf99383ba8a131e3a67d13d76e342dfb484fca20b
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 #ifndef FieldReuseFunctions_H
28 #define FieldReuseFunctions_H
30 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 namespace Foam
35 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 template<class TypeR, class Type1>
38 class reuseTmp
40 public:
42     static tmp<Field<TypeR> > New(const tmp<Field<Type1> >& tf1)
43     {
44         return tmp<Field<TypeR> >(new Field<TypeR>(tf1().size()));
45     }
47     static void clear(const tmp<Field<Type1> >& tf1)
48     {
49         tf1.clear();
50     }
54 template<class TypeR>
55 class reuseTmp<TypeR, TypeR>
57 public:
59     static tmp<Field<TypeR> > New(const tmp<Field<TypeR> >& tf1)
60     {
61         if (tf1.isTmp())
62         {
63             return tf1;
64         }
65         else
66         {
67             return tmp<Field<TypeR> >(new Field<TypeR>(tf1().size()));
68         }
69     }
71     static void clear(const tmp<Field<TypeR> >& tf1)
72     {
73         if (tf1.isTmp())
74         {
75             tf1.ptr();
76         }
77     }
81 template<class TypeR, class Type1, class Type12, class Type2>
82 class reuseTmpTmp
84 public:
86     static tmp<Field<TypeR> > New
87     (
88         const tmp<Field<Type1> >& tf1,
89         const tmp<Field<Type2> >& tf2
90     )
91     {
92         return tmp<Field<TypeR> >(new Field<TypeR>(tf1().size()));
93     }
95     static void clear
96     (
97         const tmp<Field<Type1> >& tf1,
98         const tmp<Field<Type2> >& tf2
99     )
100     {
101         tf1.clear();
102         tf2.clear();
103     }
107 template<class TypeR, class Type1, class Type12>
108 class reuseTmpTmp<TypeR, Type1, Type12, TypeR>
110 public:
112     static tmp<Field<TypeR> > New
113     (
114         const tmp<Field<Type1> >& tf1,
115         const tmp<Field<TypeR> >& tf2
116     )
117     {
118         if (tf2.isTmp())
119         {
120             return tf2;
121         }
122         else
123         {
124             return tmp<Field<TypeR> >(new Field<TypeR>(tf1().size()));
125         }
126     }
128     static void clear
129     (
130         const tmp<Field<Type1> >& tf1,
131         const tmp<Field<TypeR> >& tf2
132     )
133     {
134         tf1.clear();
135         if (tf2.isTmp())
136         {
137             tf2.ptr();
138         }
139     }
143 template<class TypeR, class Type2>
144 class reuseTmpTmp<TypeR, TypeR, TypeR, Type2>
146 public:
148     static tmp<Field<TypeR> > New
149     (
150         const tmp<Field<TypeR> >& tf1,
151         const tmp<Field<Type2> >& tf2
152     )
153     {
154         if (tf1.isTmp())
155         {
156             return tf1;
157         }
158         else
159         {
160             return tmp<Field<TypeR> >(new Field<TypeR>(tf1().size()));
161         }
162     }
164     static void clear
165     (
166         const tmp<Field<TypeR> >& tf1,
167         const tmp<Field<Type2> >& tf2
168     )
169     {
170         if (tf1.isTmp())
171         {
172             tf1.ptr();
173         }
174         tf2.clear();
175     }
179 template<class TypeR>
180 class reuseTmpTmp<TypeR, TypeR, TypeR, TypeR>
182 public:
184     static tmp<Field<TypeR> > New
185     (
186         const tmp<Field<TypeR> >& tf1,
187         const tmp<Field<TypeR> >& tf2
188     )
189     {
190         if (tf1.isTmp())
191         {
192             return tf1;
193         }
194         else if (tf2.isTmp())
195         {
196             return tf2;
197         }
198         else
199         {
200             return tmp<Field<TypeR> >(new Field<TypeR>(tf1().size()));
201         }
202     }
204     static void clear
205     (
206         const tmp<Field<TypeR> >& tf1,
207         const tmp<Field<TypeR> >& tf2
208     )
209     {
210         if (tf1.isTmp())
211         {
212             tf1.ptr();
213             tf2.clear();
214         }
215         else if (tf2.isTmp())
216         {
217             tf1.clear();
218             tf2.ptr();
219         }
220     }
224 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
226 } // End namespace Foam
228 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
230 #endif
232 // ************************************************************************* //