C++ Utilities  4.6.1
Common C++ classes and routines used by my applications such as argument parser, IO and conversion utilities
Classes | Typedefs | Enumerations | Functions
IoUtilities Namespace Reference

Contains utility classes helping to read and write streams. More...

Classes

class  BinaryReader
 Reads primitive data types from a std::istream. More...
 
class  BinaryWriter
 Writes primitive data types to a std::ostream. More...
 
class  BitReader
 The BitReader class provides bitwise reading of buffered data. More...
 
class  CopyHelper
 The CopyHelper class helps to copy bytes from one stream to another. More...
 
class  IniFile
 The IniFile class parses and makes INI files. More...
 

Typedefs

typedef std::fstream NativeFileStream
 

Enumerations

enum  DirectoryEntryType : unsigned char {
  DirectoryEntryType::None = 0, DirectoryEntryType::File = 1, DirectoryEntryType::Directory = 2, DirectoryEntryType::Symlink = 4,
  DirectoryEntryType::All = 0xFF
}
 The DirectoryEntryType enum specifies the type of a directory entry (file, directory or symlink). More...
 

Functions

constexpr DirectoryEntryType operator| (DirectoryEntryType lhs, DirectoryEntryType rhs)
 
DirectoryEntryTypeoperator|= (DirectoryEntryType &lhs, DirectoryEntryType rhs)
 
constexpr DirectoryEntryType operator & (DirectoryEntryType lhs, DirectoryEntryType rhs)
 
CPP_UTILITIES_EXPORT std::string fileName (const string &path)
 Returns the file name and extension of the specified path string. More...
 
CPP_UTILITIES_EXPORT std::string directory (const string &path)
 Returns the directory of the specified path string (including trailing slash). More...
 
CPP_UTILITIES_EXPORT void removeInvalidChars (std::string &fileName)
 Removes invalid characters from the specified fileName. More...
 
CPP_UTILITIES_EXPORT bool settingsDirectory (std::string &result, std::string applicationDirectoryName, bool createApplicationDirectory)
 Locates a directory meant to store application settings. More...
 
CPP_UTILITIES_EXPORT std::list< std::string > directoryEntries (const char *path, DirectoryEntryType types)
 Returns the names of the directory entries in the specified path with the specified types. More...
 
CPP_UTILITIES_EXPORT const char * catchIoFailure ()
 Provides a workaround for GCC Bug 66145. More...
 
CPP_UTILITIES_EXPORT void throwIoFailure (const char *what)
 Throws a std::ios_base::failure with the specified message. More...
 
CPP_UTILITIES_EXPORT std::string readFile (const string &path, std::string::size_type maxSize)
 Reads all contents of the specified file in a single call. More...
 

Detailed Description

Contains utility classes helping to read and write streams.

Typedef Documentation

◆ NativeFileStream

typedef std::fstream IoUtilities::NativeFileStream

Definition at line 19 of file nativefilestream.h.

Enumeration Type Documentation

◆ DirectoryEntryType

enum IoUtilities::DirectoryEntryType : unsigned char
strong

The DirectoryEntryType enum specifies the type of a directory entry (file, directory or symlink).

Enumerator
None 
File 
Directory 
Symlink 
All 

Definition at line 26 of file path.h.

Function Documentation

◆ catchIoFailure()

const char * IoUtilities::catchIoFailure ( )

Provides a workaround for GCC Bug 66145.

Returns
Returns the error message.
Exceptions
Throwsthe current exception if it is not std::ios_base::failure.

Definition at line 18 of file catchiofailure.cpp.

◆ directory()

string IoUtilities::directory ( const std::string &  path)

Returns the directory of the specified path string (including trailing slash).

Definition at line 52 of file path.cpp.

◆ directoryEntries()

std::list< std::string > IoUtilities::directoryEntries ( const char *  path,
DirectoryEntryType  types 
)

Returns the names of the directory entries in the specified path with the specified types.

Deprecated:
This function has FIXMEs. Since it can be replaced by using fs abstraction lib it is a good candidate for being replaced.

Definition at line 181 of file path.cpp.

◆ fileName()

string IoUtilities::fileName ( const std::string &  path)

Returns the file name and extension of the specified path string.

Definition at line 32 of file path.cpp.

◆ operator &()

constexpr DirectoryEntryType IoUtilities::operator& ( DirectoryEntryType  lhs,
DirectoryEntryType  rhs 
)

Definition at line 45 of file path.h.

◆ operator|()

constexpr DirectoryEntryType IoUtilities::operator| ( DirectoryEntryType  lhs,
DirectoryEntryType  rhs 
)

Definition at line 35 of file path.h.

◆ operator|=()

DirectoryEntryType& IoUtilities::operator|= ( DirectoryEntryType lhs,
DirectoryEntryType  rhs 
)
inline

Definition at line 40 of file path.h.

◆ readFile()

CPP_UTILITIES_EXPORT std::string IoUtilities::readFile ( const string &  path,
std::string::size_type  maxSize 
)

Reads all contents of the specified file in a single call.

Exceptions
Throwsstd::ios_base::failure when an error occurs or the specified maxSize would be exceeded.

Definition at line 16 of file misc.cpp.

◆ removeInvalidChars()

void IoUtilities::removeInvalidChars ( std::string &  fileName)

Removes invalid characters from the specified fileName.

The characters <, >, ?, !, *, |, /, :, \ and new lines are considered as invalid.

Definition at line 74 of file path.cpp.

◆ settingsDirectory()

bool IoUtilities::settingsDirectory ( std::string &  result,
std::string  applicationDirectoryName,
bool  createApplicationDirectory 
)

Locates a directory meant to store application settings.

Parameters
resultSpecifies a string to store the path in.
applicationDirectoryNameSpecifies the name for the application subdirectory.
createApplicationDirectoryIndicates wheter the application subdirectory should be created if not present.
Returns
Returns whether a settings directory could be located.
Deprecated:
This function has FIXMEs. Since it is not used a good candidate for being removed.

Definition at line 95 of file path.cpp.

◆ throwIoFailure()

void IoUtilities::throwIoFailure ( const char *  what)

Throws a std::ios_base::failure with the specified message.

Definition at line 30 of file catchiofailure.cpp.