writeRegisteredObject.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) 2011-2013 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 "writeRegisteredObject.H"
27 #include "dictionary.H"
28 #include "Time.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 defineTypeNameAndDebug(writeRegisteredObject, 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  exclusiveWriting_(false),
50  obr_(obr),
51  objectNames_()
52 {
53  read(dict);
54 }
55 
56 
57 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
58 
60 {}
61 
62 
63 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
64 
66 {
67  dict.lookup("objectNames") >> objectNames_;
68  dict.readIfPresent("exclusiveWriting", exclusiveWriting_);
69 }
70 
71 
73 {
74  // Do nothing - only valid on write
75 }
76 
77 
79 {
80  // Do nothing - only valid on write
81 }
82 
83 
85 {
86  // Do nothing - only valid on write
87 }
88 
89 
91 {
92  Info<< type() << " " << name_ << " output:" << nl;
93 
94  DynamicList<word> allNames(obr_.toc().size());
95  forAll(objectNames_, i)
96  {
97  wordList names(obr_.names<regIOobject>(objectNames_[i]));
98 
99  if (names.size())
100  {
101  allNames.append(names);
102  }
103  else
104  {
105  WarningIn("Foam::writeRegisteredObject::write()")
106  << "Object " << objectNames_[i] << " not found in "
107  << "database. Available objects:" << nl << obr_.sortedToc()
108  << endl;
109  }
110  }
111 
112  forAll(allNames, i)
113  {
114  regIOobject& obj =
115  const_cast<regIOobject&>
116  (
117  obr_.lookupObject<regIOobject>(allNames[i])
118  );
119 
120  if (exclusiveWriting_)
121  {
122  // Switch off automatic writing to prevent double write
124  }
125 
126  Info<< " writing object " << obj.name() << nl << endl;
127 
128  obj.write();
129  }
130 }
131 
132 
133 // ************************************************************************* //
virtual ~writeRegisteredObject()
Destructor.
virtual void write()
Write the writeRegisteredObject.
writeRegisteredObject(const writeRegisteredObject &)
Disallow default bitwise copy construct.
A class for handling words, derived from string.
Definition: word.H:59
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
messageStream Info
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
virtual void read(const dictionary &)
Read the writeRegisteredObject data.
Namespace for OpenFOAM.
virtual bool write() const
Write using setting from DB.
static const char nl
Definition: Ostream.H:260
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
#define WarningIn(functionName)
Report a warning using Foam::Warning.
#define forAll(list, i)
Definition: UList.H:421
writeOption writeOpt() const
Definition: IOobject.H:314
virtual void timeSet()
Called when time was set at the end of the Time::operator++.
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
Registry of regIOobjects.
bool readIfPresent(const word &, T &, bool recursive=false, bool patternMatch=true) const
Find an entry if present, and assign to T.
bool read(const char *, int32_t &)
Definition: int32IO.C:87
virtual void end()
Execute at the final time-loop, currently does nothing.
virtual void execute()
Execute, currently does nothing.
defineTypeNameAndDebug(combustionModel, 0)