uncollatedFileOperation.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 | Copyright (C) 2017 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 followLink = true
97  ) const;
98 
99  //- Return the file type: DIRECTORY, FILE or LINK
100  virtual fileName::Type type
101  (
102  const fileName&,
103  const bool followLink = true
104  ) const;
105 
106  //- Does the name exist (as DIRECTORY or FILE) in the file system?
107  // Optionally enable/disable check for gzip file.
108  virtual bool exists
109  (
110  const fileName&,
111  const bool checkGzip=true,
112  const bool followLink = true
113  ) const;
114 
115  //- Does the name exist as a DIRECTORY in the file system?
116  virtual bool isDir
117  (
118  const fileName&,
119  const bool followLink = true
120  ) const;
121 
122  //- Does the name exist as a FILE in the file system?
123  // Optionally enable/disable check for gzip file.
124  virtual bool isFile
125  (
126  const fileName&,
127  const bool checkGzip=true,
128  const bool followLink = true
129  ) const;
130 
131  //- Return size of file
132  virtual off_t fileSize
133  (
134  const fileName&,
135  const bool followLink = true
136  ) const;
137 
138  //- Return time of last file modification
139  virtual time_t lastModified
140  (
141  const fileName&,
142  const bool followLink = true
143  ) const;
144 
145  //- Return time of last file modification
146  virtual double highResLastModified
147  (
148  const fileName&,
149  const bool followLink = true
150  ) const;
151 
152  //- Read a directory and return the entries as a string list
153  virtual fileNameList readDir
154  (
155  const fileName&,
157  const bool filtergz=true,
158  const bool followLink = true
159  ) const;
160 
161  //- Copy, recursively if necessary, the source to the destination
162  virtual bool cp
163  (
164  const fileName& src,
165  const fileName& dst,
166  const bool followLink = true
167  ) const;
168 
169  //- Create a softlink. dst should not exist. Returns true if
170  // successful.
171  virtual bool ln(const fileName& src, const fileName& dst) const;
172 
173  //- Rename src to dst
174  virtual bool mv
175  (
176  const fileName& src,
177  const fileName& dst,
178  const bool followLink = false
179  ) const;
180 
181  //- Rename to a corresponding backup file
182  // If the backup file already exists, attempt with
183  // "01" .. "99" suffix
184  virtual bool mvBak
185  (
186  const fileName&,
187  const std::string& ext = "bak"
188  ) const;
189 
190  //- Remove a file, returning true if successful otherwise false
191  virtual bool rm(const fileName&) const;
192 
193  //- Remove a dirctory and its contents
194  virtual bool rmDir(const fileName&) const;
195 
196 // //- Open a shared library. Return handle to library. Print error
197 // // message if library cannot be loaded (check = true)
198 // virtual void* dlOpen
199 // (
200 // const fileName& lib,
201 // const bool check = true
202 // ) const;
203 
204 
205  // (reg)IOobject functinality
206 
207  //- Search for an object. checkGlobal : also check undecomposed case
208  virtual fileName filePath
209  (
210  const bool checkGlobal,
211  const IOobject&,
212  const word& typeName
213  ) const;
214 
215  //- Search for a directory. checkGlobal : also check undecomposed
216  // case
217  virtual fileName dirPath
218  (
219  const bool checkGlobal,
220  const IOobject&
221  ) const;
222 
223  //- Search directory for objects. Used in IOobjectList.
224  virtual fileNameList readObjects
225  (
226  const objectRegistry& db,
227  const fileName& instance,
228  const fileName& local,
229  word& newInstance
230  ) const;
231 
232  //- Read object header from supplied file
233  virtual bool readHeader
234  (
235  IOobject&,
236  const fileName&,
237  const word& typeName
238  ) const;
239 
240  //- Reads header for regIOobject and returns an ISstream
241  // to read the contents.
243  (
244  regIOobject&,
245  const fileName&,
246  const word& typeName,
247  const bool procValid = true
248  ) const;
249 
250  //- Top-level read
251  virtual bool read
252  (
253  regIOobject&,
254  const bool masterOnly,
256  const word& typeName
257  ) const;
258 
259  //- Generate an ISstream that reads a file
260  virtual autoPtr<ISstream> NewIFstream(const fileName&) const;
261 
262  //- Generate an Ostream that writes a file
264  (
265  const fileName& pathname,
269  const bool valid = true
270  ) const;
271 };
272 
273 
274 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
275 
276 } // End namespace fileOperations
277 } // End namespace Foam
278 
279 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
280 
281 #endif
282 
283 // ************************************************************************* //
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?
A class for handling file names.
Definition: fileName.H:69
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 mode_t mode(const fileName &, const bool followLink=true) const
Return the file mode.
virtual bool readHeader(IOobject &, const fileName &, const word &typeName) const
Read object header from supplied file.
virtual double highResLastModified(const fileName &, const bool followLink=true) const
Return time of last file modification.
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 bool isFile(const fileName &, const bool checkGzip=true, const bool followLink=true) const
Does the name exist as a FILE in the file system?
fileOperation that assumes file operations are local.
virtual bool rmDir(const fileName &) const
Remove a dirctory and its contents.
TypeName("uncollated")
Runtime type information.
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
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.
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.
virtual autoPtr< Ostream > NewOFstream(const fileName &pathname, IOstream::streamFormat format=IOstream::ASCII, IOstream::versionNumber version=IOstream::currentVersion, IOstream::compressionType compression=IOstream::UNCOMPRESSED, const bool valid=true) const
Generate an Ostream that writes 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 off_t fileSize(const fileName &, const bool followLink=true) const
Return size of file.
virtual fileName dirPath(const bool checkGlobal, const IOobject &) const
Search for a directory. checkGlobal : also check undecomposed.
virtual time_t lastModified(const fileName &, const bool followLink=true) const
Return time of last file modification.
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.
uncollatedFileOperation(const bool verbose)
Construct null.
virtual autoPtr< ISstream > readStream(regIOobject &, const fileName &, const word &typeName, const bool procValid=true) const
Reads header for regIOobject and returns an ISstream.
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:65
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 fileName::Type type(const fileName &, const bool followLink=true) const
Return the file type: DIRECTORY, FILE or LINK.
Type
Enumerations to handle file types and modes.
Definition: fileName.H:82
Namespace for OpenFOAM.