writeObjectsBase.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2016-2019 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 "writeObjectsBase.H"
27 #include "Time.H"
28 #include "dictionary.H"
29 
30 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
31 
33 (
34  const wordRe& name
35 )
36 {
37  writeObjectNames_.clear();
38  writeObjectNames_.append(name);
39 }
40 
41 
43 (
44  const wordReList& names
45 )
46 {
47  writeObjectNames_.clear();
48  writeObjectNames_.append(names);
49 }
50 
51 
53 {
54  DynamicList<word> allNames(writeObr_.toc().size());
56  {
58 
59  if (names.size())
60  {
61  allNames.append(names);
62  }
63  else
64  {
66  << "Object " << writeObjectNames_[i] << " not found in "
67  << "database. Available objects:" << nl << writeObr_.sortedToc()
68  << endl;
69  }
70  }
71 
72  return move(allNames);
73 }
74 
75 
77 (
78  const regIOobject& obj
79 )
80 {
81  if (log_) Info << " writing object " << obj.name() << endl;
82 
83  obj.write();
84 }
85 
86 
87 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
88 
90 (
91  const objectRegistry& obr,
92  const Switch& log
93 )
94 :
95  writeObr_(obr),
96  log_(log)
97 {}
98 
99 
100 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
101 
103 {}
104 
105 
106 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
107 
108 const Foam::wordReList&
110 {
111  return writeObjectNames_;
112 }
113 
114 
116 {
117  regExp_ = dict.lookupOrDefault<Switch>("regExp", true);
118 
119  if (regExp_)
120  {
121  dict.lookup("objects") >> writeObjectNames_;
122  }
123  else
124  {
125  const wordList objectNames(dict.lookup("objects"));
127  forAll(objectNames, i)
128  {
130  }
131  }
132 
133  return true;
134 }
135 
136 
138 {
139  wordList names(objectNames());
140 
141  if(!names.empty())
142  {
143  if (!writeObr_.time().writeTime())
144  {
146  }
147 
148  forAll(names, i)
149  {
150  const regIOobject& obj =
152 
153  writeObject(obj);
154  }
155  }
156 
157  return true;
158 }
159 
160 
161 // ************************************************************************* //
virtual bool write()
Write function.
dictionary dict
const objectRegistry & writeObr_
Reference to the region objectRegistry.
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
bool empty() const
Return true if the UList is empty (ie, size() is zero)
Definition: UListI.H:313
const word & name() const
Return name.
Definition: IOobject.H:303
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
wordList names() const
Return the list of names of the IOobjects.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
A simple wrapper around bool so that it can be read as a word: true/false, on/off, yes/no, y/n, t/f, or none/any.
Definition: Switch.H:60
const Type & lookupObject(const word &name) const
Lookup and return the object of the given Type.
void resetWriteObjectNames(const wordReList &names)
Reset the list of object names to be written.
virtual bool writeTimeDict() const
Write time dictionary to the <time>/uniform directory.
Definition: TimeIO.C:506
bool writeTime() const
Return true if this is a write time.
Definition: TimeStateI.H:65
void resetWriteObjectName(const wordRe &name)
Reset the list of object names to be written to a single regular.
const Switch & log_
Reference to the inheriting function object&#39;s log variable.
wordReList writeObjectNames_
Object names requested by the user to be written.
A wordRe is a word, but can also have a regular expression for matching words.
Definition: wordRe.H:74
Switch regExp_
Optional switch for regular expression support.
static const char nl
Definition: Ostream.H:260
const Time & time() const
Return time.
virtual void writeObject(const regIOobject &obj)
Write the requested registered IO object.
const wordReList & writeObjectNames() const
Return const access to the object names requested to be written.
void setSize(const label)
Reset size of List.
Definition: List.C:281
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
#define WarningInFunction
Report a warning using Foam::Warning.
List< Key > sortedToc() const
Return the table of contents as a sorted list.
Definition: HashTable.C:217
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:55
writeObjectsBase(const objectRegistry &obr, const Switch &logRef)
Construct from objectRegistry and inheriting function object.
messageStream Info
virtual wordList objectNames()
Get the list of field names to be written.
List< Key > toc() const
Return the table of contents.
Definition: HashTable.C:202
virtual bool write(const bool write=true) const
Write using setting from DB.
Registry of regIOobjects.
virtual bool read(const dictionary &)
Read the list of objects to be written.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:812