te::core::FileSystem Class Reference

A class for handling system files and paths using UTF-8 strings. More...

#include <FileSystem.h>

Static Public Member Functions

static std::string absolutePath (const std::string &path)
 Retrives the absolute path for the given path in UTF-8. More...
 
static std::string adjustPathToGenericForm (const std::string &filePath)
 Adjusts the given path to generic form. More...
 
static std::string adjustPathToNativeForm (const std::string &filePath)
 Adjusts the given path to native form. More...
 
static bool allocateTmpDiskFile (unsigned long int size, FILE **fileptr, std::string &fullFileName)
 Create and allocate a new temporary disk file. More...
 
static void copyFile (const std::string &from, const std::string &to)
 Copies a file. More...
 
static bool createDirectories (const std::string &path)
 Creates a directory for any element of path that does not exist. More...
 
static bool createDirectory (const std::string &path)
 Creates a directory from a given path in UTF-8. More...
 
static std::string currentPath ()
 Retrives the current working directory path in UTF-8. More...
 
static std::string executableDirectory ()
 
static bool exists (const std::string &path)
 Checks if a given path in UTF-8 exists. More...
 
static std::string extension (const std::string &path)
 Retrives the extension of a given file path in UTF-8. More...
 
static std::string fileName (const std::string &path)
 Retrives the filename of a given file path in UTF-8, including extension. More...
 
static uintmax_t fileSize (const std::string &path)
 Returns the file size of a FILE in UTF-8. More...
 
static std::string getNativeSeparator ()
 Returns the native separator based on the Operational System. More...
 
static bool isDirectory (const std::string &path)
 Checks if a given path in UTF-8 is a directory. More...
 
static bool isEmpty (const std::string &path)
 Checks if a given path in UTF-8 is an empty directory. More...
 
static bool isRegularFile (const std::string &path)
 Checks if a given path in UTF-8 is a regular file. More...
 
static std::vector< std::string > listDirectory (const std::string &path)
 Lists a directory from a given path in UTF-8. More...
 
static std::string parentPath (const std::string &path)
 Retrives the parent path of a given file path in UTF-8. For /home/files/fileName.shp, it will return /home/files. More...
 
static std::string readFromFile (const std::string &filePath)
 Read file and returns the contents of the file. More...
 
static bool remove (const std::string &path)
 Removes a file or directory from a given path in UTF-8. More...
 
static void rename (const std::string &old_p, const std::string &new_p)
 Renames a file or directory from a given path in UTF-8. More...
 
static std::string stem (const std::string &path)
 Retrives the filename of a given file path in UTF-8, excluding extension. More...
 
static std::string systemCompletePath (const std::string &path)
 Composes an absolute path for the given path in UTF-8. More...
 
static std::string tempDirectoryPath ()
 Retrives the temp directory in UTF-8. More...
 
static std::string uniquePath (const std::string &format="%%%%-%%%%-%%%%-%%%%")
 Retrives an unique path generated by a given format. More...
 
static void writeToFile (const std::string &filePath, const std::string &content)
 will create a copy of the file before saving. More...
 

Private Member Functions

 FileSystem ()
 
 FileSystem (FileSystem const &)
 
FileSystemoperator= (FileSystem const &)
 
 ~FileSystem ()
 

Static Private Member Functions

static std::string createTempFileDirectoryPathString ()
 
static std::string createTempFilePathString (const std::string &filePath)
 
static std::string getFileContent (const std::string &filePath)
 Get file content. More...
 
static bool isBlank (const std::string &filePath)
 Checks whether the file contains full non-printable character content. More...
 
static bool isInvalid (const std::string &content)
 Checks whether the contents contains full non-printable character content. More...
 

Static Private Attributes

static boost::mutex mutexFileSystem
 Used to perform the tasks: write to file or read from file. More...
 

Detailed Description

A class for handling system files and paths using UTF-8 strings.

Definition at line 53 of file FileSystem.h.

Constructor & Destructor Documentation

◆ FileSystem() [1/2]

te::core::FileSystem::FileSystem ( )
private

◆ ~FileSystem()

te::core::FileSystem::~FileSystem ( )
private

◆ FileSystem() [2/2]

te::core::FileSystem::FileSystem ( FileSystem const &  )
private

Member Function Documentation

◆ absolutePath()

static std::string te::core::FileSystem::absolutePath ( const std::string &  path)
static

Retrives the absolute path for the given path in UTF-8.

Parameters
pathPath in UTF-8.
Returns
String in UTF-8 for the absolute path.

◆ adjustPathToGenericForm()

static std::string te::core::FileSystem::adjustPathToGenericForm ( const std::string &  filePath)
static

Adjusts the given path to generic form.

\description Documentation from Boost: In general, Boost.Filesystem differentiates between native paths and generic paths. Native paths are operating system specific and must be used when calling operating system functions. Generic paths are portable and independent of the operating system.

◆ adjustPathToNativeForm()

static std::string te::core::FileSystem::adjustPathToNativeForm ( const std::string &  filePath)
static

Adjusts the given path to native form.

\description Documentation from Boost: In general, Boost.Filesystem differentiates between native paths and generic paths. Native paths are operating system specific and must be used when calling operating system functions. Generic paths are portable and independent of the operating system.

◆ allocateTmpDiskFile()

static bool te::core::FileSystem::allocateTmpDiskFile ( unsigned long int  size,
FILE **  fileptr,
std::string &  fullFileName 
)
static

Create and allocate a new temporary disk file.

Parameters
sizeThe file size.
fileptrThe created file pointer.
fullFileNameThe full file name of the created file name.
Returns
true if OK. false on errors.
Note
The caller of this method is responsable for closing and deleting the created file.
A first attempty will try to create the file inside the user diretory, if it fails a second attempt will try the system temporary directory.

Referenced by te::rp::Matrix< TemplateElementType >::reset().

◆ copyFile()

static void te::core::FileSystem::copyFile ( const std::string &  from,
const std::string &  to 
)
static

Copies a file.

Parameters
fromPath in UTF-8 for the file to be copied.
toPath in UTF-8 for the copy output.

◆ createDirectories()

static bool te::core::FileSystem::createDirectories ( const std::string &  path)
static

Creates a directory for any element of path that does not exist.

Parameters
pathPath in UTF-8.
Returns
true if a new directory was created, otherwise false.

◆ createDirectory()

static bool te::core::FileSystem::createDirectory ( const std::string &  path)
static

Creates a directory from a given path in UTF-8.

Parameters
pathPath in UTF-8.
Returns
true if a new directory was created, otherwise false.

◆ createTempFileDirectoryPathString()

static std::string te::core::FileSystem::createTempFileDirectoryPathString ( )
staticprivate

◆ createTempFilePathString()

static std::string te::core::FileSystem::createTempFilePathString ( const std::string &  filePath)
staticprivate

◆ currentPath()

static std::string te::core::FileSystem::currentPath ( )
static

Retrives the current working directory path in UTF-8.

Returns
String in UTF-8 for the current working directory path.

◆ executableDirectory()

static std::string te::core::FileSystem::executableDirectory ( )
static

◆ exists()

static bool te::core::FileSystem::exists ( const std::string &  path)
static

Checks if a given path in UTF-8 exists.

Parameters
pathPath in UTF-8.
Returns
true if exists, otherwise false.

◆ extension()

static std::string te::core::FileSystem::extension ( const std::string &  path)
static

Retrives the extension of a given file path in UTF-8.

Parameters
pathFile path in UTF-8.
Returns
String in UTF-8 for the extension.

◆ fileName()

static std::string te::core::FileSystem::fileName ( const std::string &  path)
static

Retrives the filename of a given file path in UTF-8, including extension.

Parameters
pathFile path in UTF-8.
Returns
String in UTF-8 for the name of the file, including the extension.

◆ fileSize()

static uintmax_t te::core::FileSystem::fileSize ( const std::string &  path)
static

Returns the file size of a FILE in UTF-8.

Parameters
pathPath in UTF-8.
Returns
File size.
Exceptions
te::core::Exceptionif the given path doesn't exists or its used in a directory.

◆ getFileContent()

static std::string te::core::FileSystem::getFileContent ( const std::string &  filePath)
staticprivate

Get file content.

Parameters
filepath

◆ getNativeSeparator()

static std::string te::core::FileSystem::getNativeSeparator ( )
static

Returns the native separator based on the Operational System.

◆ isBlank()

static bool te::core::FileSystem::isBlank ( const std::string &  filePath)
staticprivate

Checks whether the file contains full non-printable character content.

Parameters
filepath

◆ isDirectory()

static bool te::core::FileSystem::isDirectory ( const std::string &  path)
static

Checks if a given path in UTF-8 is a directory.

Parameters
pathPath in UTF-8.
Returns
true if is a directory, otherwise false.

◆ isEmpty()

static bool te::core::FileSystem::isEmpty ( const std::string &  path)
static

Checks if a given path in UTF-8 is an empty directory.

Parameters
pathPath in UTF-8.
Returns
true if is a empty directory, otherwise false.

◆ isInvalid()

static bool te::core::FileSystem::isInvalid ( const std::string &  content)
staticprivate

Checks whether the contents contains full non-printable character content.

Parameters
filepath

◆ isRegularFile()

static bool te::core::FileSystem::isRegularFile ( const std::string &  path)
static

Checks if a given path in UTF-8 is a regular file.

Parameters
pathFile path in UTF-8.
Returns
true if is a regular file, otherwise false.

Referenced by te::common::ApplicationSettings::load().

◆ listDirectory()

static std::vector<std::string> te::core::FileSystem::listDirectory ( const std::string &  path)
static

Lists a directory from a given path in UTF-8.

Parameters
pathPath in UTF-8.
Returns
Vector of strings in UTF-8 for directory content.

◆ operator=()

FileSystem& te::core::FileSystem::operator= ( FileSystem const &  )
private

◆ parentPath()

static std::string te::core::FileSystem::parentPath ( const std::string &  path)
static

Retrives the parent path of a given file path in UTF-8. For /home/files/fileName.shp, it will return /home/files.

Parameters
pathFile path in UTF-8.
Returns
String in UTF-8 for the parent path of the give file path.

◆ readFromFile()

static std::string te::core::FileSystem::readFromFile ( const std::string &  filePath)
static

Read file and returns the contents of the file.

\description Read file, in case of corruption use the copy. Returns the contents of the file.

◆ remove()

static bool te::core::FileSystem::remove ( const std::string &  path)
static

Removes a file or directory from a given path in UTF-8.

Note
This function will not remove if the directory is not empty.
Parameters
pathPath in UTF-8.
Returns
false if path did not exist in the first place, otherwise true.

Referenced by te::common::ApplicationSettings::update().

◆ rename()

static void te::core::FileSystem::rename ( const std::string &  old_p,
const std::string &  new_p 
)
static

Renames a file or directory from a given path in UTF-8.

Parameters
old_pOld name in UTF-8.
new_pNew name in UTF-8.

◆ stem()

static std::string te::core::FileSystem::stem ( const std::string &  path)
static

Retrives the filename of a given file path in UTF-8, excluding extension.

Parameters
pathFile path in UTF-8.
Returns
String in UTF-8 for the name of the file, excluding the extension.

◆ systemCompletePath()

static std::string te::core::FileSystem::systemCompletePath ( const std::string &  path)
static

Composes an absolute path for the given path in UTF-8.

Parameters
pathPath in UTF-8.
Returns
String in UTF-8 for the composed path.

◆ tempDirectoryPath()

static std::string te::core::FileSystem::tempDirectoryPath ( )
static

Retrives the temp directory in UTF-8.

Returns
String in UTF-8 for temp directory.

◆ uniquePath()

static std::string te::core::FileSystem::uniquePath ( const std::string &  format = "%%%%-%%%%-%%%%-%%%%")
static

Retrives an unique path generated by a given format.

Parameters
formatThe format used to create a unique path. e.g.: "%%%%-%%%%-%%%%-%%%%"
Returns
String in UTF-8 for the generated unique path.

◆ writeToFile()

static void te::core::FileSystem::writeToFile ( const std::string &  filePath,
const std::string &  content 
)
static

will create a copy of the file before saving.

\description In the write to file, this method will create a copy of the file before saving. If it gets corrupted in the process, when using the read from file method will replace the corrupted file with the copy.

Member Data Documentation

◆ mutexFileSystem

boost::mutex te::core::FileSystem::mutexFileSystem
staticprivate

Used to perform the tasks: write to file or read from file.

Definition at line 341 of file FileSystem.h.


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