Vuo  2.0.0
Public Member Functions | Friends | List of all members
VuoFileUtilities::File Class Reference

Description

A file in either a directory or an archive.

Definition at line 45 of file VuoFileUtilities.hh.

Public Member Functions

 File ()
 Creates an unset file reference. More...
 
 File (string dirPath, string filePath)
 Creates a reference to a file that is in a directory. More...
 
 File (Archive *archive, string filePath)
 Creates a reference to a file that is in an archive. More...
 
 ~File (void)
 If this file is in an archive and it was the last File object using the Archive object, closes the archive. More...
 
File fileWithDifferentExtension (string extension)
 Creates a reference to a file in the same directory/archive as the current file, but with a different extension. More...
 
bool isInArchive (void)
 Returns true if this file is inside an archive. More...
 
string getArchivePath (void)
 Returns the path of the archive that contains this file. More...
 
string getRelativePath (void)
 Returns the path of the file, relative to its enclosing directory or archive. More...
 
string path ()
 Returns the absolute path to the file, including the filename. More...
 
string dir ()
 Returns the absolute path to the folder containing the file file. More...
 
string basename ()
 Returns the part of the filename before the extension. More...
 
string extension ()
 Returns the extension part of the filename. More...
 
char * getContentsAsRawData (size_t &numBytes)
 Returns the contents of the file as an array of bytes. More...
 
string getContentsAsString (void)
 Returns the contents of the file as a string. More...
 
bool lockForReading (bool nonBlocking=false) VuoWarnUnusedResult
 Acquires a lock on the file. More...
 
bool lockForWriting (bool nonBlocking=false) VuoWarnUnusedResult
 Acquires a lock on the file. More...
 
void unlock (void)
 Releases a lock on the file from lockForReading() or lockForWriting(). More...
 

Friends

class VuoFileUtilities
 

Constructor & Destructor Documentation

◆ File() [1/3]

VuoFileUtilities::File::File ( )

Creates an unset file reference.

(This is needed in order to use VuoFileUtilities::File in Q_DECLARE_METATYPE.)

Definition at line 1031 of file VuoFileUtilities.cc.

◆ File() [2/3]

VuoFileUtilities::File::File ( string  dirPath,
string  filePath 
)

Creates a reference to a file that is in a directory.

Definition at line 1038 of file VuoFileUtilities.cc.

◆ File() [3/3]

VuoFileUtilities::File::File ( Archive archive,
string  filePath 
)

Creates a reference to a file that is in an archive.

After this constructor is called, it's important to call the destructor. The archive will be closed when all File objects that used it are destroyed.

Definition at line 1052 of file VuoFileUtilities.cc.

◆ ~File()

VuoFileUtilities::File::~File ( void  )

If this file is in an archive and it was the last File object using the Archive object, closes the archive.

Definition at line 1078 of file VuoFileUtilities.cc.

Member Function Documentation

◆ basename()

string VuoFileUtilities::File::basename ( )

Returns the part of the filename before the extension.

Definition at line 1139 of file VuoFileUtilities.cc.

◆ dir()

string VuoFileUtilities::File::dir ( )

Returns the absolute path to the folder containing the file file.

Exceptions
std::runtime_errorThe file is in an archive.

Definition at line 1128 of file VuoFileUtilities.cc.

◆ extension()

string VuoFileUtilities::File::extension ( )

Returns the extension part of the filename.

Definition at line 1147 of file VuoFileUtilities.cc.

◆ fileWithDifferentExtension()

VuoFileUtilities::File VuoFileUtilities::File::fileWithDifferentExtension ( string  extension)

Creates a reference to a file in the same directory/archive as the current file, but with a different extension.

Definition at line 1064 of file VuoFileUtilities.cc.

◆ getArchivePath()

string VuoFileUtilities::File::getArchivePath ( void  )

Returns the path of the archive that contains this file.

If this file is not inside an archive, returns an empty string.

Definition at line 1097 of file VuoFileUtilities.cc.

◆ getContentsAsRawData()

char * VuoFileUtilities::File::getContentsAsRawData ( size_t &  numBytes)

Returns the contents of the file as an array of bytes.

Parameters
[out]numBytesThe size of the returned array.
Returns
The array of bytes. The caller is responsible for freeing it.
Exceptions
std::runtime_errorThe file couldn't be read.

Definition at line 1160 of file VuoFileUtilities.cc.

◆ getContentsAsString()

string VuoFileUtilities::File::getContentsAsString ( void  )

Returns the contents of the file as a string.

Exceptions
std::runtime_errorThe file couldn't be read.

Definition at line 1205 of file VuoFileUtilities.cc.

◆ getRelativePath()

string VuoFileUtilities::File::getRelativePath ( void  )

Returns the path of the file, relative to its enclosing directory or archive.

Definition at line 1105 of file VuoFileUtilities.cc.

◆ isInArchive()

bool VuoFileUtilities::File::isInArchive ( void  )

Returns true if this file is inside an archive.

Definition at line 1087 of file VuoFileUtilities.cc.

◆ lockForReading()

bool VuoFileUtilities::File::lockForReading ( bool  nonBlocking = false)

Acquires a lock on the file.

While this lock is held, no one else (in this or another process) can hold a lock on the file from lockForWriting(). If a lock from lockFromWriting() is already held for the file, this function downgrades the lock.

Parameters
nonBlockingTrue if the function should return immediately instead of waiting if the lock is not immediately available.
Returns
True if the lock was acquired.

Definition at line 1223 of file VuoFileUtilities.cc.

◆ lockForWriting()

bool VuoFileUtilities::File::lockForWriting ( bool  nonBlocking = false)

Acquires a lock on the file.

While this lock is held, no one else (in this or another process) can hold a lock on the file from lockForReading() or lockForWriting(). If a lock from lockForReading() is already held for the file, this function upgrades the lock.

Parameters
nonBlockingTrue if the function should return immediately instead of waiting if the lock is not immediately available.
Returns
True if the lock was acquired.

Definition at line 1240 of file VuoFileUtilities.cc.

◆ path()

string VuoFileUtilities::File::path ( )

Returns the absolute path to the file, including the filename.

Exceptions
std::runtime_errorThe file is in an archive.

Definition at line 1115 of file VuoFileUtilities.cc.

◆ unlock()

void VuoFileUtilities::File::unlock ( void  )

Releases a lock on the file from lockForReading() or lockForWriting().

If a lock has been upgraded from reading to writing, this function fully unlocks the file (rather than downgrading the lock back to reading).

Definition at line 1252 of file VuoFileUtilities.cc.


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