Loading...
Searching...
No Matches
dummyFileOperation.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) 2023 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
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
26Class
27 Foam::fileOperations::dummyFileOperation
28
29Description
30 Dummy fileOperation, to be used as a placeholder for interfaces
31 taking a reference to a fileOperation.
32 Will mostly behave like a no-op, but at the moment no guarantees
33 of any particular behaviour other than good() returning false.
34
35\*---------------------------------------------------------------------------*/
36
37#ifndef Foam_fileOperations_dummyFileOperation_H
38#define Foam_fileOperations_dummyFileOperation_H
39
40#include "fileOperation.H"
41#include "OSspecific.H"
42
43// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44
45namespace Foam
46{
48{
49
50/*---------------------------------------------------------------------------*\
51 Class dummyFileOperation Declaration
52\*---------------------------------------------------------------------------*/
53
55:
57{
58public:
59
60 //- Runtime type information
61 TypeNameNoDebug("dummy");
62
63
64 // Constructors
65
66 //- Default construct
67 explicit dummyFileOperation(bool verbose = false);
68
69
70 //- Destructor
71 virtual ~dummyFileOperation();
72
73
74 // Member Functions
75
76 //- This fileOperation is not really valid for anything.
77 virtual bool good() const { return false; }
79 //- No managed communicator
80 virtual void storeComm() const {}
81
82
83 // OSSpecific equivalents
84
85 //- Make directory
86 virtual bool mkDir(const fileName&, mode_t=0777) const;
87
88 //- Set the file mode
89 virtual bool chMod(const fileName&, const mode_t) const;
90
91 //- Return the file mode
92 virtual mode_t mode
93 (
94 const fileName&,
95 const bool followLink = true
96 ) const;
97
98 //- Return the file type: DIRECTORY, FILE or SYMLINK
99 virtual fileName::Type type
100 (
101 const fileName&,
102 const bool followLink = true
103 ) const;
104
105 //- Does the name exist (as DIRECTORY or FILE) in the file system?
106 // Optionally enable/disable check for gzip file.
107 virtual bool exists
108 (
109 const fileName&,
110 const bool checkGzip=true,
111 const bool followLink = true
112 ) const;
113
114 //- Does the name exist as a DIRECTORY in the file system?
115 virtual bool isDir
116 (
117 const fileName&,
118 const bool followLink = true
119 ) const;
120
121 //- Does the name exist as a FILE in the file system?
122 // Optionally enable/disable check for gzip file.
123 virtual bool isFile
124 (
125 const fileName&,
126 const bool checkGzip=true,
127 const bool followLink = true
128 ) const;
129
130 //- Return size of file
131 virtual off_t fileSize
132 (
133 const fileName&,
134 const bool followLink = true
135 ) const;
136
137 //- Return time of last file modification
138 virtual time_t lastModified
139 (
140 const fileName&,
141 const bool followLink = true
142 ) const;
143
144 //- Return time of last file modification
145 virtual double highResLastModified
146 (
147 const fileName&,
148 const bool followLink = true
149 ) const;
150
151 //- Read a directory and return the entries as a string list
152 virtual fileNameList readDir
153 (
154 const fileName&,
156 const bool filtergz=true,
157 const bool followLink = true
158 ) const;
159
160 //- Copy, recursively if necessary, the source to the destination
161 virtual bool cp
162 (
163 const fileName& src,
164 const fileName& dst,
165 const bool followLink = true
166 ) const;
167
168 //- Create a softlink. dst should not exist. Returns true if
169 // successful.
170 virtual bool ln(const fileName& src, const fileName& dst) const;
171
172 //- Rename src to dst
173 virtual bool mv
174 (
175 const fileName& src,
176 const fileName& dst,
177 const bool followLink = false
178 ) const;
179
180 //- Rename to a corresponding backup file
181 // If the backup file already exists, attempt with
182 // "01" .. "99" suffix
183 virtual bool mvBak
184 (
185 const fileName&,
186 const std::string& ext = "bak"
187 ) const;
188
189 //- Remove a file, returning true if successful otherwise false
190 virtual bool rm(const fileName&) const;
191
192 //- Remove a directory and its contents
193 // \param dir the directory to remove
194 // \param silent do not report missing directory
195 // \param emptyOnly only remove empty directories (recursive)
196 virtual bool rmDir
197 (
198 const fileName& dir,
199 const bool silent = false,
200 const bool emptyOnly = false
201 ) const;
202
203
204 // (reg)IOobject functionality
205
206 //- Search for an object
207 virtual fileName filePath
208 (
210 const bool checkGlobal,
211 const IOobject& io,
213 const word& typeName,
214 const bool search
215 ) const;
216
217 //- Search for a directory
218 virtual fileName dirPath
219 (
221 const bool checkGlobal,
222 const IOobject& io,
223 const bool search
224 ) const;
225
226 //- Search directory for objects. Used in IOobjectList.
228 (
229 const objectRegistry& db,
230 const fileName& instance,
231 const fileName& local,
232 word& newInstance
233 ) const;
234
235 //- Read object header from supplied file
236 virtual bool readHeader
237 (
238 IOobject&,
239 const fileName&,
240 const word& typeName
241 ) const;
242
243 //- Reads header for regIOobject and returns an ISstream
244 //- to read the contents.
246 (
248 const fileName&,
249 const word& typeName,
250 const bool readOnProc = true
251 ) const;
252
253 //- Top-level read
254 virtual bool read
255 (
257 const bool masterOnly,
259 const word& typeName
260 ) const;
261
262 //- Generate an ISstream that reads a file
263 virtual autoPtr<ISstream> NewIFstream(const fileName&) const;
264
265 //- Generate an OSstream that writes a file
267 (
268 const fileName& pathname,
269 IOstreamOption streamOpt = IOstreamOption(),
270 const bool writeOnProc = true
271 ) const;
272
273 //- Generate an OSstream that writes a file
275 (
277 const fileName& pathname,
278 IOstreamOption streamOpt = IOstreamOption(),
279 const bool writeOnProc = true
280 ) const;
281};
282
283
284// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
285
286} // End namespace fileOperations
287} // End namespace Foam
288
289// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
290
291#endif
292
293// ************************************************************************* //
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition IOobject.H:191
A simple container for options an IOstream can normally have.
streamFormat
Data format (ascii | binary | coherent).
atomicType
Atomic operations (output).
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition autoPtr.H:65
A class for handling file names.
Definition fileName.H:75
Type
Enumerations to handle directory entry types.
Definition fileName.H:82
@ FILE
A regular file.
Definition fileName.H:84
fileOperation(const label comm, const labelUList &ioRanks=labelUList::null(), const bool distributedRoots=false)
Construct from communicator, optionally with specified io-ranks and/or distributed roots.
virtual double highResLastModified(const fileName &, const bool followLink=true) const
Return time of last file modification.
virtual autoPtr< OSstream > NewOFstream(const fileName &pathname, IOstreamOption streamOpt=IOstreamOption(), const bool writeOnProc=true) const
Generate an OSstream that writes a file.
virtual bool rmDir(const fileName &dir, const bool silent=false, const bool emptyOnly=false) const
Remove a directory and its contents.
virtual mode_t mode(const fileName &, const bool followLink=true) const
Return the file mode.
virtual autoPtr< ISstream > readStream(regIOobject &, const fileName &, const word &typeName, const bool readOnProc=true) const
Reads header for regIOobject and returns an ISstream to read the contents.
dummyFileOperation(bool verbose=false)
Default construct.
virtual fileNameList readDir(const fileName &, const fileName::Type=fileName::FILE, const bool filtergz=true, const bool followLink=true) const
Read a directory and return the entries as a string list.
TypeNameNoDebug("dummy")
Runtime type information.
virtual bool readHeader(IOobject &, const fileName &, const word &typeName) const
Read object header from supplied file.
virtual bool mvBak(const fileName &, const std::string &ext="bak") const
Rename to a corresponding backup file.
virtual fileNameList readObjects(const objectRegistry &db, const fileName &instance, const fileName &local, word &newInstance) const
Search directory for objects. Used in IOobjectList.
virtual bool read(regIOobject &, const bool masterOnly, const IOstreamOption::streamFormat format, const word &typeName) const
Top-level read.
virtual time_t lastModified(const fileName &, const bool followLink=true) const
Return time of last file modification.
virtual fileName dirPath(const bool checkGlobal, const IOobject &io, const bool search) const
Search for a directory.
virtual bool chMod(const fileName &, const mode_t) const
Set the file mode.
virtual bool good() const
This fileOperation is not really valid for anything.
virtual off_t fileSize(const fileName &, const bool followLink=true) const
Return size of file.
virtual bool exists(const fileName &, const bool checkGzip=true, const bool followLink=true) const
Does the name exist (as DIRECTORY or FILE) in the file system?
virtual bool rm(const fileName &) const
Remove a file, returning true if successful otherwise false.
virtual autoPtr< ISstream > NewIFstream(const fileName &) const
Generate an ISstream that reads a file.
virtual bool isFile(const fileName &, const bool checkGzip=true, const bool followLink=true) const
Does the name exist as a FILE in the file system?
virtual void storeComm() const
No managed communicator.
virtual bool isDir(const fileName &, const bool followLink=true) const
Does the name exist as a DIRECTORY in the file system?
virtual fileName filePath(const bool checkGlobal, const IOobject &io, const word &typeName, const bool search) const
Search for an object.
virtual bool mkDir(const fileName &, mode_t=0777) const
Make directory.
virtual fileName::Type type(const fileName &, const bool followLink=true) const
Return the file type: DIRECTORY, FILE or SYMLINK.
virtual bool mv(const fileName &src, const fileName &dst, const bool followLink=false) const
Rename src to dst.
virtual bool ln(const fileName &src, const fileName &dst) const
Create a softlink. dst should not exist. Returns true if.
Registry of regIOobjects.
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition regIOobject.H:71
A class for handling words, derived from Foam::string.
Definition word.H:66
bool local
Definition EEqn.H:20
const auto & io
Namespace for implementations of a fileOperation.
Definition regIOobject.H:60
Namespace for OpenFOAM.
List< fileName > fileNameList
List of fileName.
const word GlobalIOList< Tuple2< scalar, vector > >::typeName("scalarVectorTable")
fileName search(const word &file, const fileName &directory)
Recursively search the given directory for the file.
Definition fileName.C:642
word format(conversionProperties.get< word >("format"))
const volScalarField & cp
#define TypeNameNoDebug(TypeNameString)
Declare a ClassNameNoDebug() with extra virtual type info.
Definition typeInfo.H:61