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-2020 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 fileOperations_uncollatedFileOperation_H
33 #define fileOperations_uncollatedFileOperation_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  // checkGlobal : also check undecomposed case
56  // isFile : true:check for file false:check for directory
57  fileName filePathInfo
58  (
59  const bool checkGlobal,
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. checkGlobal : also check undecomposed case
204  virtual fileName filePath
205  (
206  const bool checkGlobal,
207  const IOobject&,
208  const word& typeName
209  ) const;
210 
211  //- Search for a directory. checkGlobal : also check undecomposed
212  // case
213  virtual fileName dirPath
214  (
215  const bool checkGlobal,
216  const IOobject&
217  ) const;
218 
219  //- Search directory for objects. Used in IOobjectList.
220  virtual fileNameList readObjects
221  (
222  const objectRegistry& db,
223  const fileName& instance,
224  const fileName& local,
225  word& newInstance
226  ) const;
227 
228  //- Read object header from supplied file
229  virtual bool readHeader
230  (
231  IOobject&,
232  const fileName&,
233  const word& typeName
234  ) const;
235 
236  //- Reads header for regIOobject and returns an ISstream
237  // to read the contents.
239  (
240  regIOobject&,
241  const fileName&,
242  const word& typeName,
243  const bool read = true
244  ) const;
245 
246  //- Top-level read
247  // Format set to ASCII if defaultFormat and file format are ASCII
248  virtual bool read
249  (
250  regIOobject&,
251  const bool masterOnly,
252  const IOstream::streamFormat defaultFormat,
253  const word& typeName
254  ) const;
255 
256  //- Generate an ISstream that reads a file
258  (
259  const fileName& filePath,
262  ) const;
263 
264  //- Generate an Ostream that writes a file
266  (
267  const fileName& filePath,
271  const bool write = true
272  ) const;
273 };
274 
275 
276 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
277 
278 } // End namespace fileOperations
279 } // End namespace Foam
280 
281 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
282 
283 #endif
284 
285 // ************************************************************************* //
A class for handling file names.
Definition: fileName.H:79
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 mv(const fileName &src, const fileName &dst, const bool followLink=false) const
Rename src to dst.
virtual bool chMod(const fileName &, const mode_t) const
Set the file mode.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
virtual double highResLastModified(const fileName &, const bool checkVariants=true, const bool followLink=true) const
Return time of last file modification.
virtual off_t fileSize(const fileName &, const bool checkVariants=true, const bool followLink=true) const
Return size of file.
virtual bool readHeader(IOobject &, const fileName &, const word &typeName) const
Read object header from supplied file.
word format(conversionProperties.lookup("format"))
virtual bool mkDir(const fileName &, mode_t=0777) const
Make directory.
virtual fileName filePath(const bool checkGlobal, const IOobject &, const word &typeName) const
Search for an object. checkGlobal : also check undecomposed case.
virtual fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true) const
Return the file type: directory, file or link.
fileOperation that assumes file operations are local.
virtual bool rmDir(const fileName &) const
Remove a directory and its contents.
TypeName("uncollated")
Runtime type information.
virtual autoPtr< ISstream > readStream(regIOobject &, const fileName &, const word &typeName, const bool read=true) const
Reads header for regIOobject and returns an ISstream.
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 bool read(regIOobject &, const bool masterOnly, const IOstream::streamFormat defaultFormat, const word &typeName) const
Top-level read.
virtual bool isDir(const fileName &, const bool followLink=true) const
Does the name exist as a directory in the file system?
A class for handling words, derived from string.
Definition: word.H:59
virtual bool cp(const fileName &src, const fileName &dst, const bool followLink=true) const
Copy, recursively if necessary, the source to the destination.
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:86
void write(std::ostream &os, const bool binary, List< floatScalar > &fField)
Write floats ascii or binary.
virtual fileName dirPath(const bool checkGlobal, const IOobject &) const
Search for a directory. checkGlobal : also check undecomposed.
fileType
Enumeration of file types.
Definition: fileName.H:66
virtual bool rm(const fileName &) const
Remove a file, returning true if successful otherwise false.
compressionType
Enumeration for the format of data in the stream.
Definition: IOstream.H:193
virtual bool ln(const fileName &src, const fileName &dst) const
Create a softlink. dst should not exist. Returns true if.
virtual time_t lastModified(const fileName &, const bool checkVariants=true, const bool followLink=true) const
Return time of last file modification.
uncollatedFileOperation(const bool verbose)
Construct null.
virtual mode_t mode(const fileName &, const bool checkVariants=true, const bool followLink=true) const
Return the file mode.
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?
virtual bool mvBak(const fileName &, const std::string &ext="bak") const
Rename to a corresponding backup file.
static const versionNumber currentVersion
Current version number.
Definition: IOstream.H:203
virtual fileNameList readObjects(const objectRegistry &db, const fileName &instance, const fileName &local, word &newInstance) const
Search directory for objects. Used in IOobjectList.
Version number type.
Definition: IOstream.H:96
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:52
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
Registry of regIOobjects.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:92
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?
Namespace for OpenFOAM.
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.