Fawkes API  Fawkes Development Version
fawkes::File Class Reference

File utility methods. More...

#include <utils/system/file.h>

Public Types

enum  FileOpenMethod { OVERWRITE, APPEND, ADD_SUFFIX }
 What to do when a file with the same name already exists. More...
 

Public Member Functions

 File (const char *filename, FileOpenMethod method=APPEND)
 Constructor. More...
 
 ~File ()
 Destructor. More...
 
FILE * stream () const
 Get access to the file stream. More...
 
const char * filename () const
 Get the file's name. More...
 

Static Public Member Functions

static bool exists (const char *filename)
 Check if a file exists. More...
 
static bool is_regular (const char *filename)
 Check if a file is a regular file. More...
 

Detailed Description

File utility methods.

Allows for opening a file and provides utilities to check if a file exists or whether it is a regular file (and not a symbolic link/directory).

Author
Tim Niemueller
Daniel Beck

Definition at line 38 of file file.h.

Member Enumeration Documentation

◆ FileOpenMethod

What to do when a file with the same name already exists.

Enumerator
OVERWRITE 

overwrite the existing file

APPEND 

append data at the end of the existing file

ADD_SUFFIX 

add a suffix (starting with ".1") to the given filename

Definition at line 44 of file file.h.

Constructor & Destructor Documentation

◆ File()

fawkes::File::File ( const char *  filename,
FileOpenMethod  method = APPEND 
)

Constructor.

Independent of the FileOpenMethod files are created with permissions 660

Parameters
filenamethe filename
methodthe method determines what is done if a file with the specified name already exists

Definition at line 71 of file file.cpp.

References exists(), and fawkes::UnableToOpenFileException::UnableToOpenFileException().

◆ ~File()

fawkes::File::~File ( )

Destructor.

Definition at line 117 of file file.cpp.

Member Function Documentation

◆ exists()

bool fawkes::File::exists ( const char *  filename)
static

Check if a file exists.

Parameters
filenamethe name of the file to check
Returns
true, if the file exists, false otherwise

Definition at line 149 of file file.cpp.

Referenced by File().

◆ filename()

const char * fawkes::File::filename ( ) const

Get the file's name.

Returns
a pointer to a char array where the filename is stored

Definition at line 138 of file file.cpp.

◆ is_regular()

bool fawkes::File::is_regular ( const char *  filename)
static

Check if a file is a regular file.

Parameters
filenamethe name of the file to check
Returns
true, if the given path points to a regular file, false otherwise

Definition at line 160 of file file.cpp.

Referenced by fawkes::Module::open().

◆ stream()

FILE * fawkes::File::stream ( ) const

Get access to the file stream.

Returns
a pointer to the file stream

Definition at line 129 of file file.cpp.


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