C++ Utilities  4.17.0
Useful C++ classes and routines 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

using NativeFileStream = std::fstream
 

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 an 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

using IoUtilities::NativeFileStream = typedef std::fstream

Definition at line 76 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.
Remarks
  • GCC Bug 66145 is "resolved", but the story continues with GCC Bug 85222.
  • However, the bug finally got fixed for 7.4 and 8.1 so this workaround can be dropped in the next major release which also drops support for older libstdc++ versions.
See also

Definition at line 36 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 38 of file path.h.

◆ operator|()

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

Definition at line 28 of file path.h.

◆ operator|=()

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

Definition at line 33 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 an std::ios_base::failure with the specified message.

See also
catchIoFailure()

Definition at line 49 of file catchiofailure.cpp.