dummyFileOperation Class Reference

Dummy fileOperation, to be used as a placeholder for interfaces taking a reference to a fileOperation. Will mostly behave like a no-op, but at the moment no guarantees of any particular behaviour other than good() returning false. More...

Inheritance diagram for dummyFileOperation:
Collaboration diagram for dummyFileOperation:

Public Member Functions

 TypeNameNoDebug ("dummy")
 Runtime type information. More...
 
 dummyFileOperation (bool verbose=false)
 Default construct. More...
 
virtual ~dummyFileOperation ()
 Destructor. More...
 
virtual bool good () const
 This fileOperation is not really valid for anything. More...
 
virtual void storeComm () const
 No managed communicator. More...
 
virtual bool mkDir (const fileName &, mode_t=0777) const
 Make directory. More...
 
virtual bool chMod (const fileName &, const mode_t) const
 Set the file mode. More...
 
virtual mode_t mode (const fileName &, const bool followLink=true) const
 Return the file mode. More...
 
virtual fileName::Type type (const fileName &, const bool followLink=true) const
 Return the file type: DIRECTORY, FILE or SYMLINK. More...
 
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? More...
 
virtual bool isDir (const fileName &, const bool followLink=true) const
 Does the name exist as a DIRECTORY in the file system? More...
 
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? More...
 
virtual off_t fileSize (const fileName &, const bool followLink=true) const
 Return size of file. More...
 
virtual time_t lastModified (const fileName &, const bool followLink=true) const
 Return time of last file modification. More...
 
virtual double highResLastModified (const fileName &, const bool followLink=true) const
 Return time of last file modification. More...
 
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. More...
 
virtual bool cp (const fileName &src, const fileName &dst, const bool followLink=true) const
 Copy, recursively if necessary, the source to the destination. More...
 
virtual bool ln (const fileName &src, const fileName &dst) const
 Create a softlink. dst should not exist. Returns true if. More...
 
virtual bool mv (const fileName &src, const fileName &dst, const bool followLink=false) const
 Rename src to dst. More...
 
virtual bool mvBak (const fileName &, const std::string &ext="bak") const
 Rename to a corresponding backup file. More...
 
virtual bool rm (const fileName &) const
 Remove a file, returning true if successful otherwise false. More...
 
virtual bool rmDir (const fileName &dir, const bool silent=false, const bool emptyOnly=false) const
 Remove a directory and its contents. More...
 
virtual fileName filePath (const bool checkGlobal, const IOobject &io, const word &typeName, const bool search) const
 Search for an object. checkGlobal. More...
 
virtual fileName dirPath (const bool checkGlobal, const IOobject &io, const bool search) const
 Search for a directory. checkGlobal. More...
 
virtual fileNameList readObjects (const objectRegistry &db, const fileName &instance, const fileName &local, word &newInstance) const
 Search directory for objects. Used in IOobjectList. More...
 
virtual bool readHeader (IOobject &, const fileName &, const word &typeName) const
 Read object header from supplied file. More...
 
virtual autoPtr< ISstreamreadStream (regIOobject &, const fileName &, const word &typeName, const bool readOnProc=true) const
 Reads header for regIOobject and returns an ISstream to read the contents. More...
 
virtual bool read (regIOobject &, const bool masterOnly, const IOstreamOption::streamFormat format, const word &typeName) const
 Top-level read. More...
 
virtual autoPtr< ISstreamNewIFstream (const fileName &) const
 Generate an ISstream that reads a file. More...
 
virtual autoPtr< OSstreamNewOFstream (const fileName &pathname, IOstreamOption streamOpt=IOstreamOption(), const bool writeOnProc=true) const
 Generate an OSstream that writes a file. More...
 
virtual autoPtr< OSstreamNewOFstream (IOstreamOption::atomicType, const fileName &pathname, IOstreamOption streamOpt=IOstreamOption(), const bool writeOnProc=true) const
 Generate an OSstream that writes a file. More...
 
- Public Member Functions inherited from fileOperation
 TypeName ("fileOperation")
 Runtime type information. More...
 
 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. More...
 
 fileOperation (const Tuple2< label, labelList > &commAndIORanks, const bool distributedRoots=false)
 Construct from communicator with specified io-ranks. More...
 
 declareRunTimeSelectionTable (autoPtr, fileOperation, word,(bool verbose),(verbose))
 
 declareRunTimeSelectionTable (autoPtr, fileOperation, comm,(const Tuple2< label, labelList > &commAndIORanks, const bool distributedRoots, bool verbose),(commAndIORanks, distributedRoots, verbose))
 
virtual ~fileOperation ()=default
 Destructor. More...
 
label comm () const noexcept
 Communicator to use. More...
 
label comm (label communicator) const noexcept
 Set communicator to use [mutable]. Negative values are a no-op. More...
 
bool distributed () const noexcept
 Distributed roots (parallel run) More...
 
bool distributed (bool on) const noexcept
 Set distributed roots on/off [mutable]. More...
 
const labelListioRanks () const noexcept
 The list of IO ranks (global ranks) More...
 
InfoProxy< fileOperationinfo () const noexcept
 Return info proxy, used to print information to a stream. More...
 
virtual bool broadcastCopy (const label comm, const bool writeOnProc, const fileName &src, const fileName &dst) const
 Read dir/file (recursively if necessary) on master of the communicator, send and write contents to all 'writeOnProc' processors with local file name. More...
 
virtual fileName objectPath (const IOobject &io, const word &typeName) const
 Generate disk file name for object. Opposite of filePath. More...
 
virtual bool writeObject (const regIOobject &io, IOstreamOption streamOpt=IOstreamOption(), const bool writeOnProc=true) const
 Writes a regIOobject (so header, contents and divider). More...
 
virtual fileName filePath (const fileName &, const bool checkGzip=true, const bool followLink=true) const
 Search for a file or directory. Use IOobject version in preference. More...
 
virtual label addWatch (const fileName &) const
 Add watching of a file. Returns handle. More...
 
virtual bool removeWatch (const label) const
 Remove watch on a file (using handle) More...
 
virtual label findWatch (const labelList &watchIndices, const fileName &) const
 Find index (or -1) of file in list of handles. More...
 
virtual void addWatches (regIOobject &, const fileNameList &) const
 Helper: add watches for list of regIOobjects. More...
 
virtual fileName getFile (const label) const
 Get name of file being watched (using handle) More...
 
virtual void updateStates (const bool masterOnly, const bool syncPar) const
 Update state of all files. More...
 
virtual fileMonitor::fileState getState (const label) const
 Get current state of file (using handle) More...
 
virtual void setUnmodified (const label) const
 Set current state of file (using handle) to unmodified. More...
 
virtual word processorsDir (const IOobject &io) const
 Actual name of processors dir (for use in mode PROCOBJECT, PROCINSTANCE) More...
 
virtual word processorsDir (const fileName &) const
 Actual name of processors dir (for use in mode PROCOBJECT, PROCINSTANCE) More...
 
label nProcs () const noexcept
 Overall number of processors, from UPstream::nProcs() or detected from directories/results. More...
 
label nProcs (const label numProcs) noexcept
 Set number of processor directories/results. More...
 
virtual label nProcs (const fileName &dir, const fileName &local="", const label wantedNProcs=0) const
 Get number of processor directories/results. More...
 
virtual instantList findTimes (const fileName &, const word &) const
 Get sorted list of times. More...
 
virtual IOobject findInstance (const IOobject &io, const scalar startValue, const word &stopInstance) const
 Find instance where IOobject is. More...
 
virtual void setTime (const Time &) const
 Callback for time change. More...
 
virtual void flush () const
 Forcibly wait until all output done. Flush any cached data. More...
 
virtual void sync ()
 Forcibly parallel sync. More...
 
fileName processorsCasePath (const IOobject &io, const word &procDir) const
 Generate path (like io.path) from root+casename with any. More...
 
fileName processorsPath (const IOobject &io, const word &instance, const word &procDir) const
 Generate path (like io.path) with provided instance and any. More...
 
fileName processorsPath (const fileName &, const word &procDir) const
 Operating on fileName: replace processorXXX with procDir. More...
 
label setNProcs (label numProcs)
 Same as nProcs. More...
 

Additional Inherited Members

- Public Types inherited from fileOperation
enum  pathType : int {
  NOTFOUND = 0, ABSOLUTE, OBJECT, WRITEOBJECT,
  PROCUNCOLLATED, PROCBASEOBJECT = PROCUNCOLLATED + 1, PROCOBJECT = PROCBASEOBJECT + 1, PARENTOBJECT,
  FINDINSTANCE, PROCUNCOLLATEDINSTANCE, PROCBASEINSTANCE, PROCINSTANCE
}
 Enumeration for the location of an IOobject. More...
 
typedef Tuple2< fileName, Tuple2< pathType, int > > dirIndex
 Augment fileName with pathType and local offset. More...
 
typedef List< dirIndexdirIndexList
 
typedef IntRange< int > procRangeType
 For addressing a range of processors, identical to UPstream::rangeType. More...
 
- Static Public Member Functions inherited from fileOperation
static refPtr< fileOperationnull ()
 Reference to a dummy file handler. More...
 
static autoPtr< fileOperationNew (const word &handlerType, bool verbose=false)
 Select fileHandler-type. Uses defaultFileHandler if the handlerType is empty. More...
 
static autoPtr< fileOperationNew (const word &handlerType, const Tuple2< label, labelList > &commAndIORanks, const bool distributedRoots, bool verbose=false)
 Select fileHandler-type. Uses defaultFileHandler if the handlerType is empty. More...
 
static autoPtr< fileOperationNew (const fileOperation &origHandler, const boolUList &useProc, bool verbose=false)
 Replicate the given fileHandler properties with a subset of (global) ranks. More...
 
static autoPtr< fileOperationNew (const fileOperation &origHandler, const bitSet &useProc, bool verbose=false)
 Replicate the given fileHandler properties with a subset of (global) ranks. More...
 
static autoPtr< fileOperationNewUncollated ()
 The commonly used uncollatedFileOperation. More...
 
static const fileOperationfileHandler ()
 Return the current file handler. Will create the default file handler if necessary. More...
 
static refPtr< fileOperationfileHandler (std::nullptr_t)
 Delete current file handler. More...
 
static refPtr< fileOperationfileHandler (refPtr< fileOperation > &newHandler)
 Replace the current file handler. More...
 
static refPtr< fileOperationfileHandler (refPtr< fileOperation > &&newHandler)
 Replace the current file handler. More...
 
static refPtr< fileOperationfileHandler (autoPtr< fileOperation > &&newHandler)
 Replace the current file handler. More...
 
static int cacheLevel () noexcept
 Return cache level. More...
 
static int cacheLevel (int level) noexcept
 Set cache level (0 = off). More...
 
static int nProcsFilter () noexcept
 Return collated 'processorsDDD' filtering. More...
 
static int nProcsFilter (int level) noexcept
 Set collated 'processorsDDD' filtering (0 = off). More...
 
static instantList sortTimes (const fileNameList &dirEntries, const word &constantName="constant")
 Sort directory entries according to time value,. More...
 
static bool uniformFile (const fileNameList &names)
 True if the file names are identical. False on an empty list. More...
 
static bool uniformFile (const label comm, const fileName &name)
 True if the file name is identical on all ranks. More...
 
static label splitProcessorPath (const fileName &objectPath, fileName &path, fileName &procDir, fileName &local, procRangeType &group, label &nProcs)
 Split objectPath into part before 'processor' and part after. More...
 
static label detectProcessorPath (const fileName &objPath)
 Detect processor number from '/aa/bb/processorDDD/cc'. More...
 
static labelRange subRanks (const labelUList &mainIOranks)
 Get (contiguous) range/bounds of ranks addressed within the given main io-ranks. More...
 
static labelList getGlobalHostIORanks ()
 Get list of global IO master ranks based on the hostname. It is assumed that each host range is contiguous. More...
 
static labelList getGlobalIORanks ()
 Get list of global IO ranks from FOAM_IORANKS env variable. If set, these correspond to the IO master ranks. More...
 
- Static Public Attributes inherited from fileOperation
static const Enum< pathTypepathTypeNames_
 
static word processorsBaseDir = "processors"
 Return the processors directory name (usually "processors") More...
 
static word defaultFileHandler
 Name of the default fileHandler. More...
 
static refPtr< fileOperationfileHandlerPtr_
 The currently active file handler. Avoid accessing directly. More...
 
- Protected Member Functions inherited from fileOperation
fileMonitormonitor () const
 Get or create fileMonitor singleton. More...
 
refPtr< dirIndexListlookupAndCacheProcessorsPath (const fileName &objectPath, const bool syncPar) const
 Lookup name of processorsDDD using cache. More...
 
virtual refPtr< dirIndexListlookupProcessorsPath (const fileName &objectPath) const
 Lookup name of processorsDDD using cache. More...
 
bool exists (IOobject &io) const
 Does IOobject exist? Is either a directory (empty name()) or a file. More...
 
bool isIOrank (const label proci) const
 Is proci a master rank in the communicator (in parallel) or a master rank in the IO ranks (non-parallel) More...
 
void printRanks () const
 Helper: output which ranks are IO. More...
 
- Static Protected Member Functions inherited from fileOperation
static void mergeTimes (const instantList &extraTimes, const word &constantName, instantList &times)
 Merge two times. More...
 
static bool isFileOrDir (const bool isFile, const fileName &)
 Helper: check for file (isFile) or directory (!isFile) More...
 
static label getManagedComm (const label communicator)
 Construction helper: check for locally allocated communicator. More...
 
- Protected Attributes inherited from fileOperation
label comm_
 Communicator to use. More...
 
label nProcs_
 Overall number of processors. More...
 
bool distributed_
 Distributed roots (parallel run) More...
 
const labelList ioRanks_
 The list of IO ranks (global ranks) More...
 
HashTable< dirIndexListprocsDirs_
 Detected processors directories. More...
 
std::unique_ptr< fileMonitormonitorPtr_
 File-change monitor for all registered files. More...
 
- Static Protected Attributes inherited from fileOperation
static int cacheLevel_
 Cache level (eg, for caching time directories). Default: 1. More...
 

Detailed Description

Dummy fileOperation, to be used as a placeholder for interfaces taking a reference to a fileOperation. Will mostly behave like a no-op, but at the moment no guarantees of any particular behaviour other than good() returning false.

Definition at line 47 of file dummyFileOperation.H.

Constructor & Destructor Documentation

◆ dummyFileOperation()

dummyFileOperation ( bool  verbose = false)
explicit

Default construct.

Definition at line 42 of file dummyFileOperation.C.

◆ ~dummyFileOperation()

~dummyFileOperation ( )
virtual

Destructor.

Definition at line 60 of file dummyFileOperation.C.

Member Function Documentation

◆ TypeNameNoDebug()

TypeNameNoDebug ( "dummy"  )

Runtime type information.

◆ good()

virtual bool good ( ) const
inlinevirtual

This fileOperation is not really valid for anything.

Reimplemented from fileOperation.

Definition at line 78 of file dummyFileOperation.H.

◆ storeComm()

virtual void storeComm ( ) const
inlinevirtual

No managed communicator.

Implements fileOperation.

Definition at line 83 of file dummyFileOperation.H.

◆ mkDir()

bool mkDir ( const fileName dir,
mode_t  mode = 0777 
) const
virtual

Make directory.

Implements fileOperation.

Definition at line 67 of file dummyFileOperation.C.

References NotImplemented.

◆ chMod()

bool chMod ( const fileName fName,
const mode_t  mode 
) const
virtual

Set the file mode.

Implements fileOperation.

Definition at line 78 of file dummyFileOperation.C.

References NotImplemented.

◆ mode()

mode_t mode ( const fileName fName,
const bool  followLink = true 
) const
virtual

Return the file mode.

Implements fileOperation.

Definition at line 89 of file dummyFileOperation.C.

References NotImplemented.

◆ type()

Foam::fileName::Type type ( const fileName fName,
const bool  followLink = true 
) const
virtual

Return the file type: DIRECTORY, FILE or SYMLINK.

Implements fileOperation.

Definition at line 100 of file dummyFileOperation.C.

References NotImplemented.

◆ exists()

bool exists ( const fileName fName,
const bool  checkGzip = true,
const bool  followLink = true 
) const
virtual

Does the name exist (as DIRECTORY or FILE) in the file system?

Optionally enable/disable check for gzip file.

Implements fileOperation.

Definition at line 111 of file dummyFileOperation.C.

References NotImplemented.

◆ isDir()

bool isDir ( const fileName fName,
const bool  followLink = true 
) const
virtual

Does the name exist as a DIRECTORY in the file system?

Implements fileOperation.

Definition at line 123 of file dummyFileOperation.C.

References NotImplemented.

◆ isFile()

bool isFile ( const fileName fName,
const bool  checkGzip = true,
const bool  followLink = true 
) const
virtual

Does the name exist as a FILE in the file system?

Optionally enable/disable check for gzip file.

Implements fileOperation.

Definition at line 134 of file dummyFileOperation.C.

References NotImplemented.

◆ fileSize()

off_t fileSize ( const fileName fName,
const bool  followLink = true 
) const
virtual

Return size of file.

Implements fileOperation.

Definition at line 146 of file dummyFileOperation.C.

References NotImplemented.

◆ lastModified()

time_t lastModified ( const fileName fName,
const bool  followLink = true 
) const
virtual

Return time of last file modification.

Implements fileOperation.

Definition at line 157 of file dummyFileOperation.C.

References NotImplemented.

◆ highResLastModified()

double highResLastModified ( const fileName fName,
const bool  followLink = true 
) const
virtual

Return time of last file modification.

Implements fileOperation.

Definition at line 168 of file dummyFileOperation.C.

References NotImplemented.

◆ readDir()

Foam::fileNameList readDir ( const fileName dir,
const fileName::Type  type = fileName::FILE,
const bool  filtergz = true,
const bool  followLink = true 
) const
virtual

Read a directory and return the entries as a string list.

Implements fileOperation.

Definition at line 180 of file dummyFileOperation.C.

References NotImplemented.

◆ cp()

bool cp ( const fileName src,
const fileName dst,
const bool  followLink = true 
) const
virtual

Copy, recursively if necessary, the source to the destination.

Implements fileOperation.

Definition at line 193 of file dummyFileOperation.C.

References NotImplemented.

◆ ln()

bool ln ( const fileName src,
const fileName dst 
) const
virtual

Create a softlink. dst should not exist. Returns true if.

successful.

Implements fileOperation.

Definition at line 205 of file dummyFileOperation.C.

References NotImplemented.

◆ mv()

bool mv ( const fileName src,
const fileName dst,
const bool  followLink = false 
) const
virtual

Rename src to dst.

Implements fileOperation.

Definition at line 216 of file dummyFileOperation.C.

References NotImplemented.

◆ mvBak()

bool mvBak ( const fileName fName,
const std::string &  ext = "bak" 
) const
virtual

Rename to a corresponding backup file.

If the backup file already exists, attempt with "01" .. "99" suffix

Implements fileOperation.

Definition at line 228 of file dummyFileOperation.C.

References NotImplemented.

◆ rm()

bool rm ( const fileName fName) const
virtual

Remove a file, returning true if successful otherwise false.

Implements fileOperation.

Definition at line 239 of file dummyFileOperation.C.

References NotImplemented.

◆ rmDir()

bool rmDir ( const fileName dir,
const bool  silent = false,
const bool  emptyOnly = false 
) const
virtual

Remove a directory and its contents.

Parameters
dirthe directory to remove
silentdo not report missing directory
emptyOnlyonly remove empty directories (recursive)

Implements fileOperation.

Definition at line 249 of file dummyFileOperation.C.

References NotImplemented.

◆ filePath()

Foam::fileName filePath ( const bool  checkGlobal,
const IOobject io,
const word typeName,
const bool  search 
) const
virtual

Search for an object. checkGlobal.

Implements fileOperation.

Definition at line 263 of file dummyFileOperation.C.

References NotImplemented.

◆ dirPath()

Foam::fileName dirPath ( const bool  checkGlobal,
const IOobject io,
const bool  search 
) const
virtual

Search for a directory. checkGlobal.

Implements fileOperation.

Definition at line 276 of file dummyFileOperation.C.

References NotImplemented.

◆ readObjects()

Foam::fileNameList readObjects ( const objectRegistry db,
const fileName instance,
const fileName local,
word newInstance 
) const
virtual

Search directory for objects. Used in IOobjectList.

Reimplemented from fileOperation.

Definition at line 288 of file dummyFileOperation.C.

References NotImplemented.

◆ readHeader()

bool readHeader ( IOobject io,
const fileName fName,
const word typeName 
) const
virtual

Read object header from supplied file.

Implements fileOperation.

Definition at line 301 of file dummyFileOperation.C.

References io(), and NotImplemented.

Here is the call graph for this function:

◆ readStream()

Foam::autoPtr< Foam::ISstream > readStream ( regIOobject io,
const fileName fName,
const word typeName,
const bool  readOnProc = true 
) const
virtual

Reads header for regIOobject and returns an ISstream to read the contents.

Implements fileOperation.

Definition at line 315 of file dummyFileOperation.C.

References NotImplemented.

◆ read()

bool read ( regIOobject io,
const bool  masterOnly,
const IOstreamOption::streamFormat  format,
const word typeName 
) const
virtual

Top-level read.

Implements fileOperation.

Definition at line 328 of file dummyFileOperation.C.

References NotImplemented.

◆ NewIFstream()

Foam::autoPtr< Foam::ISstream > NewIFstream ( const fileName filePath) const
virtual

Generate an ISstream that reads a file.

Implements fileOperation.

Definition at line 342 of file dummyFileOperation.C.

References NotImplemented.

◆ NewOFstream() [1/2]

Foam::autoPtr< Foam::OSstream > NewOFstream ( const fileName pathname,
IOstreamOption  streamOpt = IOstreamOption(),
const bool  writeOnProc = true 
) const
virtual

Generate an OSstream that writes a file.

Implements fileOperation.

Definition at line 353 of file dummyFileOperation.C.

References NotImplemented.

◆ NewOFstream() [2/2]

Foam::autoPtr< Foam::OSstream > NewOFstream ( IOstreamOption::atomicType  atomic,
const fileName pathname,
IOstreamOption  streamOpt = IOstreamOption(),
const bool  writeOnProc = true 
) const
virtual

Generate an OSstream that writes a file.

Implements fileOperation.

Definition at line 366 of file dummyFileOperation.C.

References NotImplemented.


The documentation for this class was generated from the following files: