Allolib  1.0
C++ Components For Interactive Multimedia
al::File Class Reference

File. More...

#include <C:/Users/Andres/source/repos/casm_viewer/external/tinc/external/allolib/include/al/io/al_File.hpp>

Public Member Functions

 File (std::string path=".", std::string mode="r", bool open_=false)
 
 File (const FilePath &path, std::string mode="r", bool open_=false)
 
bool open (const std::string &path, const std::string &mode="r")
 Open file. More...
 
bool open ()
 Open file using member variables. More...
 
void close ()
 Close file.
 
Filemode (const std::string &v)
 Set i/o mode. More...
 
Filepath (const std::string &v)
 Set path of file.
 
int write (const std::string &v)
 Write string to file.
 
int write (const void *v, int itemSizeInBytes, int items=1)
 Write memory elements to file.
 
int read (void *v, int size, int items=1)
 Read memory elements from file.
 
const char * readAll ()
 Returns character string of file contents (read mode only)
 
bool opened () const
 Returns whether file is open.
 
const std::string & mode () const
 Returns file i/o mode string.
 
const std::string & path () const
 Returns path string.
 
size_t size () const
 Returns size, in bytes, of file contents.
 
FILE * filePointer ()
 Return size file (or 0 on failure) More...
 

Static Public Member Functions

static std::string read (const std::string &path)
 Quick and dirty read of all bytes from file.
 
static int write (const std::string &path, const void *v, int size, int items=1)
 Quick and dirty write memory to file.
 
static int write (const std::string &path, const std::string &data)
 Quick and dirty write character string to file.
 
static bool copy (const std::string &srcPath, const std::string &dstPath, unsigned int bufferSize=1e6)
 
static bool remove (const std::string &path)
 Delete file from file system.
 
static std::string conformDirectory (const std::string &dir)
 Returns string ensured to having an ending delimiter. More...
 
static std::string conformPathToOS (const std::string &path)
 Conforms path. More...
 
static std::string absolutePath (const std::string &path)
 Convert relative paths to absolute paths.
 
static bool isRelativePath (const std::string &path)
 
static std::string currentPath ()
 
static bool isSamePath (const std::string &path1, const std::string &path2)
 
static std::string baseName (const std::string &path, const std::string &suffix="")
 Returns the base name of path. More...
 
static std::string directory (const std::string &path)
 Returns the directory part of path. More...
 
static std::string extension (const std::string &path)
 Returns extension of file name. More...
 
static bool exists (const std::string &path)
 Returns whether a file or directory exists.
 
static bool exists (const std::string &name, const std::string &path)
 Returns whether a file in a directory exists.
 
static bool isDirectory (const std::string &path)
 Returns true if path is a directory.
 
static bool searchBack (std::string &rootPath, const std::string &matchPath, int maxDepth=6)
 Search for file or directory back from current directory. More...
 
static bool searchBack (std::string &path, int maxDepth=6)
 
static al_sec modificationTime (const char *path)
 

Protected Member Functions

void dtor ()
 
void freeContent ()
 
void allocContent (int n)
 
void getSize ()
 

Protected Attributes

std::string mPath
 
std::string mMode
 
char * mContent
 
size_t mSizeBytes
 
FILE * mFP
 

Friends

class Dir
 

Detailed Description

File.

Used to retrieve data from and store data to disk. The term 'path' means a file or directory.

Definition at line 166 of file al_File.hpp.

Constructor & Destructor Documentation

◆ File()

al::File::File ( std::string  path = ".",
std::string  mode = "r",
bool  open_ = false 
)
Parameters
[in]pathpath of file
[in]modei/o mode "w", "r", "wb", "rb"
[in]openwhether to open the file

Member Function Documentation

◆ baseName()

static std::string al::File::baseName ( const std::string &  path,
const std::string &  suffix = "" 
)
static

Returns the base name of path.

The base name is everything following the last slash.

Parameters
[in]pathThe input path
[in]suffixAn optional suffix to strip from the end of the base name

◆ conformDirectory()

static std::string al::File::conformDirectory ( const std::string &  dir)
static

Returns string ensured to having an ending delimiter.

The directory string argument is not checked to actually exist in the file system.

◆ conformPathToOS()

static std::string al::File::conformPathToOS ( const std::string &  path)
static

Conforms path.

This function takes a path as an argument and returns a new path with correct platform-specific directory delimiters, '/' or '\' and an extra delimiter at the end if the argument is a valid directory.

◆ copy()

static bool al::File::copy ( const std::string &  srcPath,
const std::string &  dstPath,
unsigned int  bufferSize = 1e6 
)
static

Copy a file in srcPath to a new location. dstPath can be the new file name or the directory where the file is copied. Returns true when sucessful.

◆ currentPath()

static std::string al::File::currentPath ( )
static

Returns current path in filesystem This function should be replaced when moved to C++17 to std::filesystem::current_path()

◆ directory()

static std::string al::File::directory ( const std::string &  path)
static

Returns the directory part of path.

The directory part of the path is everything up through (and including) the last slash in it. If the path contains no slash, the directory part is the string './'. E.g., /usr/bin/man -> /usr/bin/.

◆ extension()

static std::string al::File::extension ( const std::string &  path)
static

Returns extension of file name.

The extension is everything including and after the last period. If there is no period, an empty string is returned.

◆ filePointer()

FILE* al::File::filePointer ( )
inline

Return size file (or 0 on failure)

Return modification time of file (or 0 on failure) as number of seconds since 00:00:00 January 1, 1970 UTC Return last access time of file (or 0 on failure) as number of seconds since 00:00:00 January 1, 1970 UTC Return creation time of file (or 0 on failure) as number of seconds since 00:00:00 January 1, 1970 UTC Return space used on disk of file (or 0 on failure)

Definition at line 257 of file al_File.hpp.

◆ mode()

File& al::File::mode ( const std::string &  v)
inline

Set i/o mode.

Parameters
[in]vA string indicating the i/o mode.

Definition at line 196 of file al_File.hpp.

◆ open() [1/2]

bool al::File::open ( )

Open file using member variables.

Returns
true on success, false otherwise

◆ open() [2/2]

bool al::File::open ( const std::string &  path,
const std::string &  mode = "r" 
)

Open file.

Parameters
[in]pathpath of file
[in]modei/o mode "w", "r", "wb", "rb"
Returns
true on success, false otherwise

◆ searchBack() [1/2]

static bool al::File::searchBack ( std::string &  path,
int  maxDepth = 6 
)
static

Search for file or directory back from current directory

Parameters
[in,out]pathInput is a file or directory to search for. If the file is found, the output contains a series of "../" prefixed to the input. Otherwise, the input path is not modified.
[in]maxDepthMaximum number of directories to search back
Returns
whether the file or directory was found

◆ searchBack() [2/2]

static bool al::File::searchBack ( std::string &  rootPath,
const std::string &  matchPath,
int  maxDepth = 6 
)
static

Search for file or directory back from current directory.

Parameters
[in,out]rootPathThe input should contain the path to search relative to. If the input is empty, then "./" is assumed. If a match is made, then the output is a string that can be prefixed to 'matchPath' to get the actual location of the match.
[in]matchPathFile or directory to search for
[in]maxDepthMaximum number of directories to search back
Returns
whether the file or directory was found

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