removeRegisteredObject.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2013-2014 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "removeRegisteredObject.H"
27 #include "dictionary.H"
28 #include "Time.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 defineTypeNameAndDebug(removeRegisteredObject, 0);
35 }
36 
37 
38 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
39 
41 (
42  const word& name,
43  const objectRegistry& obr,
44  const dictionary& dict,
45  const bool loadFromFiles
46 )
47 :
48  name_(name),
49  obr_(obr),
50  objectNames_()
51 {
52  read(dict);
53 }
54 
55 
56 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
57 
59 {}
60 
61 
62 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
63 
65 {
66  dict.lookup("objectNames") >> objectNames_;
67 }
68 
69 
71 {
72  forAll(objectNames_, i)
73  {
74  if (obr_.foundObject<regIOobject>(objectNames_[i]))
75  {
76  const regIOobject& obj =
77  obr_.lookupObject<regIOobject>(objectNames_[i]);
78 
79  if (obj.ownedByRegistry())
80  {
81  Info<< type() << " " << name_ << " output:" << nl
82  << " removing object " << obj.name() << nl
83  << endl;
84 
85  const_cast<regIOobject&>(obj).release();
86  delete &obj;
87  }
88  }
89  }
90 }
91 
92 
94 {
95  execute();
96 }
97 
98 
100 {
101  // Do nothing - only valid on execute
102 }
103 
104 
106 {
107  // Do nothing - only valid on execute
108 }
109 
110 
111 // ************************************************************************* //
virtual void timeSet()
Called when time was set at the end of the Time::operator++.
A class for handling words, derived from string.
Definition: word.H:59
messageStream Info
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
virtual void end()
Execute at the final time-loop, currently does nothing.
Namespace for OpenFOAM.
virtual ~removeRegisteredObject()
Destructor.
virtual void execute()
Execute, currently does nothing.
static const char nl
Definition: Ostream.H:260
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
virtual void read(const dictionary &)
Read the removeRegisteredObject data.
#define forAll(list, i)
Definition: UList.H:421
const word & name() const
Return name.
Definition: IOobject.H:260
fileName::Type type(const fileName &)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:589
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:60
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:452
bool ownedByRegistry() const
Is this object owned by the registry?
Definition: regIOobjectI.H:28
virtual void write()
Write the removeRegisteredObject.
Registry of regIOobjects.
bool read(const char *, int32_t &)
Definition: int32IO.C:87
removeRegisteredObject(const removeRegisteredObject &)
Disallow default bitwise copy construct.
defineTypeNameAndDebug(combustionModel, 0)