unwatchedIOdictionary.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2015 OpenFOAM Foundation
9  Copyright (C) 2021 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "unwatchedIOdictionary.H"
30 #include "objectRegistry.H"
31 #include "Pstream.H"
32 #include "Time.H"
33 
34 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
35 
37 (
38  const IOobject& io,
39  const dictionary* fallback
40 )
41 :
42  unwatchedIOdictionary(io, typeName, fallback)
43 {}
44 
45 
47 (
48  const IOobject& io,
49  const dictionary& dict
50 )
51 :
52  unwatchedIOdictionary(io, typeName, &dict)
53 {}
54 
55 
57 (
58  const IOobject& io,
59  const word& wantedType,
60  const dictionary* fallback
61 )
62 :
63  baseIOdictionary(io, fallback)
64 {
65  if (!readHeaderOk(IOstream::ASCII, wantedType) && fallback)
66  {
67  dictionary::operator=(*fallback);
68  }
69 
70  // For if MUST_READ_IF_MODIFIED
71  addWatch();
72 }
73 
74 
76 (
77  const IOobject& io,
78  Istream& is
79 )
80 :
81  baseIOdictionary(io, is)
82 {
83  // Default construct dictionary and read in afterwards
84  // so that if there is some fancy massaging due to a
85  // functionEntry in
86  // the dictionary at least the type information is already complete.
87  is >> *this;
88 
89  // For if MUST_READ_IF_MODIFIED
90  addWatch();
91 }
92 
93 
94 // * * * * * * * * * * * * * * * Members Functions * * * * * * * * * * * * * //
95 
97 {
98  label index = -1;
99 
100  if (readOpt() == MUST_READ_IF_MODIFIED)
101  {
102  index = files_.find(f);
103 
104  if (index == -1)
105  {
106  index = files_.size();
107  files_.append(f);
108  }
109  }
110  return index;
111 }
112 
113 
115 {
116  if (readOpt() == MUST_READ_IF_MODIFIED)
117  {
118  fileName f = filePath();
119  if (f.empty())
120  {
121  // We don't have this file but would like to re-read it.
122  // Possibly if master-only reading mode.
123  f = objectPath();
124  }
125 
126  if (files_.found(f))
127  {
129  << "Object " << objectPath() << " of type " << type()
130  << " already watched" << nl
131  << abort(FatalError);
132  }
133 
134  // If master-only reading only the master will have all dependencies
135  // so scatter these to slaves
136  bool masterOnly =
137  global()
138  && (
141  );
142 
143  if (masterOnly && Pstream::parRun())
144  {
145  Pstream::scatter(files_);
146  }
147 
148  addWatch(f);
149  }
150 }
151 
152 
153 // ************************************************************************* //
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:165
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:63
Foam::fileName
A class for handling file names.
Definition: fileName.H:71
Foam::IOobject::inotifyMaster
@ inotifyMaster
Definition: IOobject.H:200
Foam::IOobject::timeStampMaster
@ timeStampMaster
Definition: IOobject.H:198
objectRegistry.H
Foam::IOobject::fileModificationChecking
static fileCheckTypes fileModificationChecking
Definition: IOobject.H:299
Foam::unwatchedIOdictionary::addWatch
virtual void addWatch()
Definition: unwatchedIOdictionary.C:107
Foam::Pstream::scatter
static void scatter(const List< commsStruct > &comms, T &Value, const int tag, const label comm)
Definition: gatherScatter.C:144
Foam::unwatchedIOdictionary::unwatchedIOdictionary
unwatchedIOdictionary(const IOobject &io, const dictionary *fallback=nullptr)
Definition: unwatchedIOdictionary.C:30
Foam::List::append
void append(const T &val)
Foam::unwatchedIOdictionary
unwatchedIOdictionary is like IOdictionary but stores dependencies as files instead of fileMonitor wa...
Definition: unwatchedIOdictionary.H:49
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:57
Foam::baseIOdictionary
baseIOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO function...
Definition: baseIOdictionary.H:52
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:119
Pstream.H
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:139
Foam::IOobject::readOpt
readOption readOpt() const noexcept
Definition: IOobjectI.H:157
Time.H
Foam::IOstreamOption::ASCII
@ ASCII
"ascii" (normal default)
Definition: IOstreamOption.H:68
FatalErrorInFunction
#define FatalErrorInFunction
Definition: error.H:465
Foam::nl
constexpr char nl
Definition: Ostream.H:424
f
labelList f(nPoints)
Foam::UPstream::parRun
static bool & parRun() noexcept
Definition: UPstream.H:429
Foam::type
fileName::Type type(const fileName &name, const bool followLink=true)
Definition: POSIX.C:717
Foam::dictionary::operator=
void operator=(const dictionary &rhs)
Definition: dictionary.C:874
Foam::IOobject::MUST_READ_IF_MODIFIED
@ MUST_READ_IF_MODIFIED
Definition: IOobject.H:182
Foam::regIOobject::readHeaderOk
bool readHeaderOk(const IOstreamOption::streamFormat fmt, const word &typeName)
Definition: regIOobjectRead.C:32
unwatchedIOdictionary.H