Evo C++ Library v0.5.1
Public Member Functions | List of all members
Directory Class Reference

#include <evo/dir.h>

Inheritance diagram for Directory:
Inheritance graph
[legend]

Detailed Description

Directory reader.

Example
#include <evo/dir.h>
#include <evo/io.h>
using namespace evo;
int main() {
SubString filename;
try {
Directory dir(".");
while (dir.read(filename))
con().out << filename << NL;
} EVO_CATCH(return 1);
return 0;
}

Public Member Functions

 Directory (bool excep=1)
 Constructor. More...
 
 Directory (const char *path, bool excep=1)
 Constructor to open directory. More...
 
bool chdir ()
 Change current working directory to currently open directory (Linux/Unix only). More...
 
void close ()
 Close currently open directory, if any. More...
 
Error error () const
 Get error code from last operation. More...
 
bool excep () const
 Get whether exceptions are enabled. More...
 
void excep (bool val)
 Set whether exceptions are enabled. More...
 
bool isopen () const
 Get whether directory is open. More...
 
bool open (const char *path)
 Open directory for reading entries. More...
 
 operator SafeBoolType () const
 Safe (explicit) evaluation as bool type. More...
 
bool operator! () const
 Negation operator checks whether an error was set by a previous operation. More...
 
bool read (SubString &entry)
 Read next directory entry. More...
 
void seek ()
 Seek to beginning of directory. More...
 

Constructor & Destructor Documentation

◆ Directory() [1/2]

Directory ( bool  excep = 1)
inline

Constructor.

Parameters
excepWhether to enable exceptions on error, default set by Evo config: EVO_EXCEPTIONS

◆ Directory() [2/2]

Directory ( const char *  path,
bool  excep = 1 
)
inline

Constructor to open directory.

Parameters
pathDirectory path to open
excepWhether to enable exceptions on error, default set by Evo config: EVO_EXCEPTIONS

Member Function Documentation

◆ chdir()

bool chdir ( )
inline

Change current working directory to currently open directory (Linux/Unix only).

Returns
Whether successful, false if directory not open or permission denied

◆ close()

void close ( )
inline

Close currently open directory, if any.

◆ error()

Error error ( ) const
inline

Get error code from last operation.

Returns
Error code, ENone for success (no error)

◆ excep() [1/2]

bool excep ( ) const
inline

Get whether exceptions are enabled.

Returns
Whether exceptions enabled

◆ excep() [2/2]

void excep ( bool  val)
inline

Set whether exceptions are enabled.

Parameters
valWhether to enable exceptions

◆ isopen()

bool isopen ( ) const
inline

Get whether directory is open.

Returns
Whether open

◆ open()

bool open ( const char *  path)
inline

Open directory for reading entries.

Parameters
pathDirectory path to open
Returns
Whether successful, false on error – call error() for error code

◆ operator SafeBoolType()

operator SafeBoolType ( ) const
inlineinherited

Safe (explicit) evaluation as bool type.

  • This is called when object is directly evaluated as a bool, and is equivalent to: !operator!()
  • See SafeBool

◆ operator!()

bool operator! ( ) const
inline

Negation operator checks whether an error was set by a previous operation.

  • Call error() to get last error code
  • Alternatively, use SafeBool evaluation to check whether previous operations were successful
Returns
Whether last operation set an error

◆ read()

bool read ( SubString entry)
inline

Read next directory entry.

  • Call seek() to move back to the first entry
  • Caution: Result string will reference internal memory that will be invalid on next read() or on close()
Parameters
entrySubString to store the entry, set to null after last entry [out]
Returns
Whether entry read, false if no more entries

◆ seek()

void seek ( )
inline

Seek to beginning of directory.

  • After this read() will return entries from the beginning

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