Ocean
Ocean::IO::Directory Class Reference

This class holds a directory. More...

Inheritance diagram for Ocean::IO::Directory:

Public Member Functions

 Directory ()
 Creates an empty directory. More...
 
 Directory (const std::string &path)
 Creates a new directory. More...
 
 Directory (const File &file)
 Creates a new directory by a given file. More...
 
 Directory (const Path &path)
 Creates a new directory by a given path. More...
 
virtual bool isValid () const
 Returns whether the directory is valid. More...
 
virtual bool exists () const
 Returns whether the directory exists already. More...
 
bool remove (const bool recursively=false) const
 Removes this directory from the filesystem. More...
 
bool create () const
 Create all necessary sub-directories for the given path, if they do not exist. More...
 
std::string base () const
 Returns the base of this directory. More...
 
std::string name () const
 Returns the name of a directory. More...
 
Files findFiles (const std::string &fileType=std::string("*"), const bool recursive=false) const
 Returns all files in the directory with the given file format. More...
 
Directories findDirectories (const bool recursive=false) const
 Returns all directories of this directory. More...
 
File operator+ (const File &file) const
 Returns a file composed of this directory and a relative file. More...
 
Directory operator+ (const Directory &path) const
 Returns a directory composed of this and a relative directory. More...
 
Directoryoperator+= (const Directory &path)
 Adds an relative path to this directory. More...
 
Directoryoperator-- ()
 Removes the last sub-directory from this directory. More...
 
Directory operator-- (int)
 Removes the last sub-directory from this directory. More...
 
- Public Member Functions inherited from Ocean::IO::Path
virtual ~Path ()=default
 Destructs a path. More...
 
Type type () const
 Returns the type of this path. More...
 
bool isAbsolute () const
 Returns whether this path is absolute. More...
 
bool isRelative () const
 Returns whether this path is relative. More...
 
bool isNull () const
 Returns whether this path holds no valid. More...
 
bool operator== (const Path &right) const
 Returns whether two paths are equal. More...
 
bool operator!= (const Path &path) const
 Returns whether two paths are not equal. More...
 
const std::string & operator() () const
 Returns the value of this path. More...
 
bool operator< (const Path &path) const
 Less operator comparing the actual strings of two paths. More...
 

Static Public Member Functions

static Directory createTemporaryDirectory ()
 Creates a new temporary directory. More...
 
- Static Public Member Functions inherited from Ocean::IO::Path
static bool isSeparator (const char character)
 Returns whether a given character is a separator. More...
 
static char defaultSeparator ()
 Returns the default separator of a path. More...
 

Static Protected Member Functions

static Directory createTemporaryDirectoryApple ()
 Creates a new temporary directory (specialization for Apple platforms). More...
 
static bool existsApple (const std::string &directory)
 Returns whether a directory exists (specialization for Apple platforms). More...
 

Additional Inherited Members

- Public Types inherited from Ocean::IO::Path
enum  Type {
  TYPE_INVALID = 0 , TYPE_FILE = 1 , TYPE_DIRECTORY = 2 , TYPE_ABSOLUTE = 4 ,
  TYPE_RELATIVE = 8 , TYPE_NETWORK = 16
}
 Definition of different path types. More...
 
enum  Separator { SEPARATOR_UNDEFINED = 0 , SEPARATOR_SLASH = '/' , SEPARATOR_BACKSLASH = '\\' }
 Definition of path separators. More...
 
- Protected Member Functions inherited from Ocean::IO::Path
 Path ()=default
 Creates a new undefined path. More...
 
 Path (const Path &path)=default
 Copy constructor. More...
 
 Path (const std::string &value)
 Creates a new path. More...
 
void checkPath (const Type expectType)
 Checks the type of this path and trims it. More...
 
void trim ()
 Trims this path. More...
 
Pathoperator= (const Path &path)=default
 Default assign operator. More...
 
- Protected Attributes inherited from Ocean::IO::Path
Type pathType_ = TYPE_INVALID
 Path type. More...
 
std::string pathValue_
 Path value. More...
 

Detailed Description

This class holds a directory.

Valid directories will end with a separator.

Constructor & Destructor Documentation

◆ Directory() [1/4]

Ocean::IO::Directory::Directory ( )

Creates an empty directory.

◆ Directory() [2/4]

Ocean::IO::Directory::Directory ( const std::string &  path)
explicit

Creates a new directory.

Parameters
pathDirectory path

◆ Directory() [3/4]

Ocean::IO::Directory::Directory ( const File file)
explicit

Creates a new directory by a given file.

Parameters
fileFile to get the directory from

◆ Directory() [4/4]

Ocean::IO::Directory::Directory ( const Path path)
explicit

Creates a new directory by a given path.

Parameters
pathPath to create a directory from

Member Function Documentation

◆ base()

std::string Ocean::IO::Directory::base ( ) const

Returns the base of this directory.

The directory's base is the entire directory path without the ending separator.
The base of e.g. "/path/to/foo/bar/" is "/path/to/foo/bar"

Returns
The directory's base

◆ create()

bool Ocean::IO::Directory::create ( ) const

Create all necessary sub-directories for the given path, if they do not exist.

Returns
True, if succeeded

◆ createTemporaryDirectory()

static Directory Ocean::IO::Directory::createTemporaryDirectory ( )
static

Creates a new temporary directory.

The directory will be created as a sub-directory inside of a OS-specific temporary files path.

Returns
Created temporary directory if the operation succeeded; otherwise, an empty file path is returned.

◆ createTemporaryDirectoryApple()

static Directory Ocean::IO::Directory::createTemporaryDirectoryApple ( )
staticprotected

Creates a new temporary directory (specialization for Apple platforms).

The directory will be created as a sub-directory inside of a OS-specific temporary files path.

See also
createTemporaryDirectory()
Returns
Created temporary directory if the operation succeeded; otherwise, an empty file path is returned.

◆ exists()

virtual bool Ocean::IO::Directory::exists ( ) const
virtual

Returns whether the directory exists already.

See also
Path::exists().

Implements Ocean::IO::Path.

◆ existsApple()

static bool Ocean::IO::Directory::existsApple ( const std::string &  directory)
staticprotected

Returns whether a directory exists (specialization for Apple platforms).

Parameters
directoryDirectory to check
Returns
True, if so

◆ findDirectories()

Directories Ocean::IO::Directory::findDirectories ( const bool  recursive = false) const

Returns all directories of this directory.

Parameters
recursiveTrue, to find sub-directories as well; False, to find direct child directories only
Returns
List of existing directories

◆ findFiles()

Files Ocean::IO::Directory::findFiles ( const std::string &  fileType = std::string("*"),
const bool  recursive = false 
) const

Returns all files in the directory with the given file format.

Parameters
fileTypeFile type to find files for, for example "png", "txt", or "json". Use "*" to list all files.
recursiveTrue, to find file in all possible sub-directories; False, to find files in this directory only
Returns
List of existing files

◆ isValid()

virtual bool Ocean::IO::Directory::isValid ( ) const
virtual

Returns whether the directory is valid.

See also
Path::isValid().

Implements Ocean::IO::Path.

◆ name()

std::string Ocean::IO::Directory::name ( ) const

Returns the name of a directory.

Returns
The name of a directory, e.g., for "/path/to/foo/bar/" it returns "bar"; will be empty if the directory doesn't exist or is invalid

◆ operator+() [1/2]

Directory Ocean::IO::Directory::operator+ ( const Directory path) const

Returns a directory composed of this and a relative directory.

Parameters
pathRelative path to add
Returns
New created directory

◆ operator+() [2/2]

File Ocean::IO::Directory::operator+ ( const File file) const

Returns a file composed of this directory and a relative file.

Parameters
fileRelative file
Returns
New created file

◆ operator+=()

Directory& Ocean::IO::Directory::operator+= ( const Directory path)

Adds an relative path to this directory.

Parameters
pathRelative path to add
Returns
Reference to the new path

◆ operator--() [1/2]

Directory& Ocean::IO::Directory::operator-- ( )

Removes the last sub-directory from this directory.

Returns
Reference to the modified path

◆ operator--() [2/2]

Directory Ocean::IO::Directory::operator-- ( int  )

Removes the last sub-directory from this directory.

Returns
A copy of this directory before the last sub-directory was removed

◆ remove()

bool Ocean::IO::Directory::remove ( const bool  recursively = false) const

Removes this directory from the filesystem.

Parameters
recursivelyTrue, to remove all sub-directories and their files recursively; False, to remove only this directory if empty
Returns
True, if succeeded
See also
exists().

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