ADTF  3.18.2
a_util::filesystem Namespace Reference

Serves as component for path and filesystem functionality. More...

Classes

class  PathException
 Exception class used by Path methods. More...
 
class  Path
 File/Directory path class. More...
 

Enumerations

enum  Error {
  OK , OPEN_FAILED , GENERAL_FAILURE , IO_ERROR ,
  INVALID_PATH , ACCESS_DENIED
}
 Enumerates possible error values for filesystem interaction. More...
 
enum  EnumDirFlags { ED_FILES = 0x1 , ED_DIRECTORIES = 0x2 }
 Enumeration for possible listings in a directory, usable in function enumDirectory() More...
 
enum class  DiffOptions : std::uint64_t { none = 0 }
 Available options for operations comparing files or directories. More...
 

Functions

Path getTempDirectory ()
 Retrieve path to the temp directory of the system. More...
 
Path getWorkingDirectory ()
 Retrieve path to the working directory of the current process. More...
 
Error setWorkingDirectory (const Path &path)
 Set the working directory. More...
 
Error readTextFile (const Path &file_path, std::string &content)
 Read entire content of a text file into a string. More...
 
Error readTextLines (const Path &file_path, std::vector< std::string > &vec_lines)
 Read entire content of a text file and split it every new line, dropping the EOL characters. More...
 
Error writeTextFile (const Path &file_path, const std::string &content)
 Open a file in mode 'w' and write new content to it. More...
 
Error enumDirectory (const Path &dir_path, std::vector< Path > &vec_entries, std::int32_t flags=ED_FILES|ED_DIRECTORIES)
 List all entries in a directory. More...
 
bool exists (const Path &path)
 Check whether the file or directory exists on the filesystem. More...
 
bool createDirectory (const Path &path)
 Create a new directory on the filesystem. More...
 
bool isFile (const Path &file_path)
 Check whether the path points to a file on the filesystem. More...
 
bool isDirectory (const Path &dir_path)
 Check whether the path points to a directory on the filesystem. More...
 
bool remove (const Path &path)
 Remove the file or directory pointed to by path. More...
 
bool rename (const Path &path, const Path &new_path)
 Rename or move a file or directory from path to new_path. More...
 
std::int64_t compareFiles (const Path &p1, const Path &p2)
 Compare content of two files. More...
 
std::int64_t compareFiles (const Path &p1, const Path &p2, DiffOptions options)
 Compare content of two files. More...
 
bool operator== (const Path &lhs, const Path &rhs)
 Check two paths for equality. More...
 
bool operator!= (const Path &lhs, const Path &rhs)
 Check two paths for inequality. More...
 
std::ostream & operator<< (std::ostream &os, const Path &p)
 Performs stream output on the path p. More...
 
Path operator+ (const Path &a, const Path &b)
 Appends two paths, forming a new path. More...
 

Detailed Description

Serves as component for path and filesystem functionality.

Enumeration Type Documentation

◆ DiffOptions

enum DiffOptions : std::uint64_t
strong

Available options for operations comparing files or directories.

Enumerator
none 

Default behavior; needs to be specified by the using function.

Definition at line 47 of file workspace/conan/dev_essential/1.3.3/dw/stable/package/37682420cd166e229516a41c8d6a139a0b13e1e1/include/a_util/filesystem/filesystem.h.

◆ EnumDirFlags

Enumeration for possible listings in a directory, usable in function enumDirectory()

Enumerator
ED_FILES 

List files in the directory.

ED_DIRECTORIES 

List directories in the directory.

Definition at line 37 of file workspace/conan/dev_essential/1.3.3/dw/stable/package/37682420cd166e229516a41c8d6a139a0b13e1e1/include/a_util/filesystem/filesystem.h.

◆ Error

enum Error

Enumerates possible error values for filesystem interaction.

Enumerator
OK 

No error, basically meaning success.

OPEN_FAILED 

Opening a file or folder from the filesystem failed.

GENERAL_FAILURE 

General errors.

IO_ERROR 

Input/output error during filesystem access.

INVALID_PATH 

Accessed path on the filesystem is invalid.

ACCESS_DENIED 

Access to file or folder in the filesystem denied.

Definition at line 27 of file workspace/conan/dev_essential/1.3.3/dw/stable/package/37682420cd166e229516a41c8d6a139a0b13e1e1/include/a_util/filesystem/filesystem.h.

Function Documentation

◆ compareFiles() [1/2]

std::int64_t a_util::filesystem::compareFiles ( const Path p1,
const Path p2 
)

Compare content of two files.

Parameters
[in]p1Path to first file.
[in]p2Path to second file.
Return values
0File contents are equal or p1 and p2 are the same file.
>0Position of the first different character in the files.
<0Comparison not possible, e.g. file does not exist or path is a directory.
Exceptions
ios_base::failureexception if cannot open the file, or try to access character after the end of file, or no character were written or error was set in ifstream.

◆ compareFiles() [2/2]

std::int64_t a_util::filesystem::compareFiles ( const Path p1,
const Path p2,
DiffOptions  options 
)

Compare content of two files.

Parameters
[in]optionsOptions controlling the behavior of the diff operation. Supported options:
[in]p1Path to first file.
[in]p2Path to second file.
Return values
0File contents are equal or p1 and p2 are the same file.
>0Position of the first different character in the files.
<0Comparison not possible, e.g. file does not exist or path is a directory.
Exceptions
ios_base::failureexception if cannot open the file, or try to access character after the end of file, or no character were written or error was set in ifstream.

◆ createDirectory()

bool a_util::filesystem::createDirectory ( const Path path)

Create a new directory on the filesystem.

Note
All given non-existing subdirectories are created as well
Parameters
[in]pathPath to the directory to create
Returns
true if the directory was created or already exists, false otherwise

◆ enumDirectory()

Error a_util::filesystem::enumDirectory ( const Path dir_path,
std::vector< Path > &  vec_entries,
std::int32_t  flags = ED_FILES|ED_DIRECTORIES 
)

List all entries in a directory.

Parameters
[in]dir_pathPath to the directory to list the entries from
[out]vec_entriesAll entries listed in the directory
[in]flagsEnumDirFlags filtering what to list in the directory
Return values
INVALID_PATHThe path does not exist or is not a directory
GENERAL_FAILURESome unknown error while listing entries in the directory occurred
OKEntries listed successfully, with the list being copied to vec_entries

◆ exists()

bool a_util::filesystem::exists ( const Path path)

Check whether the file or directory exists on the filesystem.

Parameters
[in]pathPath to the file or directory
Returns
true if the path exists, false otherwise

◆ getTempDirectory()

Path a_util::filesystem::getTempDirectory ( )

Retrieve path to the temp directory of the system.

Returns
Temp directory of the system

◆ getWorkingDirectory()

Path getWorkingDirectory ( )

Retrieve path to the working directory of the current process.

Returns
Current working directory path

◆ isDirectory()

bool a_util::filesystem::isDirectory ( const Path dir_path)

Check whether the path points to a directory on the filesystem.

Parameters
[in]dir_pathPath to the directory to check
Returns
true if the path points to a directory, false otherwise

◆ isFile()

bool a_util::filesystem::isFile ( const Path file_path)

Check whether the path points to a file on the filesystem.

Parameters
[in]file_pathPath to the file to check
Returns
true if the path points to a file, false otherwise

◆ operator!=()

bool a_util::filesystem::operator!= ( const Path lhs,
const Path rhs 
)

Check two paths for inequality.

Note
The paths are compared syntactically, any canonicalization must be done manually!
Parameters
[in]lhsRight hand side object
[in]rhsLeft hand side object
Return values
trueif the paths are not equal, false otherwise

◆ operator+()

Path a_util::filesystem::operator+ ( const Path a,
const Path b 
)

Appends two paths, forming a new path.

Parameters
[in]aThe left path
[in]bThe right path
Return values
Anew path combined from a and b (or empty, in case of an error)

◆ operator<<()

std::ostream& a_util::filesystem::operator<< ( std::ostream &  os,
const Path p 
)

Performs stream output on the path p.

Note
The implemenation simply calls toString() without arguments.
This mean that this operator doesn't support a non-default separator
Parameters
[in]osthe output stream
[in]ppath to print
Return values
theoutput stream

◆ operator==()

bool a_util::filesystem::operator== ( const Path lhs,
const Path rhs 
)

Check two paths for equality.

Note
The paths are compared syntactically, any canonicalization must be done manually!
Parameters
[in]lhsRight hand side object
[in]rhsLeft hand side object
Return values
trueif the paths are equal, false otherwise

◆ readTextFile()

Error a_util::filesystem::readTextFile ( const Path file_path,
std::string &  content 
)

Read entire content of a text file into a string.

Parameters
[in]file_pathPath to the file to be read
[out]contentDestination string to be filled
Return values
OPEN_FAILEDFile could not be opened
GENERAL_FAILURESeeking the file did not succeed
IO_ERRORSome I/O error occurred while reading the file
OKContent successfully read and copied to out parameter content

◆ readTextLines()

Error a_util::filesystem::readTextLines ( const Path file_path,
std::vector< std::string > &  vec_lines 
)

Read entire content of a text file and split it every new line, dropping the EOL characters.

Parameters
[in]file_pathPath to the file to be read
[out]vec_linesVector of strings with each string containing one line of the file
Returns
Same values documented in readTextFile()

◆ remove()

bool a_util::filesystem::remove ( const Path path)

Remove the file or directory pointed to by path.

Note
Directories and their content are deleted recursively.
Parameters
[in]pathPath to the element to be deleted.
Returns
true if the element could be deleted, false otherwise.

◆ rename()

bool a_util::filesystem::rename ( const Path path,
const Path new_path 
)

Rename or move a file or directory from path to new_path.

Parameters
[in]pathPath to the file or directory to be renamed or moved.
[in]new_pathPath the file or directory is renamed of moved to.
Returns
true on success, false otherwise.

◆ setWorkingDirectory()

Error a_util::filesystem::setWorkingDirectory ( const Path path)

Set the working directory.

Parameters
[in]pathPath to the new working directory
Return values
INVALID_PATHThe path is invalid/nonexisting or a file path
GENERAL_FAILUREThe OS failed to set the working directory
OKWorking directory was successfully set

◆ writeTextFile()

Error a_util::filesystem::writeTextFile ( const Path file_path,
const std::string &  content 
)

Open a file in mode 'w' and write new content to it.

Parameters
[in]file_pathPath to the file to (over-)write
[in]contentContent to write to the file
Return values
OPEN_FAILEDFile could not be opened
IO_ERRORSome I/O error occurred while writing the file
OKContent successfully read and copied to out parameter content