Inviwo 0.9.12-pre
Inviwo documentation
|
Enumerations | |
enum class | ListMode { Files , Directories , FilesAndDirectories } |
Functions | |
IVW_CORE_API FILE * | fopen (const std::filesystem::path &filename, const char *mode) |
IVW_CORE_API std::fstream | fstream (const std::filesystem::path &filename, std::ios_base::openmode mode=std::ios_base::in|std::ios_base::out) |
IVW_CORE_API std::ifstream | ifstream (const std::filesystem::path &filename, std::ios_base::openmode mode=std::ios_base::in) |
IVW_CORE_API std::ofstream | ofstream (const std::filesystem::path &filename, std::ios_base::openmode mode=std::ios_base::out) |
IVW_CORE_API bool | skipByteOrderMark (std::istream &stream) |
IVW_CORE_API std::filesystem::path | getWorkingDirectory () |
IVW_CORE_API void | setWorkingDirectory (const std::filesystem::path &path) |
IVW_CORE_API std::filesystem::path | getExecutablePath () |
IVW_CORE_API std::filesystem::path | getInviwoBinDir () |
IVW_CORE_API std::vector< std::filesystem::path > | getLoadedLibraries () |
IVW_CORE_API int | getCurrentProcessId () |
IVW_CORE_API std::filesystem::path | getInviwoUserSettingsPath () |
IVW_CORE_API bool | fileExists (const std::filesystem::path &filePath) |
Check if a file exists. | |
IVW_CORE_API bool | directoryExists (const std::filesystem::path &path) |
IVW_CORE_API std::time_t | fileModificationTime (const std::filesystem::path &filePath) |
Get last time file was modified. Error can occur if the file does not exist for example. | |
IVW_CORE_API bool | copyFile (const std::filesystem::path &src, const std::filesystem::path &dst) |
Copy an existing file to a new file. Overwrites existing file. | |
IVW_CORE_API std::vector< std::filesystem::path > | getDirectoryContents (const std::filesystem::path &path, ListMode mode=ListMode::Files) |
IVW_CORE_API std::vector< std::filesystem::path > | getDirectoryContentsRecursively (const std::filesystem::path &path, ListMode mode=ListMode::Files) |
IVW_CORE_API bool | wildcardStringMatch (const std::string &pattern, const std::string &str) |
IVW_CORE_API bool | wildcardStringMatchDigits (const std::string &pattern, const std::string &str, int &index, bool matchLess=false, bool matchMore=true) |
IVW_CORE_API std::optional< std::filesystem::path > | getParentFolderWithChildren (const std::filesystem::path &path, std::span< const std::filesystem::path > childFolders) |
IVW_CORE_API const std::filesystem::path & | findBasePath () |
IVW_CORE_API std::filesystem::path | getPath (PathType pathType, const std::string &suffix="", const bool createFolder=false) |
IVW_CORE_API void | createDirectoryRecursively (const std::filesystem::path &path) |
IVW_CORE_API std::filesystem::path | addBasePath (const std::filesystem::path &url) |
Adds the InviwoApplication base path before the url. | |
IVW_CORE_API std::filesystem::path | getFileDirectory (const std::filesystem::path &url) |
IVW_CORE_API std::filesystem::path | getFileNameWithExtension (const std::filesystem::path &url) |
IVW_CORE_API std::filesystem::path | getFileNameWithoutExtension (const std::filesystem::path &url) |
IVW_CORE_API std::string | getFileExtension (const std::filesystem::path &url) |
Returns the characters after last dot (.). | |
IVW_CORE_API std::filesystem::path | replaceFileExtension (const std::filesystem::path &url, std::string_view newFileExtension) |
IVW_CORE_API std::filesystem::path | getRelativePath (const std::filesystem::path &basePath, const std::filesystem::path &absolutePath) |
Make a path relative to basePath. Requirement: basePath and absulutePath has to be absolute paths. basePath should point at directory. | |
IVW_CORE_API std::filesystem::path | getCanonicalPath (const std::filesystem::path &url) |
IVW_CORE_API bool | isAbsolutePath (const std::filesystem::path &path) |
IVW_CORE_API bool | sameDrive (const std::filesystem::path &refPath, const std::filesystem::path &queryPath) |
Checks whether the second path is on the same drive as the first path. | |
IVW_CORE_API std::filesystem::path | cleanupPath (std::string_view path) |
clean up path by replacing backslashes with forward slash and removing surrounding quotes | |
filesystem
IVW_CORE_API std::filesystem::path inviwo::filesystem::addBasePath | ( | const std::filesystem::path & | url | ) |
Adds the InviwoApplication base path before the url.
url | Relative path |
IVW_CORE_API std::filesystem::path inviwo::filesystem::cleanupPath | ( | std::string_view | path | ) |
clean up path by replacing backslashes with forward slash and removing surrounding quotes
path | given path to be cleaned up |
IVW_CORE_API bool inviwo::filesystem::copyFile | ( | const std::filesystem::path & | src, |
const std::filesystem::path & | dst ) |
Copy an existing file to a new file. Overwrites existing file.
src | Path to the file to the existing file |
dst | Path to the new file |
IVW_CORE_API bool inviwo::filesystem::directoryExists | ( | const std::filesystem::path & | path | ) |
Check if the directory exists
path | Directory path |
IVW_CORE_API bool inviwo::filesystem::fileExists | ( | const std::filesystem::path & | filePath | ) |
Check if a file exists.
filePath | The path to the file |
IVW_CORE_API std::time_t inviwo::filesystem::fileModificationTime | ( | const std::filesystem::path & | filePath | ) |
Get last time file was modified. Error can occur if the file does not exist for example.
filePath | The path to the file |
IVW_CORE_API const std::filesystem::path & inviwo::filesystem::findBasePath | ( | ) |
Try to find the Inviwo base path containing subfolders "data/workspaces" and "modules". If not found, try searching for path containing "modules". If neither are found, return the executable path.
IVW_CORE_API FILE * inviwo::filesystem::fopen | ( | const std::filesystem::path & | filename, |
const char * | mode ) |
Creates and returns a FILE pointer for the given file name (utf-8 encoded). The call auto f = filesystem::fopen(filename, mode);
is functionally equivalent to the statement fopen(filename, mode);
or _wfopen();
, respectively. No checks whether the file exists or was successfully opened are performed. That is the caller has to check it. For more details check the documentation of fopen.
Since all strings within Inviwo are utf-8 encoded, this function should be used to create a file handle when reading from/writing to files.
On Windows, the file name is first converted from a utf-8 string to std::wstring and then the file handle is created using the std::wstring as fopen(const char*) does not support utf-8.
filename | utf-8 encoded string |
mode | mode to open the file (input or output) |
fopen(filename, mode);
IVW_CORE_API std::fstream inviwo::filesystem::fstream | ( | const std::filesystem::path & | filename, |
std::ios_base::openmode | mode = std::ios_base::in|std::ios_base::out ) |
Creates and returns a std::fstream for the given file name (utf-8 encoded). The call auto f = filesystem::fstream(filename, mode);
is functionally equivalent to the statement std::fstream f(filename, mode);
. No checks whether the file exists or was successfully opened are performed. That is the caller has to check it. For more details check the documentation of std::fstream.
Since all strings within Inviwo are utf-8 encoded, this function should be used to create a stream when reading from/writing to files using streams.
On Windows, the file name is first converted from a utf-8 string to std::wstring and then the stream is created using the std::wstring as std::fstream(std::string) does not support utf-8.
filename | utf-8 encoded string |
mode | mode to open the file (input or output) |
std::fstream(filename, mode);
IVW_CORE_API std::vector< std::filesystem::path > inviwo::filesystem::getDirectoryContents | ( | const std::filesystem::path & | path, |
ListMode | mode = ListMode::Files ) |
Returns the file listing of a directory
path | Files are listed for this directory |
mode | What types of contents to return see ListMode |
IVW_CORE_API std::vector< std::filesystem::path > inviwo::filesystem::getDirectoryContentsRecursively | ( | const std::filesystem::path & | path, |
ListMode | mode = ListMode::Files ) |
Recursively searches and returns full path to files/directories in specified directory and its subdirectories.
path | Files are listed for this directory and its subdirectories |
mode | What types of contents to return see ListMode |
IVW_CORE_API std::filesystem::path inviwo::filesystem::getExecutablePath | ( | ) |
Get full/path/to/executable running the application.
IVW_CORE_API std::string inviwo::filesystem::getFileExtension | ( | const std::filesystem::path & | url | ) |
Returns the characters after last dot (.).
url | Path to extract extension from. |
IVW_CORE_API std::filesystem::path inviwo::filesystem::getInviwoUserSettingsPath | ( | ) |
Get path to the user settings / data folder for Inviwo, i.e. a folder where we have write-access. Will be:
IVW_CORE_API std::optional< std::filesystem::path > inviwo::filesystem::getParentFolderWithChildren | ( | const std::filesystem::path & | path, |
std::span< const std::filesystem::path > | childFolders ) |
Traverses all parent folders of path and returns the first directory matching the list of child folders.
path | directory where the search is started |
childFolders | list of subfolders |
IVW_CORE_API std::filesystem::path inviwo::filesystem::getPath | ( | PathType | pathType, |
const std::string & | suffix = "", | ||
const bool | createFolder = false ) |
Get basePath + pathType + suffix.
pathType | Enum for type of path |
suffix | Path extension |
createFolder | if true, will create the folder on disk if it does not exists. |
IVW_CORE_API std::filesystem::path inviwo::filesystem::getRelativePath | ( | const std::filesystem::path & | basePath, |
const std::filesystem::path & | absolutePath ) |
Make a path relative to basePath. Requirement: basePath and absulutePath has to be absolute paths. basePath should point at directory.
Example: basePath = "C:/foo/bar" absolutePath = "C:/foo/test/file.txt" returns "../test/file.txt"
IVW_CORE_API std::filesystem::path inviwo::filesystem::getWorkingDirectory | ( | ) |
Get the working directory of the application.
IVW_CORE_API std::ifstream inviwo::filesystem::ifstream | ( | const std::filesystem::path & | filename, |
std::ios_base::openmode | mode = std::ios_base::in ) |
Creates and returns a std::ifstream for the given file name (utf-8 encoded). The call auto in = filesystem::ifstream(filename, mode);
is functionally equivalent to the statement std::ifstream in(filename, mode);
. No checks whether the file exists or was successfully opened are performed. That is the caller has to check it. For more details check the documentation of std::ifstream.
Since all strings within Inviwo are utf-8 encoded, this function should be used to create a stream when reading from files using streams.
On Windows, the file name is first converted from a utf-8 string to std::wstring and then the stream is created using the std::wstring as std::ifstream(std::string) does not support utf-8.
filename | utf-8 encoded string |
mode | mode to open the file (input or output) |
std::ifstream(filename, mode);
IVW_CORE_API std::ofstream inviwo::filesystem::ofstream | ( | const std::filesystem::path & | filename, |
std::ios_base::openmode | mode = std::ios_base::out ) |
Creates and returns a std::ofstream for the given file name (utf-8 encoded). The call auto out = filesystem::ofstream(filename, mode);
is functionally equivalent to the statement std::ofstream out(filename, mode);
. No checks whether the file exists or was successfully opened are performed. That is the caller has to check it. For more details check the documentation of std::ofstream.
Since all strings within Inviwo are utf-8 encoded, this function should be used to create a stream when writing to files using streams.
On Windows, the file name is first converted from a utf-8 string to std::wstring and then the stream is created using the std::wstring as std::ofstream(std::string) does not support utf-8.
filename | utf-8 encoded string |
mode | mode to open the file (input or output) |
std::ofstream(filename, mode);
IVW_CORE_API std::filesystem::path inviwo::filesystem::replaceFileExtension | ( | const std::filesystem::path & | url, |
std::string_view | newFileExtension ) |
Replace the last file extension to newFileExtension, if no extension exists append newFileExtension. newFileExtension should not contain any leading "."
IVW_CORE_API bool inviwo::filesystem::sameDrive | ( | const std::filesystem::path & | refPath, |
const std::filesystem::path & | queryPath ) |
Checks whether the second path is on the same drive as the first path.
If both paths are relative, this function returns true. If only refPath is relative InviwoApplication::getBasePath is used instead as reference.
refPath | reference path, if relative then InviwoApplication::getBasePath is used instead |
queryPath | path to be checked |
IVW_CORE_API void inviwo::filesystem::setWorkingDirectory | ( | const std::filesystem::path & | path | ) |
Set the working directory of the application.
IVW_CORE_API bool inviwo::filesystem::skipByteOrderMark | ( | std::istream & | stream | ) |
Detects the UTF-8 byte order mark (BOM) and skips it if it exists. Reads the first three characters to determine if the BOM exists. Rewinds stream if no BOM exists and otherwise leaves the stream position after the three BOM characters.
stream | stream to check and potentially modify. |
IVW_CORE_API bool inviwo::filesystem::wildcardStringMatch | ( | const std::string & | pattern, |
const std::string & | str ) |
Checks whether a given string matches a pattern. The pattern might contain '*' matching any string including the empty string and '?' matching a single character.
pattern | The pattern used for matching, might contain '*' and '?' |
str | String which needs to be checked |
IVW_CORE_API bool inviwo::filesystem::wildcardStringMatchDigits | ( | const std::string & | pattern, |
const std::string & | str, | ||
int & | index, | ||
bool | matchLess = false, | ||
bool | matchMore = true ) |
Checks whether a given string matches a pattern including digits. The pattern might contain a single sequence of '#' for indicating a number besides '*' matching any string including the empty string and '?' matching a single character.
The digit sequence indicated by '#' is extracted and returned. Depending on the flags, the number have to exactly match sequence or might be shorter (matchLess) or longer (matchMore). For example, the sequence '###' matches only a three-digit number. Enabling 'matchLess' also matches one-digit and two-digit numbers whereas 'matchMore' allows for numbers with more digits.
Examples:
pattern | The pattern used for matching, might contain a single sequence of '#' besides '*', and '?' |
str | String which needs to be checked |
index | if the match is successful, this index contains the extracted digit sequence indicated by '#' |
matchLess | allows to match digit sequences shorter than defined by the number of '#' (default false) |
matchMore | allows to match longer digit sequences (default true) |