OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

MeshObject.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "MeshObject.H"
00028 #include "objectRegistry.H"
00029 
00030 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00031 
00032 template<class Mesh, class Type>
00033 Foam::MeshObject<Mesh, Type>::MeshObject(const Mesh& mesh)
00034 :
00035     regIOobject
00036     (
00037         IOobject
00038         (
00039             Type::typeName,
00040             mesh.thisDb().instance(),
00041             mesh.thisDb()
00042         )
00043     ),
00044     mesh_(mesh)
00045 {}
00046 
00047 
00048 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
00049 
00050 template<class Mesh, class Type>
00051 const Type& Foam::MeshObject<Mesh, Type>::New
00052 (
00053     const Mesh& mesh
00054 )
00055 {
00056     if (!mesh.thisDb().objectRegistry::foundObject<Type>(Type::typeName))
00057     {
00058         return store(new Type(mesh));
00059     }
00060     else
00061     {
00062         return mesh.thisDb().objectRegistry::lookupObject<Type>(Type::typeName);
00063     }
00064 }
00065 
00066 
00067 template<class Mesh, class Type>
00068 template<class Data1>
00069 const Type& Foam::MeshObject<Mesh, Type>::New
00070 (
00071     const Mesh& mesh,
00072     const Data1& d
00073 )
00074 {
00075     if (!mesh.thisDb().objectRegistry::foundObject<Type>(Type::typeName))
00076     {
00077         return store(new Type(mesh, d));
00078     }
00079     else
00080     {
00081         return mesh.thisDb().objectRegistry::lookupObject<Type>(Type::typeName);
00082     }
00083 }
00084 
00085 
00086 template<class Mesh, class Type>
00087 template<class Data1, class Data2>
00088 const Type& Foam::MeshObject<Mesh, Type>::New
00089 (
00090     const Mesh& mesh,
00091     const Data1& d1,
00092     const Data2& d2
00093 )
00094 {
00095     if (!mesh.thisDb().objectRegistry::foundObject<Type>(Type::typeName))
00096     {
00097         return store(new Type(mesh, d1, d2));
00098     }
00099     else
00100     {
00101         return mesh.thisDb().objectRegistry::lookupObject<Type>(Type::typeName);
00102     }
00103 }
00104 
00105 
00106 template<class Mesh, class Type>
00107 template<class Data1, class Data2, class Data3>
00108 const Type& Foam::MeshObject<Mesh, Type>::New
00109 (
00110     const Mesh& mesh,
00111     const Data1& d1,
00112     const Data2& d2,
00113     const Data3& d3
00114 )
00115 {
00116     if (!mesh.thisDb().objectRegistry::foundObject<Type>(Type::typeName))
00117     {
00118         return store(new Type(mesh, d1, d2, d3));
00119     }
00120     else
00121     {
00122         return mesh.thisDb().objectRegistry::lookupObject<Type>(Type::typeName);
00123     }
00124 }
00125 
00126 
00127 template<class Mesh, class Type>
00128 template<class Data1, class Data2, class Data3, class Data4>
00129 const Type& Foam::MeshObject<Mesh, Type>::New
00130 (
00131     const Mesh& mesh,
00132     const Data1& d1,
00133     const Data2& d2,
00134     const Data3& d3,
00135     const Data4& d4
00136 )
00137 {
00138     if (!mesh.thisDb().objectRegistry::foundObject<Type>(Type::typeName))
00139     {
00140         return store(new Type(mesh, d1, d2, d3, d4));
00141     }
00142     else
00143     {
00144         return mesh.thisDb().objectRegistry::lookupObject<Type>(Type::typeName);
00145     }
00146 }
00147 
00148 
00149 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * //
00150 
00151 template<class Mesh, class Type>
00152 bool Foam::MeshObject<Mesh, Type>::Delete(const Mesh& mesh)
00153 {
00154     if (mesh.thisDb().objectRegistry::foundObject<Type>(Type::typeName))
00155     {
00156         return mesh.thisDb().checkOut
00157         (
00158             const_cast<Type&>
00159             (
00160                 mesh.thisDb().objectRegistry::lookupObject<Type>
00161                 (
00162                     Type::typeName
00163                 )
00164             )
00165         );
00166     }
00167     else
00168     {
00169         return false;
00170     }
00171 }
00172 
00173 
00174 template<class Mesh, class Type>
00175 Foam::MeshObject<Mesh, Type>::~MeshObject()
00176 {
00177     release();
00178 }
00179 
00180 
00181 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd