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... | |
bool | exists () |
Returns true if the file exists. 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 |
VuoFileUtilities::File::File | ( | ) |
Creates an unset file reference.
(This is needed in order to use VuoFileUtilities::File in Q_DECLARE_METATYPE.)
Definition at line 1126 of file VuoFileUtilities.cc.
VuoFileUtilities::File::File | ( | string | dirPath, |
string | filePath | ||
) |
Creates a reference to a file that is in a directory.
Definition at line 1133 of file VuoFileUtilities.cc.
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 1147 of file VuoFileUtilities.cc.
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 1173 of file VuoFileUtilities.cc.
string VuoFileUtilities::File::basename | ( | ) |
Returns the part of the filename before the extension.
Definition at line 1234 of file VuoFileUtilities.cc.
string VuoFileUtilities::File::dir | ( | ) |
Returns the absolute path to the folder containing the file file.
VuoException | The file is in an archive. |
Definition at line 1223 of file VuoFileUtilities.cc.
bool VuoFileUtilities::File::exists | ( | ) |
Returns true if the file exists.
Definition at line 1250 of file VuoFileUtilities.cc.
string VuoFileUtilities::File::extension | ( | ) |
Returns the extension part of the filename.
Definition at line 1242 of file VuoFileUtilities.cc.
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 1159 of file VuoFileUtilities.cc.
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 1192 of file VuoFileUtilities.cc.
char * VuoFileUtilities::File::getContentsAsRawData | ( | size_t & | numBytes | ) |
Returns the contents of the file as an array of bytes.
[out] | numBytes | The size of the returned array. |
VuoException | The file couldn't be read. |
Definition at line 1266 of file VuoFileUtilities.cc.
string VuoFileUtilities::File::getContentsAsString | ( | void | ) |
Returns the contents of the file as a string.
VuoException | The file couldn't be read. |
Definition at line 1311 of file VuoFileUtilities.cc.
string VuoFileUtilities::File::getRelativePath | ( | void | ) |
Returns the path of the file, relative to its enclosing directory or archive.
Definition at line 1200 of file VuoFileUtilities.cc.
bool VuoFileUtilities::File::isInArchive | ( | void | ) |
Returns true if this file is inside an archive.
Definition at line 1182 of file VuoFileUtilities.cc.
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.
nonBlocking | True if the function should return immediately instead of waiting if the lock is not immediately available. |
Definition at line 1329 of file VuoFileUtilities.cc.
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.
nonBlocking | True if the function should return immediately instead of waiting if the lock is not immediately available. |
Definition at line 1346 of file VuoFileUtilities.cc.
string VuoFileUtilities::File::path | ( | ) |
Returns the absolute path to the file, including the filename.
VuoException | The file is in an archive. |
Definition at line 1210 of file VuoFileUtilities.cc.
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 1358 of file VuoFileUtilities.cc.