IOdictionary.H
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) 2011-2017 OpenFOAM Foundation
9  Copyright (C) 2021-2024 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::IOdictionary
29 
30 Description
31  IOdictionary is derived from dictionary and IOobject to give the dictionary
32  automatic IO functionality via the objectRegistry. To facilitate IO,
33  IOdictionary is provided with a constructor from IOobject and with
34  readData/writeData functions.
35 
36 SourceFiles
37  IOdictionary.C
38 
39 \*---------------------------------------------------------------------------*/
40 
41 #ifndef Foam_IOdictionary_H
42 #define Foam_IOdictionary_H
43 
44 #include "baseIOdictionary.H"
45 
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 
48 namespace Foam
49 {
50 
51 /*---------------------------------------------------------------------------*\
52  Class IOdictionary Declaration
53 \*---------------------------------------------------------------------------*/
54 
55 class IOdictionary
56 :
57  public baseIOdictionary
58 {
59 public:
60 
61  // Constructors
62 
63  //- Construct given an IOobject
64  //- and optional fallback dictionary content
65  // A null dictionary pointer is treated like an empty dictionary.
66  explicit IOdictionary
67  (
68  const IOobject& io,
69  const dictionary* fallback = nullptr
70  );
71 
72  //- Construct given an IOobject
73  //- and fallback dictionary content
74  IOdictionary(const IOobject& io, const dictionary& dict);
75 
76  //- Construct given an IOobject, wanted typeName
77  //- and optional fallback dictionary content
78  // A null dictionary pointer is treated like an empty dictionary.
80  (
81  const IOobject& io,
82  const word& wantedType,
83  const dictionary* fallback = nullptr
84  );
85 
86  //- Construct given an IOobject and Istream
87  IOdictionary(const IOobject& io, Istream& is);
88 
89 
90  // Factory Methods
91 
92  //- Read and return contents, testing for "dictionary" type.
93  //- The IOobject will not be registered
94  static dictionary readContents(const IOobject& io);
95 
96  //- Read and return contents, testing for expected type.
97  //- The IOobject will not be registered
99  (
100  const IOobject& io,
101  const word& wantedType
102  );
103 
104 
105  //- Destructor
106  virtual ~IOdictionary() = default;
107 
108 
109  // Member Functions
110 
111  //- The object is global
112  virtual bool global() const
113  {
114  return true;
115  }
116 
117  //- Return complete path + object name if the file exists
118  //- either in the case/processor or case otherwise null
119  virtual fileName filePath() const
120  {
121  return globalFilePath(type());
122  }
123 };
124 
126 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
127 
128 //- Global file type for IOdictionary
129 template<>
130 struct is_globalIOobject<IOdictionary> : std::true_type {};
131 
132 
133 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
135 } // End namespace Foam
136 
137 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
138 
139 #endif
140 
141 // ************************************************************************* //
virtual ~IOdictionary()=default
Destructor.
dictionary dict
A class for handling file names.
Definition: fileName.H:72
baseIOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO function...
fileName globalFilePath(const word &typeName, const bool search=true) const
Redirect to fileHandler filePath, searching up if in parallel.
Definition: IOobject.C:547
IOdictionary(const IOobject &io, const dictionary *fallback=nullptr)
Construct given an IOobject and optional fallback dictionary content.
Definition: IOdictionary.C:30
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
virtual bool global() const
The object is global.
Definition: IOdictionary.H:125
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
Trait for specifying global vs. local IOobject file types.
Definition: IOobject.H:173
static dictionary readContents(const IOobject &io)
Read and return contents, testing for "dictionary" type. The IOobject will not be registered...
Definition: IOdictionary.C:89
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:50
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: POSIX.C:799
virtual fileName filePath() const
Return complete path + object name if the file exists either in the case/processor or case otherwise ...
Definition: IOdictionary.H:134
A class for handling words, derived from Foam::string.
Definition: word.H:63
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:180
Namespace for OpenFOAM.