unwatchedIOdictionary.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) 2015-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 "unwatchedIOdictionary.H"
27 #include "objectRegistry.H"
28 #include "Pstream.H"
29 #include "Time.H"
30 
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32 
34 :
36 {
37  readHeaderOk(IOstream::ASCII, typeName);
38 
39  // For if MUST_READ_IF_MODIFIED
40  addWatch();
41 }
42 
43 
45 (
46  const IOobject& io,
47  const dictionary& dict
48 )
49 :
50  baseIOdictionary(io, dict)
51 {
52  if (!readHeaderOk(IOstream::ASCII, typeName))
53  {
55  }
56 
57  // For if MUST_READ_IF_MODIFIED
58  addWatch();
59 }
60 
61 
63 (
64  const IOobject& io,
65  Istream& is
66 )
67 :
68  baseIOdictionary(io, is)
69 {
70  // Note that we do construct the dictionary null and read in
71  // afterwards
72  // so that if there is some fancy massaging due to a
73  // functionEntry in
74  // the dictionary at least the type information is already complete.
75  is >> *this;
76 
77  // For if MUST_READ_IF_MODIFIED
78  addWatch();
79 }
80 
81 
83 (
85 )
86 :
87  baseIOdictionary(move(dict)),
88  files_(move(dict.files_))
89 {}
90 
91 
92 // * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * * //
93 
95 {}
96 
97 
98 // * * * * * * * * * * * * * * * Members Functions * * * * * * * * * * * * * //
99 
101 {
102  label index = -1;
103 
105  {
106  index = findIndex(files_, f);
107 
108  if (index == -1)
109  {
110  index = files_.size();
111  files_.append(f);
112  }
113  }
114  return index;
115 }
116 
117 
119 {
121  {
122  fileName f = filePath();
123  if (!f.size())
124  {
125  // We don't have this file but would like to re-read it.
126  // Possibly if master-only reading mode.
127  f = objectPath();
128  }
129 
130  if (findIndex(files_, f) != -1)
131  {
132  FatalErrorIn("regIOobject::addWatch()")
133  << "Object " << objectPath() << " of type " << type()
134  << " already watched" << abort(FatalError);
135  }
136 
137  // If master-only reading only the master will have all dependencies
138  // so scatter these to slaves
139  bool masterOnly =
140  global()
141  && (
144  );
145 
146  if (masterOnly && Pstream::parRun())
147  {
148  Pstream::scatter(files_);
149  }
150 
151  addWatch(f);
152  }
153 }
154 
155 
156 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
157 
159 {
160  baseIOdictionary::operator=(move(rhs));
161  files_ = move(rhs.files_);
162 }
163 
164 
165 // ************************************************************************* //
void operator=(const baseIOdictionary &)
Assignment of other baseIOdictionary&#39;s entries to this.
baseIOdictionary(const IOobject &)
Construct given an IOobject.
unwatchedIOdictionary is like IOdictionary but stores dependencies as files instead of fileMonitor wa...
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
A class for handling file names.
Definition: fileName.H:79
baseIOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO function...
void operator=(const dictionary &)
Definition: dictionary.C:1172
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:163
virtual ~unwatchedIOdictionary()
Destructor.
virtual bool global() const
This object is global.
unwatchedIOdictionary(const IOobject &io)
Construct given an IOobject.
virtual void addWatch()
Add file watch on object (READ_IF_MODIFIED)
void append(const T &)
Append an element at the end of the list.
Definition: ListI.H:177
errorManip< error > abort(error &err)
Definition: errorManip.H:131
static void scatter(const List< commsStruct > &comms, T &Value, const int tag, const label comm)
Scatter data. Distribute without modification. Reverse of gather.
static fileCheckTypes fileModificationChecking
Type of file modification checking.
Definition: IOobject.H:211
labelList f(nPoints)
label findIndex(const ListType &, typename ListType::const_reference, const label start=0)
Find first occurrence of given element and return index,.
static bool & parRun()
Is this a parallel run?
Definition: UPstream.H:399
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
virtual fileName filePath() const
Return complete path + object name if the file exists.
void operator=(unwatchedIOdictionary &&)
Move assignment.
readOption readOpt() const
Definition: IOobject.H:345
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:92
fileName objectPath() const
Return complete path + object name.
Definition: IOobject.H:404
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
bool readHeaderOk(const IOstream::streamFormat PstreamFormat, const word &typeName)
Helper: check readOpt flags and read if necessary.