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-2019 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 #include "OSspecific.H"
37 
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39 
40 namespace Foam
41 {
42 namespace fileOperations
43 {
44 
45 /*---------------------------------------------------------------------------*\
46  Class uncollatedFileOperation Declaration
47 \*---------------------------------------------------------------------------*/
48 
50 :
51  public fileOperation
52 {
53  // Private Member Functions
54 
55  //- Search for an object.
56  // checkGlobal : also check undecomposed case
57  // isFile : true:check for file false:check for directory
58  fileName filePathInfo
59  (
60  const bool checkGlobal,
61  const bool isFile,
62  const IOobject&
63  ) const;
64 
65 
66 public:
67 
68  //- Runtime type information
69  TypeName("uncollated");
70 
71 
72  // Constructors
73 
74  //- Construct null
75  uncollatedFileOperation(const bool verbose);
76 
77 
78  //- Destructor
79  virtual ~uncollatedFileOperation();
80 
81 
82  // Member Functions
83 
84  // OSSpecific equivalents
85 
86  //- Make directory
87  virtual bool mkDir(const fileName&, mode_t=0777) const;
88 
89  //- Set the file mode
90  virtual bool chMod(const fileName&, const mode_t) const;
91 
92  //- Return the file mode
93  virtual mode_t mode
94  (
95  const fileName&,
96  const bool checkVariants = true,
97  const bool followLink = true
98  ) const;
99 
100  //- Return the file type: directory, file or link
101  virtual fileType type
102  (
103  const fileName&,
104  const bool checkVariants = true,
105  const bool followLink = true
106  ) const;
107 
108  //- Does the name exist (as directory or file) in the file system?
109  // Optionally enable/disable check for gzip file.
110  virtual bool exists
111  (
112  const fileName&,
113  const bool checkVariants = true,
114  const bool followLink = true
115  ) const;
116 
117  //- Does the name exist as a directory in the file system?
118  virtual bool isDir
119  (
120  const fileName&,
121  const bool followLink = true
122  ) const;
123 
124  //- Does the name exist as a FILE in the file system?
125  // Optionally enable/disable check for gzip file.
126  virtual bool isFile
127  (
128  const fileName&,
129  const bool checkVariants = true,
130  const bool followLink = true
131  ) const;
132 
133  //- Return size of file
134  virtual off_t fileSize
135  (
136  const fileName&,
137  const bool checkVariants = true,
138  const bool followLink = true
139  ) const;
140 
141  //- Return time of last file modification
142  virtual time_t lastModified
143  (
144  const fileName&,
145  const bool checkVariants = true,
146  const bool followLink = true
147  ) const;
148 
149  //- Return time of last file modification
150  virtual double highResLastModified
151  (
152  const fileName&,
153  const bool checkVariants = true,
154  const bool followLink = true
155  ) const;
156 
157  //- Read a directory and return the entries as a string list
158  virtual fileNameList readDir
159  (
160  const fileName&,
161  const fileType = fileType::file,
162  const bool filtergz=true,
163  const bool followLink = true
164  ) const;
165 
166  //- Copy, recursively if necessary, the source to the destination
167  virtual bool cp
168  (
169  const fileName& src,
170  const fileName& dst,
171  const bool followLink = true
172  ) const;
173 
174  //- Create a softlink. dst should not exist. Returns true if
175  // successful.
176  virtual bool ln(const fileName& src, const fileName& dst) const;
177 
178  //- Rename src to dst
179  virtual bool mv
180  (
181  const fileName& src,
182  const fileName& dst,
183  const bool followLink = false
184  ) const;
185 
186  //- Rename to a corresponding backup file
187  // If the backup file already exists, attempt with
188  // "01" .. "99" suffix
189  virtual bool mvBak
190  (
191  const fileName&,
192  const std::string& ext = "bak"
193  ) const;
194 
195  //- Remove a file, returning true if successful otherwise false
196  virtual bool rm(const fileName&) const;
197 
198  //- Remove a directory and its contents
199  virtual bool rmDir(const fileName&) const;
200 
201 // //- Open a shared library. Return handle to library. Print error
202 // // message if library cannot be loaded (check = true)
203 // virtual void* dlOpen
204 // (
205 // const fileName& lib,
206 // const bool check = true
207 // ) const;
208 
209 
210  // (reg)IOobject functinality
211 
212  //- Search for an object. checkGlobal : also check undecomposed case
213  virtual fileName filePath
214  (
215  const bool checkGlobal,
216  const IOobject&,
217  const word& typeName
218  ) const;
219 
220  //- Search for a directory. checkGlobal : also check undecomposed
221  // case
222  virtual fileName dirPath
223  (
224  const bool checkGlobal,
225  const IOobject&
226  ) const;
227 
228  //- Search directory for objects. Used in IOobjectList.
229  virtual fileNameList readObjects
230  (
231  const objectRegistry& db,
232  const fileName& instance,
233  const fileName& local,
234  word& newInstance
235  ) const;
236 
237  //- Read object header from supplied file
238  virtual bool readHeader
239  (
240  IOobject&,
241  const fileName&,
242  const word& typeName
243  ) const;
244 
245  //- Reads header for regIOobject and returns an ISstream
246  // to read the contents.
248  (
249  regIOobject&,
250  const fileName&,
251  const word& typeName,
252  const bool read = true
253  ) const;
254 
255  //- Top-level read
256  virtual bool read
257  (
258  regIOobject&,
259  const bool masterOnly,
261  const word& typeName
262  ) const;
263 
264  //- Generate an ISstream that reads a file
265  virtual autoPtr<ISstream> NewIFstream(const fileName&) const;
266 
267  //- Generate an Ostream that writes a file
269  (
270  const fileName& pathname,
274  const bool write = true
275  ) const;
276 };
277 
278 
279 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
280 
281 } // End namespace fileOperations
282 } // End namespace Foam
283 
284 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
285 
286 #endif
287 
288 // ************************************************************************* //
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.
virtual autoPtr< Ostream > NewOFstream(const fileName &pathname, 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 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.
virtual bool read(regIOobject &, const bool masterOnly, const IOstream::streamFormat format, const word &typeName) const
Top-level read.
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.
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
void write(Ostream &, const label, const dictionary &)
Write with dictionary lookup.
virtual bool isDir(const fileName &, const bool followLink=true) const
Does the name exist as a directory in the file system?
virtual autoPtr< ISstream > NewIFstream(const fileName &) const
Generate an ISstream that reads a file.
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
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:206
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:55
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.