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