systemDict.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) 2021 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 "systemDict.H"
27 #include "IOdictionary.H"
28 #include "Time.H"
29 
30 // * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * * //
31 
33 (
34  const word& dictName,
35  const argList& args,
36  const objectRegistry& ob,
37  const word& regionName
38 )
39 {
40  fileName dictPath = dictName;
41 
42  if (args.optionFound("dict"))
43  {
44  dictPath = args["dict"];
45 
46  if
47  (
48  isDir
49  (
50  dictPath.isAbsolute()
51  ? dictPath
52  : ob.time().globalPath()/dictPath
53  )
54  )
55  {
56  dictPath = dictPath/dictName;
57  }
58  }
59 
60  Info<< "Reading " << dictPath << nl << endl;
61 
62  if (args.optionFound("dict") && !dictPath.isName())
63  {
64  return
65  IOobject
66  (
67  dictPath.isAbsolute()
68  ? dictPath
69  : ob.time().globalPath()/dictPath,
70  ob,
71  IOobject::MUST_READ_IF_MODIFIED,
72  IOobject::NO_WRITE
73  );
74  }
75  else
76  {
77  return
78  IOobject
79  (
80  dictPath,
81  ob.time().system(),
82  regionName == polyMesh::defaultRegion ? word::null : regionName,
83  ob,
84  IOobject::MUST_READ_IF_MODIFIED,
85  IOobject::NO_WRITE
86  );
87  }
88 }
89 
90 
92 (
93  const word& dictName,
94  const argList& args,
95  const objectRegistry& ob,
96  const word& regionName
97 )
98 {
99  return IOdictionary(systemDictIO(dictName, args, ob, regionName));
100 }
101 
102 
103 // ************************************************************************* //
Foam::word regionName
A class for handling file names.
Definition: fileName.H:79
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
bool optionFound(const word &opt) const
Return true if the named option is found.
Definition: argListI.H:114
IOdictionary systemDict(const word &dictName, const argList &args, const objectRegistry &ob, const word &regionName=polyMesh::defaultRegion)
Definition: systemDict.C:92
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:53
bool isName() const
Return true if file name is a name without a path.
Definition: fileName.C:61
bool isAbsolute() const
Return true if file name is absolute.
Definition: fileName.C:73
bool isDir(const fileName &, const bool followLink=true)
Does the name exist as a directory in the file system?
Definition: POSIX.C:539
A class for handling words, derived from string.
Definition: word.H:59
Extract command arguments and options from the supplied argc and argv parameters. ...
Definition: argList.H:102
const word & system() const
Return system name.
Definition: TimePaths.H:113
static const char nl
Definition: Ostream.H:260
const Time & time() const
Return time.
fileName globalPath() const
Return the global path.
Definition: TimePaths.H:133
messageStream Info
IOobject systemDictIO(const word &dictName, const argList &args, const objectRegistry &ob, const word &regionName=polyMesh::defaultRegion)
Definition: systemDict.C:33
Registry of regIOobjects.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:98
const word dictName("noiseDict")