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 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "unwatchedIOdictionary.H"
29 #include "objectRegistry.H"
30 #include "Pstream.H"
31 #include "Time.H"
32 
33 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
34 
36 :
38 {
39  readHeaderOk(IOstream::ASCII, typeName);
40 
41  // For if MUST_READ_IF_MODIFIED
42  addWatch();
43 }
44 
45 
47 (
48  const IOobject& io,
49  const dictionary& dict
50 )
51 :
53 {
54  if (!readHeaderOk(IOstream::ASCII, typeName))
55  {
57  }
58 
59  // For if MUST_READ_IF_MODIFIED
60  addWatch();
61 }
62 
63 
65 (
66  const IOobject& io,
67  Istream& is
68 )
69 :
70  baseIOdictionary(io, is)
71 {
72  // Note that we do construct the dictionary null and read in
73  // afterwards
74  // so that if there is some fancy massaging due to a
75  // functionEntry in
76  // the dictionary at least the type information is already complete.
77  is >> *this;
78 
79  // For if MUST_READ_IF_MODIFIED
80  addWatch();
81 }
82 
83 
84 // * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * * //
85 
87 {}
88 
89 
90 // * * * * * * * * * * * * * * * Members Functions * * * * * * * * * * * * * //
91 
93 {
94  label index = -1;
95 
96  if (readOpt() == MUST_READ_IF_MODIFIED)
97  {
98  index = files_.find(f);
99 
100  if (index == -1)
101  {
102  index = files_.size();
103  files_.append(f);
104  }
105  }
106  return index;
107 }
108 
109 
111 {
112  if (readOpt() == MUST_READ_IF_MODIFIED)
113  {
114  fileName f = filePath();
115  if (!f.size())
116  {
117  // We don't have this file but would like to re-read it.
118  // Possibly if master-only reading mode.
119  f = objectPath();
120  }
121 
122  if (files_.found(f))
123  {
125  << "Object " << objectPath() << " of type " << type()
126  << " already watched" << abort(FatalError);
127  }
128 
129  // If master-only reading only the master will have all dependencies
130  // so scatter these to slaves
131  bool masterOnly =
132  global()
133  && (
134  regIOobject::fileModificationChecking == timeStampMaster
135  || regIOobject::fileModificationChecking == inotifyMaster
136  );
137 
138  if (masterOnly && Pstream::parRun())
139  {
140  Pstream::scatter(files_);
141  }
142 
143  addWatch(f);
144  }
145 }
146 
147 
148 // ************************************************************************* //
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:104
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::UPstream::parRun
static bool & parRun()
Test if this a parallel run, or allow modify access.
Definition: UPstream.H:434
objectRegistry.H
Foam::IOobject::fileModificationChecking
static fileCheckTypes fileModificationChecking
Type of file modification checking.
Definition: IOobject.H:211
Foam::unwatchedIOdictionary::addWatch
virtual void addWatch()
Add file watch on object (READ_IF_MODIFIED)
Definition: unwatchedIOdictionary.C:110
Foam::Pstream::scatter
static void scatter(const List< commsStruct > &comms, T &Value, const int tag, const label comm)
Scatter data. Distribute without modification. Reverse of gather.
Definition: gatherScatter.C:150
Foam::regIOobject::readHeaderOk
bool readHeaderOk(const IOstream::streamFormat PstreamFormat, const word &typeName)
Helper: check readOpt flags and read if necessary.
Definition: regIOobjectRead.C:39
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::unwatchedIOdictionary::~unwatchedIOdictionary
virtual ~unwatchedIOdictionary()
Destructor.
Definition: unwatchedIOdictionary.C:86
Foam::baseIOdictionary
baseIOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO function...
Definition: baseIOdictionary.H:57
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:121
Pstream.H
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
Foam::unwatchedIOdictionary::unwatchedIOdictionary
unwatchedIOdictionary(const IOobject &io)
Construct given an IOobject.
Definition: unwatchedIOdictionary.C:35
Time.H
Foam::IOstreamOption::ASCII
"ascii" (normal default)
Definition: IOstreamOption.H:72
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:381
f
labelList f(nPoints)
Foam::type
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:590
Foam::dictionary::operator=
void operator=(const dictionary &rhs)
Copy assignment.
Definition: dictionary.C:948
unwatchedIOdictionary.H