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 | Copyright (C) 2015-2017 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 
82 // * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * * //
83 
85 {}
86 
87 
88 // * * * * * * * * * * * * * * * Members Functions * * * * * * * * * * * * * //
89 
91 {
92  label index = -1;
93 
95  {
96  index = findIndex(files_, f);
97 
98  if (index == -1)
99  {
100  index = files_.size();
101  files_.append(f);
102  }
103  }
104  return index;
105 }
106 
107 
109 {
111  {
112  fileName f = filePath();
113  if (!f.size())
114  {
115  // We don't have this file but would like to re-read it.
116  // Possibly if master-only reading mode.
117  f = objectPath();
118  }
119 
120  if (findIndex(files_, f) != -1)
121  {
122  FatalErrorIn("regIOobject::addWatch()")
123  << "Object " << objectPath() << " of type " << type()
124  << " already watched" << abort(FatalError);
125  }
126 
127  // If master-only reading only the master will have all dependencies
128  // so scatter these to slaves
129  bool masterOnly =
130  global()
131  && (
134  );
135 
136  if (masterOnly && Pstream::parRun())
137  {
138  Pstream::scatter(files_);
139  }
140 
141  addWatch(f);
142  }
143 }
144 
145 
146 // ************************************************************************* //
baseIOdictionary(const IOobject &)
Construct given an IOobject.
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:69
baseIOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO function...
void operator=(const dictionary &)
Definition: dictionary.C:1171
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
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
Is object 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:184
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:208
labelList f(nPoints)
label findIndex(const ListType &, typename ListType::const_reference, const label start=0)
Find first occurence of given element and return index,.
fileName::Type type(const fileName &, const bool followLink=true)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:485
static bool & parRun()
Is this a parallel run?
Definition: UPstream.H:394
virtual fileName filePath() const
Return complete path + object name if the file exists.
readOption readOpt() const
Definition: IOobject.H:353
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:412
#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.