uncollatedFileOperation.H
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) 2017-2025 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 Class
25  Foam::fileOperations::uncollatedFileOperation
26 
27 Description
28  fileOperation that assumes file operations are local.
29 
30 \*---------------------------------------------------------------------------*/
31 
32 #ifndef uncollatedFileOperation_fileOperation_H
33 #define uncollatedFileOperation_fileOperation_H
34 
35 #include "fileOperation.H"
36 
37 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 
39 namespace Foam
40 {
41 namespace fileOperations
42 {
43 
44 /*---------------------------------------------------------------------------*\
45  Class uncollatedFileOperation Declaration
46 \*---------------------------------------------------------------------------*/
47 
49 :
50  public fileOperation
51 {
52  // Private Member Functions
53 
54  //- Search for an object.
55  // globalFile : also check undecomposed case
56  // isFile : true:check for file false:check for directory
57  fileName filePathInfo
58  (
59  const bool globalFile,
60  const bool isFile,
61  const IOobject&
62  ) const;
63 
64 
65 public:
66 
67  //- Runtime type information
68  TypeName("uncollated");
69 
70 
71  // Constructors
72 
73  //- Construct null
74  uncollatedFileOperation(const bool verbose);
75 
76 
77  //- Destructor
78  virtual ~uncollatedFileOperation();
79 
80 
81  // Member Functions
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 checkVariants = true,
96  const bool followLink = true
97  ) const;
98 
99  //- Return the file type: directory, file or link
100  virtual fileType type
101  (
102  const fileName&,
103  const bool checkVariants = true,
104  const bool followLink = true
105  ) const;
106 
107  //- Does the name exist (as directory or file) in the file system?
108  // Optionally enable/disable check for gzip file.
109  virtual bool exists
110  (
111  const fileName&,
112  const bool checkVariants = true,
113  const bool followLink = true
114  ) const;
115 
116  //- Does the name exist as a directory in the file system?
117  virtual bool isDir
118  (
119  const fileName&,
120  const bool followLink = true
121  ) const;
122 
123  //- Does the name exist as a FILE in the file system?
124  // Optionally enable/disable check for gzip file.
125  virtual bool isFile
126  (
127  const fileName&,
128  const bool checkVariants = true,
129  const bool followLink = true
130  ) const;
131 
132  //- Return size of file
133  virtual off_t fileSize
134  (
135  const fileName&,
136  const bool checkVariants = true,
137  const bool followLink = true
138  ) const;
139 
140  //- Return time of last file modification
141  virtual time_t lastModified
142  (
143  const fileName&,
144  const bool checkVariants = true,
145  const bool followLink = true
146  ) const;
147 
148  //- Return time of last file modification
149  virtual double highResLastModified
150  (
151  const fileName&,
152  const bool checkVariants = true,
153  const bool followLink = true
154  ) const;
155 
156  //- Read a directory and return the entries as a string list
157  virtual fileNameList readDir
158  (
159  const fileName&,
160  const fileType = fileType::file,
161  const bool filtergz=true,
162  const bool followLink = true
163  ) const;
164 
165  //- Copy, recursively if necessary, the source to the destination
166  virtual bool cp
167  (
168  const fileName& src,
169  const fileName& dst,
170  const bool followLink = true
171  ) const;
172 
173  //- Create a softlink. dst should not exist. Returns true if
174  // successful.
175  virtual bool ln(const fileName& src, const fileName& dst) const;
176 
177  //- Rename src to dst
178  virtual bool mv
179  (
180  const fileName& src,
181  const fileName& dst,
182  const bool followLink = false
183  ) const;
184 
185  //- Rename to a corresponding backup file
186  // If the backup file already exists, attempt with
187  // "01" .. "99" suffix
188  virtual bool mvBak
189  (
190  const fileName&,
191  const std::string& ext = "bak"
192  ) const;
193 
194  //- Remove a file, returning true if successful otherwise false
195  virtual bool rm(const fileName&) const;
196 
197  //- Remove a directory and its contents
198  virtual bool rmDir(const fileName&) const;
199 
200 
201  // (reg)IOobject functionality
202 
203  //- Search for an object. globalFile : also check undecomposed case
204  virtual fileName filePath
205  (
206  const bool globalFile,
207  const IOobject&
208  ) const;
209 
210  //- Search for a directory. globalFile : also check undecomposed
211  // case
212  virtual fileName dirPath
213  (
214  const bool globalFile,
215  const IOobject&
216  ) const;
217 
218  //- Search directory for objects. Used in IOobjectList.
219  virtual fileNameList readObjects
220  (
221  const objectRegistry& db,
222  const fileName& instance,
223  const fileName& local,
224  word& newInstance
225  ) const;
226 
227  //- Read object header from supplied file
228  virtual bool readHeader
229  (
230  IOobject&,
231  const fileName&,
232  const word& typeName
233  ) const;
234 
235  //- Reads header for regIOobject and returns an ISstream
236  // to read the contents.
238  (
239  regIOobject&,
240  const fileName&,
241  const word& typeName,
242  const bool read = true
243  ) const;
244 
245  //- Top-level read
246  // Format set to ASCII if defaultFormat and file format are ASCII
247  virtual bool read
248  (
249  regIOobject&,
250  const bool masterOnly,
251  const IOstream::streamFormat defaultFormat,
252  const word& typeName
253  ) const;
254 
255  //- Generate an ISstream that reads a file
257  (
258  const fileName& filePath,
261  ) const;
262 
263  //- Generate an Ostream that writes a file
265  (
266  const fileName& filePath,
270  const bool write = true
271  ) const;
272 };
273 
274 
275 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
276 
277 } // End namespace fileOperations
278 } // End namespace Foam
279 
280 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
281 
282 #endif
283 
284 // ************************************************************************* //
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
Version number type.
Definition: IOstream.H:97
static const versionNumber currentVersion
Current version number.
Definition: IOstream.H:203
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:87
compressionType
Enumeration for the format of data in the stream.
Definition: IOstream.H:194
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
A class for handling file names.
Definition: fileName.H:82
fileOperation that assumes file operations are local.
TypeName("uncollated")
Runtime type information.
virtual autoPtr< ISstream > NewIFstream(const fileName &filePath, IOstream::streamFormat format=IOstream::ASCII, IOstream::versionNumber version=IOstream::currentVersion) const
Generate an ISstream that reads a file.
virtual double highResLastModified(const fileName &, const bool checkVariants=true, const bool followLink=true) const
Return time of last file modification.
virtual fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true) const
Return the file type: directory, file or link.
virtual bool isFile(const fileName &, const bool checkVariants=true, const bool followLink=true) const
Does the name exist as a FILE in the file system?
virtual off_t fileSize(const fileName &, const bool checkVariants=true, const bool followLink=true) const
Return size of file.
virtual time_t lastModified(const fileName &, const bool checkVariants=true, const bool followLink=true) const
Return time of last file modification.
virtual bool read(regIOobject &, const bool masterOnly, const IOstream::streamFormat defaultFormat, const word &typeName) const
Top-level read.
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 rmDir(const fileName &) const
Remove a directory and its contents.
virtual bool cp(const fileName &src, const fileName &dst, const bool followLink=true) const
Copy, recursively if necessary, the source to the destination.
virtual bool chMod(const fileName &, const mode_t) const
Set the file mode.
virtual autoPtr< Ostream > NewOFstream(const fileName &filePath, IOstream::streamFormat format=IOstream::ASCII, IOstream::versionNumber version=IOstream::currentVersion, IOstream::compressionType compression=IOstream::UNCOMPRESSED, const bool write=true) const
Generate an Ostream that writes a file.
virtual autoPtr< ISstream > readStream(regIOobject &, const fileName &, const word &typeName, const bool read=true) const
Reads header for regIOobject and returns an ISstream.
virtual bool rm(const fileName &) const
Remove a file, returning true if successful otherwise false.
virtual fileName filePath(const bool globalFile, const IOobject &) const
Search for an object. globalFile : also check undecomposed case.
virtual fileNameList readDir(const fileName &, const fileType=fileType::file, const bool filtergz=true, const bool followLink=true) const
Read a directory and return the entries as a string list.
virtual bool isDir(const fileName &, const bool followLink=true) const
Does the name exist as a directory in the file system?
virtual mode_t mode(const fileName &, const bool checkVariants=true, const bool followLink=true) const
Return the file mode.
virtual bool mkDir(const fileName &, mode_t=0777) const
Make directory.
virtual fileName dirPath(const bool globalFile, const IOobject &) const
Search for a directory. globalFile : also check undecomposed.
uncollatedFileOperation(const bool verbose)
Construct null.
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.
virtual bool exists(const fileName &, const bool checkVariants=true, const bool followLink=true) const
Does the name exist (as directory or file) in the file system?
Registry of regIOobjects.
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:55
A class for handling words, derived from string.
Definition: word.H:62
void write(std::ostream &os, const bool binary, List< floatScalar > &fField)
Write floats ascii or binary.
Namespace for OpenFOAM.
fileType
Enumeration of file types.
Definition: fileName.H:67
word format(conversionProperties.lookup("format"))