C++ Utilities 5.26.1
Useful C++ classes and routines such as argument parser, IO and conversion utilities
Loading...
Searching...
No Matches
CppUtilities Namespace Reference

Contains all utilities provides by the c++utilities library. More...

Namespaces

namespace  BE
 Encapsulates binary conversion functions using the big endian byte order.
 
namespace  EscapeCodes
 Encapsulates functions for formatted terminal output using ANSI escape codes.
 
namespace  FlagEnumClassOperations
 The FlagEnumClassOperations namespace contains operations for flag enums.
 
namespace  LE
 Encapsulates binary conversion functions using the little endian byte order.
 
namespace  Literals
 Contains literals to ease asserting with CPPUNIT_ASSERT_EQUAL.
 
namespace  Traits
 Contains traits for conveniently exploiting SFINAE.
 
namespace  ValueConversion
 Contains functions to convert raw argument values to certain types.
 

Classes

class  AdvancedIniFile
 The AdvancedIniFile class allows parsing and writing INI files. More...
 
struct  ApplicationInfo
 Stores information about an application. More...
 
class  ArchiveException
 The ArchiveException class is thrown by the various archiving-related functions of this library when a conversion error occurs. More...
 
struct  ArchiveFile
 The ArchiveFile class holds data about a file within an archive. More...
 
class  Argument
 The Argument class is a wrapper for command line argument information. More...
 
struct  ArgumentCompletionInfo
 The ArgumentCompletionInfo struct holds information internally used for shell completion and suggestions. More...
 
struct  ArgumentOccurrence
 The ArgumentOccurrence struct holds argument values for an occurrence of an argument. More...
 
class  ArgumentParser
 The ArgumentParser class provides a means for handling command line arguments. More...
 
class  ArgumentReader
 The ArgumentReader class internally encapsulates the process of reading command line arguments. More...
 
struct  ArrayBasedMultiArray
 The ArrayBasedMultiArray struct allows using a fixed size array as underlying container for the MultiArray class. More...
 
class  AsHexNumber
 The AsHexNumber class allows printing values asserted with cppunit (or similar test framework) using the hex system in the error case. More...
 
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  BufferSearch
 The BufferSearch struct invokes a callback if an initially given search term occurs in consecutively provided buffers. More...
 
class  ConfigValueArgument
 The ConfigValueArgument class is an Argument where setCombinable() is true by default. More...
 
class  ConversionException
 The ConversionException class is thrown by the various conversion functions of this library when a conversion error occurs. More...
 
class  CopyHelper
 The CopyHelper class helps to copy bytes from one stream to another. More...
 
class  DateTime
 Represents an instant in time, typically expressed as a date and time of day. More...
 
struct  DateTimeExpression
 The DateTimeExpression struct holds information about a time expression (e.g. More...
 
class  FakeQtConfigArguments
 The FakeQtConfigArguments class provides arguments for the Qt GUI used when the application hasn't been built with Qt GUI support. More...
 
class  HelpArgument
 The HelpArgument class prints help information for an argument parser when present (–help, -h). More...
 
class  Indentation
 The Indentation class allows printing indentation conveniently, eg. More...
 
class  IniFile
 The IniFile class allows parsing and writing INI files. More...
 
struct  IsFlagEnumClass
 The IsFlagEnumClass class is used to decide whether to enable operations for flag enums for. More...
 
class  MultiArray
 The MultiArray class provides an N-dimensional array. More...
 
class  NoColorArgument
 The NoColorArgument class allows to specify whether use of escape codes or similar technique to provide formatted output on the terminal should be enabled/disabled. More...
 
struct  NoneOwningMultiArray
 The NoneOwningMultiArray struct allows using a caller-managed buffer array as underlying container for the MultiArray class. More...
 
class  OperationArgument
 The OperationArgument class is an Argument where denotesOperation() is true by default. More...
 
class  OutputCheck
 The StandardOutputCheck class asserts whether the (standard) output written in the enclosing code block matches the expected output. More...
 
class  ParseError
 The ParseError class is thrown by an ArgumentParser when a parsing error occurs. More...
 
class  Period
 Represents a period of time. More...
 
struct  StringDataDeleter
 The StringDataDeleter struct deletes the data of a StringData instance. More...
 
struct  TerminalSize
 The TerminalSize struct describes a terminal size. More...
 
class  TestApplication
 The TestApplication class simplifies writing test applications that require opening test files. More...
 
class  TimeSpan
 Represents a time interval. More...
 
struct  VectorBasedMultiArray
 The VectorBasedMultiArray struct allows using an std::vector with custom allocator as underlying container for the MultiArray class. More...
 
struct  VectorBasedMultiArray< void >
 The VectorBasedMultiArray struct allows using an std::vector as underlying container for the MultiArray class. More...
 
class  Wrapper
 The Wrapper class is internally used print text which might needs to be wrapped preserving the indentation. More...
 

Typedefs

using ArgumentInitializerList = std::initializer_list<Argument *>
 
using ArgumentVector = std::vector<Argument *>
 
using ArgumentPredicate = std::function<bool(Argument *)>
 
using StringData = std::pair<std::unique_ptr<char[], StringDataDeleter>, std::size_t>
 Type used to return string encoding conversion result.
 
using PathValueType
 The native type used by std::filesystem:path.
 
using NativePathString = std::basic_string<PathValueType>
 The string type used to store paths in the native encoding.
 
using NativePathStringView = std::basic_string_view<PathValueType>
 The string view type used to pass paths in the native encoding.
 
using PathString = std::string
 The string type used to store paths UTF-8 encoded.
 
using PathStringView = std::string_view
 The string view type used to pass paths UTF-8 encoded.
 
using NativeFileStream = std::fstream
 
using FileMap = std::map<std::string, std::vector<ArchiveFile>>
 A map of files extracted from an archive. Keys represent directories and values files within those directories.
 
using FilePredicate = std::function<bool(const char *, const char *, mode_t)>
 A function that is invoked for each file within an archive. If it returns true, the file is considered; otherwise the file is ignored.
 
using DirectoryHandler = std::function<bool(std::string_view path)>
 A function that is invoked by the walk-through-functions to return a directory.
 
using FileHandler = std::function<bool(std::string_view path, ArchiveFile &&file)>
 A function that is invoked by the walk-through-functions to return a file.
 

Enumerations

enum class  UnknownArgumentBehavior { Ignore , Warn , Fail }
 The UnknownArgumentBehavior enum specifies the behavior of the argument parser when an unknown argument is detected. More...
 
enum class  ParseArgumentBehavior { ReadArguments = 0x0 , CheckConstraints = 0x1 , InvokeCallbacks = 0x2 , ExitOnFailure = 0x4 }
 The ParseArgumentBehavior enum specifies the behavior when parsing arguments. More...
 
enum class  ValueCompletionBehavior : unsigned char {
  None = 0 , PreDefinedValues = 2 , Files = 4 , Directories = 8 ,
  FileSystemIfNoPreDefinedValues = 16 , AppendEquationSign = 32 , InvokeCallback = 64
}
 The ValueCompletionBehavior enum specifies the items to be considered when generating completion for an argument value. More...
 
enum class  Response { None , Yes , No }
 The Response enum is used to specify the default response for the confirmPrompt() method. More...
 
enum class  DateTimeOutputFormat {
  DateAndTime , DateOnly , TimeOnly , DateTimeAndWeekday ,
  DateTimeAndShortWeekday , Iso , IsoOmittingDefaultComponents
}
 Specifies the output format. More...
 
enum class  DayOfWeek {
  Monday , Tuesday , Wednesday , Thursday ,
  Friday , Saturday , Sunday
}
 Specifies the day of the week. More...
 
enum class  DatePart { Year , Month , DayOfYear , Day }
 Specifies the date part. More...
 
enum class  DateTimeParts : std::uint64_t {
  None = 0 , Year = (1 << 0) , Month = (1 << 1) , Day = (1 << 2) ,
  Hour = (1 << 3) , Minute = (1 << 4) , Second = (1 << 5) , SubSecond = (1 << 6) ,
  DeltaHour = (1 << 7) , DeltaMinute = (1 << 8) , Date = Year | Month | Day , Time = Hour | Minute | Second | SubSecond ,
  DateTime = Date | Time , TimeZoneDelta = DeltaHour | DeltaMinute , All = DateTime | TimeZoneDelta
}
 The DateTimeParts enum specifies which parts of a timestamp are present. More...
 
enum class  TimeSpanOutputFormat { Normal , WithMeasures , TotalSeconds }
 Specifies the output format. More...
 
enum class  EmptyPartsTreat { Keep , Omit , Merge }
 Specifies the role of empty parts when splitting strings. More...
 
enum class  IniFileParseOptions { None = 0 }
 
enum class  IniFileMakeOptions { None = 0 }
 
enum class  IniFileFieldFlags { None = 0 , HasValue = (1 << 0) }
 
enum class  IniFileSectionFlags { None = 0 , Implicit = (1 << 0) , Truncated = (1 << 1) }
 
enum class  WorkingCopyMode { CreateCopy , NoCopy , Cleanup }
 The WorkingCopyMode enum specifies additional options to influence behavior of TestApplication::workingCopyPath(). More...
 
enum  ArgumentDenotationType : unsigned char { Value = 0 , Abbreviation = 1 , FullName = 2 }
 The ArgumentDenotationType enum specifies the type of a given argument denotation. More...
 
enum class  ArchiveFileType { Regular , Link }
 The ArchiveFileType enum specifies the type of a file within an archive. More...
 

Functions

CPP_UTILITIES_EXPORT bool confirmPrompt (const char *message, Response defaultResponse)
 Prompts for confirmation displaying the specified message.
 
CPP_UTILITIES_EXPORT std::optional< bool > isEnvVariableSet (const char *variableName)
 Returns whether the specified env variable is set to a non-zero and non-white-space-only value.
 
CPP_UTILITIES_EXPORT TerminalSize determineTerminalSize ()
 Returns the current size of the terminal.
 
CPP_UTILITIES_EXPORT std::ostream & operator<< (std::ostream &out, Indentation indentation)
 
CPP_UTILITIES_EXPORT DateTime operator+ (DateTime begin, Period period)
 Adds the specified period to the specified date.
 
CPP_UTILITIES_EXPORT constexpr std::uint16_t toFixed8 (float float32value)
 Returns the 8.8 fixed point representation converted from the specified 32-bit floating point number.
 
CPP_UTILITIES_EXPORT constexpr float toFloat32 (std::uint16_t fixed8value)
 Returns a 32-bit floating point number converted from the specified 8.8 fixed point representation.
 
CPP_UTILITIES_EXPORT constexpr std::uint32_t toFixed16 (float float32value)
 Returns the 16.16 fixed point representation converted from the specified 32-bit floating point number.
 
CPP_UTILITIES_EXPORT constexpr float toFloat32 (std::uint32_t fixed16value)
 Returns a 32-bit floating point number converted from the specified 16.16 fixed point representation.
 
CPP_UTILITIES_EXPORT constexpr std::uint32_t toSynchsafeInt (std::uint32_t normalInt)
 Returns a 32-bit synchsafe integer converted from a normal 32-bit integer.
 
CPP_UTILITIES_EXPORT constexpr std::uint32_t toNormalInt (std::uint32_t synchsafeInt)
 Returns a normal 32-bit integer converted from a 32-bit synchsafe integer.
 
CPP_UTILITIES_EXPORT constexpr std::uint16_t swapOrder (std::uint16_t value)
 Swaps the byte order of the specified 16-bit unsigned integer.
 
CPP_UTILITIES_EXPORT constexpr std::uint32_t swapOrder (std::uint32_t value)
 Swaps the byte order of the specified 32-bit unsigned integer.
 
CPP_UTILITIES_EXPORT constexpr std::uint64_t swapOrder (std::uint64_t value)
 Swaps the byte order of the specified 64-bit unsigned integer.
 
CPP_UTILITIES_EXPORT constexpr std::int16_t swapOrder (std::int16_t value)
 Swaps the byte order of the specified 16-bit integer.
 
CPP_UTILITIES_EXPORT constexpr std::int32_t swapOrder (std::int32_t value)
 Swaps the byte order of the specified 32-bit integer.
 
CPP_UTILITIES_EXPORT constexpr std::int64_t swapOrder (std::int64_t value)
 Swaps the byte order of the specified 64-bit integer.
 
CPP_UTILITIES_EXPORT StringData convertString (const char *fromCharset, const char *toCharset, const char *inputBuffer, std::size_t inputBufferSize, float outputBufferSizeFactor)
 Converts the specified string from one character set to another.
 
CPP_UTILITIES_EXPORT StringData convertUtf8ToUtf16LE (const char *inputBuffer, std::size_t inputBufferSize)
 Converts the specified UTF-8 string to UTF-16 (little-endian).
 
CPP_UTILITIES_EXPORT StringData convertUtf16LEToUtf8 (const char *inputBuffer, std::size_t inputBufferSize)
 Converts the specified UTF-16 (little-endian) string to UTF-8.
 
CPP_UTILITIES_EXPORT StringData convertUtf8ToUtf16BE (const char *inputBuffer, std::size_t inputBufferSize)
 Converts the specified UTF-8 string to UTF-16 (big-endian).
 
CPP_UTILITIES_EXPORT StringData convertUtf16BEToUtf8 (const char *inputBuffer, std::size_t inputBufferSize)
 Converts the specified UTF-16 (big-endian) string to UTF-8.
 
CPP_UTILITIES_EXPORT StringData convertLatin1ToUtf8 (const char *inputBuffer, std::size_t inputBufferSize)
 Converts the specified Latin-1 string to UTF-8.
 
CPP_UTILITIES_EXPORT StringData convertUtf8ToLatin1 (const char *inputBuffer, std::size_t inputBufferSize)
 Converts the specified UTF-8 string to Latin-1.
 
CPP_UTILITIES_EXPORT void truncateString (string &str, char terminationChar)
 Truncates all characters after the first occurrence of the specified terminationChar and the termination character as well.
 
template<class Container = std::initializer_list<std::string>, class ReturnType = Detail::DefaultReturnTypeForContainer<Container>>
ReturnType joinStrings (const Container &strings, Detail::StringParamForContainer< Container > delimiter=Detail::StringParamForContainer< Container >(), bool omitEmpty=false, Detail::StringParamForContainer< Container > leftClosure=Detail::StringParamForContainer< Container >(), Detail::StringParamForContainer< Container > rightClosure=Detail::StringParamForContainer< Container >())
 Joins the given strings using the specified delimiter.
 
template<class Container = std::initializer_list<std::string>>
auto toMultiline (const Container &arrayOfLines)
 Converts the specified arrayOfLines to a multiline string.
 
template<class Container = std::list<std::string>>
Container splitString (Detail::StringParamForContainer< Container > string, Detail::StringParamForContainer< Container > delimiter, EmptyPartsTreat emptyPartsRole=EmptyPartsTreat::Keep, int maxParts=-1)
 Splits the given string at the specified delimiter.
 
template<class Container = std::list<std::string>>
Container splitStringSimple (Detail::StringParamForContainer< Container > string, Detail::StringParamForContainer< Container > delimiter, int maxParts=-1)
 Splits the given string (which might also be a string view) at the specified delimiter.
 
template<class Container = std::vector<std::string>>
auto toArrayOfLines (const std::string &multilineString)
 Converts the specified multilineString to an array of lines.
 
template<typename StringType >
bool startsWith (const StringType &str, const StringType &phrase)
 Returns whether str starts with phrase.
 
template<typename StringType >
bool startsWith (const StringType &str, const typename StringType::value_type *phrase)
 Returns whether str starts with phrase.
 
template<typename StringType >
bool endsWith (const StringType &str, const StringType &phrase)
 Returns whether str ends with phrase.
 
template<typename StringType >
bool endsWith (const StringType &str, const typename StringType::value_type *phrase)
 Returns whether str ends with phrase.
 
template<typename StringType >
bool containsSubstrings (const StringType &str, std::initializer_list< StringType > substrings)
 Returns whether str contains the specified substrings.
 
template<typename StringType >
bool containsSubstrings (const StringType &str, std::initializer_list< const typename StringType::value_type * > substrings)
 Returns whether str contains the specified substrings.
 
template<typename StringType1 , typename StringType2 , typename StringType3 >
void findAndReplace (StringType1 &str, const StringType2 &find, const StringType3 &replace)
 Replaces all occurrences of find with relpace in the specified str.
 
template<typename StringType >
void findAndReplace (StringType &str, const typename StringType::value_type *find, const typename StringType::value_type *replace)
 Replaces all occurrences of find with relpace in the specified str.
 
template<typename StringType1 , typename StringType2 >
void findAndReplace (StringType1 &str, const StringType2 &find, const typename StringType1::value_type *replace)
 Replaces all occurrences of find with relpace in the specified str.
 
template<typename StringType1 , typename StringType2 >
void findAndReplace (StringType1 &str, const typename StringType1::value_type *find, const StringType2 &replace)
 Replaces all occurrences of find with relpace in the specified str.
 
template<typename CharType >
constexpr CharType digitToChar (CharType digit)
 Returns the character representation of the specified digit.
 
template<typename IntegralType , class StringType = std::string, typename BaseType = IntegralType, CppUtilities::Traits::EnableIf< std::is_integral< IntegralType >, std::is_unsigned< IntegralType > > * = nullptr>
StringType numberToString (IntegralType number, BaseType base=10)
 Converts the given number to its equivalent string representation using the specified base.
 
template<typename FloatingType , class StringType = std::string, Traits::EnableIf< std::is_floating_point< FloatingType > > * = nullptr>
StringType numberToString (FloatingType number, int base=10)
 Converts the given number to its equivalent string representation using the specified base.
 
template<typename CharType >
CharType charToDigit (CharType character, CharType base)
 Returns number/digit of the specified character representation using the specified base.
 
template<typename IntegralType , class CharType , typename BaseType = IntegralType, Traits::EnableIf< std::is_integral< IntegralType >, std::is_unsigned< IntegralType > > * = nullptr>
IntegralType bufferToNumber (const CharType *string, std::size_t size, BaseType base=10)
 Converts the given string of size characters to an unsigned numeric value using the specified base.
 
template<typename IntegralType , class StringType , typename BaseType = IntegralType, Traits::EnableIf< std::is_integral< IntegralType >, Traits::Not< std::is_scalar< std::decay_t< StringType > > > > * = nullptr>
IntegralType stringToNumber (const StringType &string, BaseType base=10)
 Converts the given string to an unsigned/signed number assuming string uses the specified base.
 
template<typename FloatingType , class StringViewType , Traits::EnableIf< std::is_floating_point< FloatingType >, Traits::IsSpecializationOf< StringViewType, std::basic_string_view > > * = nullptr>
FloatingType stringToNumber (StringViewType stringView, int base=10)
 Converts the given stringView to a number assuming stringView uses the specified base.
 
template<typename FloatingType , class StringType , Traits::EnableIf< std::is_floating_point< FloatingType >, Traits::Not< std::is_scalar< std::decay_t< StringType > > >, Traits::Not< Traits::IsSpecializationOf< StringType, std::basic_string_view > > > * = nullptr>
FloatingType stringToNumber (const StringType &string, int base=10)
 Converts the given string to a number assuming string uses the specified base.
 
template<typename IntegralType , typename CharType , typename BaseType = IntegralType, Traits::EnableIf< std::is_integral< IntegralType >, std::is_unsigned< IntegralType > > * = nullptr>
IntegralType stringToNumber (const CharType *string, BaseType base=10)
 Converts the given null-terminated string to an unsigned numeric value using the specified base.
 
template<typename FloatingType , class CharType , Traits::EnableIf< std::is_floating_point< FloatingType > > * = nullptr>
FloatingType stringToNumber (const CharType *string, int base=10)
 Converts the given null-terminated string to a number assuming string uses the specified base.
 
template<typename IntegralType , typename CharType , typename BaseType = IntegralType, Traits::EnableIf< std::is_integral< IntegralType >, std::is_signed< IntegralType > > * = nullptr>
IntegralType stringToNumber (const CharType *string, IntegralType base=10)
 Converts the given null-terminated string to a signed numeric value using the specified base.
 
template<typename T >
std::string interpretIntegerAsString (T integer, int startOffset=0)
 Interprets the given integer at the specified position as std::string using the specified byte order.
 
CPP_UTILITIES_EXPORT std::string dataSizeToString (std::uint64_t sizeInByte, bool includeByte)
 Converts the specified data size in byte to its equivalent std::string representation.
 
CPP_UTILITIES_EXPORT std::string bitrateToString (double bitrateInKbitsPerSecond, bool useIecBinaryPrefixes)
 Converts the specified bitrate in kbit/s to its equivalent std::string representation.
 
CPP_UTILITIES_EXPORT std::string encodeBase64 (const std::uint8_t *data, std::uint32_t dataSize)
 Encodes the specified data to Base64.
 
CPP_UTILITIES_EXPORT std::pair< std::unique_ptr< std::uint8_t[]>, std::uint32_t > decodeBase64 (const char *encodedStr, const std::uint32_t strSize)
 Decodes the specified Base64 encoded string.
 
template<class StringType = std::string, class... Args>
StringType tupleToString (const std::tuple< Args... > &tuple)
 Concatenates all strings hold by the specified tuple.
 
template<class StringType = std::string, class... Args>
StringType argsToString (Args &&...args)
 
template<class Tuple , class StringType , Traits::EnableIf< Traits::IsSpecializationOf< Tuple, std::tuple >, Traits::IsSpecializingAnyOf< StringType, std::basic_string, std::basic_string_view > > * = nullptr>
constexpr auto operator% (const Tuple &lhs, const StringType &rhs) -> decltype(std::tuple_cat(lhs, std::tuple< const StringType & >(rhs)))
 Allows construction of string-tuples via %-operator, eg.
 
template<class Tuple , Traits::EnableIf< Traits::IsSpecializationOf< Tuple, std::tuple > > * = nullptr>
constexpr auto operator% (const Tuple &lhs, const char *rhs) -> decltype(std::tuple_cat(lhs, std::tuple< const char * >(rhs)))
 Allows construction of string-tuples via %-operator, eg.
 
template<class Tuple , typename IntegralType , Traits::EnableIf< Traits::IsSpecializationOf< Tuple, std::tuple >, std::is_integral< IntegralType > > * = nullptr>
constexpr auto operator% (const Tuple &lhs, IntegralType rhs) -> decltype(std::tuple_cat(lhs, std::tuple< IntegralType >(rhs)))
 Allows construction of string-tuples via %-operator, eg.
 
template<class StringType , Traits::EnableIfAny< Traits::IsSpecializationOf< StringType, std::basic_string >, Traits::IsSpecializationOf< StringType, std::basic_string_view > > * = nullptr>
constexpr auto operator% (const StringType &lhs, const StringType &rhs) -> decltype(std::tuple< const StringType &, const StringType & >(lhs, rhs))
 Allows construction of string-tuples via %-operator, eg.
 
template<class StringType , Traits::EnableIfAny< Traits::IsSpecializationOf< StringType, std::basic_string >, Traits::IsSpecializationOf< StringType, std::basic_string_view > > * = nullptr>
constexpr auto operator% (const char *lhs, const StringType &rhs) -> decltype(std::tuple< const char *, const StringType & >(lhs, rhs))
 Allows construction of string-tuples via %-operator, eg.
 
template<class StringType , Traits::EnableIfAny< Traits::IsSpecializationOf< StringType, std::basic_string >, Traits::IsSpecializationOf< StringType, std::basic_string_view > > * = nullptr>
constexpr auto operator% (const StringType &lhs, const char *rhs) -> decltype(std::tuple< const StringType &, const char * >(lhs, rhs))
 Allows construction of string-tuples via %-operator, eg.
 
template<class StringType , Traits::EnableIfAny< Traits::IsSpecializationOf< StringType, std::basic_string >, Traits::IsSpecializationOf< StringType, std::basic_string_view > > * = nullptr>
constexpr auto operator% (const StringType &lhs, char rhs) -> decltype(std::tuple< const StringType &, char >(lhs, rhs))
 Allows construction of string-tuples via %-operator, eg.
 
template<class StringType , Traits::EnableIfAny< Traits::IsSpecializationOf< StringType, std::basic_string >, Traits::IsSpecializationOf< StringType, std::basic_string_view > > * = nullptr>
constexpr auto operator% (char lhs, const StringType &rhs) -> decltype(std::tuple< char, const StringType & >(lhs, rhs))
 Allows construction of string-tuples via %-operator, eg.
 
template<class Tuple , class StringType , Traits::EnableIf< Traits::IsSpecializationOf< Tuple, std::tuple >, Traits::Any< Traits::IsSpecializationOf< StringType, std::basic_string >, Traits::IsSpecializationOf< StringType, std::basic_string_view > > > * = nullptr>
std::string operator+ (const Tuple &lhs, const StringType &rhs)
 Allows construction of final string from previously constructed string-tuple and trailing string via +-operator.
 
template<class Tuple , Traits::EnableIf< Traits::IsSpecializationOf< Tuple, std::tuple > > * = nullptr>
std::string operator+ (const Tuple &lhs, const char *rhs)
 Allows construction of final string from previously constructed string-tuple and trailing string via +-operator.
 
template<class Tuple , typename IntegralType , Traits::EnableIf< Traits::IsSpecializationOf< Tuple, std::tuple >, std::is_integral< IntegralType > > * = nullptr>
std::string operator+ (const Tuple &lhs, IntegralType rhs)
 Allows construction of final string from previously constructed string-tuple and trailing char via +-operator.
 
CPP_UTILITIES_EXPORT std::string fileName (const std::string &path)
 Returns the file name and extension of the specified path string.
 
CPP_UTILITIES_EXPORT std::string directory (const std::string &path)
 Returns the directory of the specified path string (including trailing slash).
 
CPP_UTILITIES_EXPORT void removeInvalidChars (std::string &fileName)
 Removes invalid characters from the specified fileName.
 
NativePathStringView makeNativePath (PathStringView path)
 Returns path in the platform's native encoding.
 
PathStringView extractNativePath (NativePathStringView path)
 Returns path as UTF-8 string or string view.
 
CPP_UTILITIES_EXPORT std::string readFile (const std::string &path, std::string::size_type maxSize)
 Reads all contents of the specified file in a single call.
 
CPP_UTILITIES_EXPORT void writeFile (std::string_view path, std::string_view contents)
 Writes all contents to the specified file in a single call.
 
template<typename FlagEnumClass , Traits::EnableIf< IsFlagEnumClass< FlagEnumClass > > * = nullptr>
constexpr FlagEnumClass & modFlagEnum (FlagEnumClass &flagVariable, FlagEnumClass relevantFlags, bool value)
 Sets the specified relevantFlags in the specified flagVariable to the specified value.
 
template<typename FlagEnumClass , Traits::EnableIf< IsFlagEnumClass< FlagEnumClass > > * = nullptr>
constexpr bool checkFlagEnum (FlagEnumClass flagVariable, FlagEnumClass flagsToCheck)
 Returns whether the specified flagVariable has set all flags specified via flagsToCheck to true.
 
template<typename IntegralType , Traits::EnableIf< std::is_integral< IntegralType > > * = nullptr>
constexpr IntegralType digitsum (IntegralType number, IntegralType base=10)
 Returns the digitsum of the given number using the specified base.
 
template<typename IntegralType , Traits::EnableIf< std::is_integral< IntegralType > > * = nullptr>
constexpr IntegralType factorial (IntegralType number)
 Returns the factorial of the given number.
 
template<typename IntegralType , Traits::EnableIf< std::is_integral< IntegralType >, std::is_unsigned< IntegralType > > * = nullptr>
constexpr IntegralType powerModulo (const IntegralType base, const IntegralType exponent, const IntegralType module)
 Computes base power exponent modulo module.
 
template<typename IntegralType , Traits::EnableIf< std::is_integral< IntegralType >, std::is_unsigned< IntegralType > > * = nullptr>
constexpr IntegralType inverseModulo (IntegralType number, IntegralType module)
 Computes the inverse of number modulo module.
 
template<typename IntegralType , Traits::EnableIf< std::is_integral< IntegralType >, std::is_unsigned< IntegralType > > * = nullptr>
constexpr IntegralType orderModulo (const IntegralType number, const IntegralType module)
 Computes the order of number modulo module.
 
template<typename T >
constexpr T min (T first, T second)
 Returns the smallest of the given items.
 
template<typename T1 , typename... T2>
constexpr T1 min (T1 first, T1 second, T2... remaining)
 Returns the smallest of the given items.
 
template<typename T >
constexpr T max (T first, T second)
 Returns the greatest of the given items.
 
template<typename T1 , typename... T2>
constexpr T1 max (T1 first, T1 second, T2... remaining)
 Returns the greatest of the given items.
 
template<typename ValueType , typename... DimensionSizes>
auto makeMultiArray (DimensionSizes... dimensionSizes)
 Constructs a new N-dimensional array using an std::vector with std::allocator as underlying container. The sizes for the dimensions are passed as arguments.
 
template<typename ValueType , std::size_t size, typename... DimensionSizes>
auto makeFixedSizeMultiArray (DimensionSizes... dimensionSizes)
 Constructs a new N-dimensional array using a fixed size array as underlying container. The sizes for the dimensions are passed as arguments.
 
template<typename ValueType , typename... DimensionSizes>
auto makeNoneOwningMultiArray (DimensionSizes... dimensionSizes)
 Constructs a new N-dimensional array using a caller-managed buffer as underlying container. The sizes for the dimensions are passed as arguments.
 
CPP_UTILITIES_EXPORT std::ostream & operator<< (std::ostream &o, const ParseError &failure)
 Prints an error message "Unable to parse arguments: ..." for the specified failure.
 
CPP_UTILITIES_EXPORT std::size_t computeDamerauLevenshteinDistance (const char *str1, std::size_t size1, const char *str2, std::size_t size2)
 
std::size_t computeDamerauLevenshteinDistance (const std::string &str1, const std::string &str2)
 
std::size_t computeDamerauLevenshteinDistance (const char *str1, const char *str2)
 
CPP_UTILITIES_EXPORT std::string testFilePath (const std::string &relativeTestFilePath)
 Convenience function to invoke TestApplication::testFilePath().
 
CPP_UTILITIES_EXPORT std::string testDirPath (const std::string &relativeTestDirPath)
 Convenience function to invoke TestApplication::testDirPath().
 
CPP_UTILITIES_EXPORT std::string workingCopyPath (const std::string &relativeTestFilePath, WorkingCopyMode mode=WorkingCopyMode::CreateCopy)
 Convenience function to invoke TestApplication::workingCopyPath().
 
CPP_UTILITIES_EXPORT std::string workingCopyPathAs (const std::string &relativeTestFilePath, const std::string &relativeWorkingCopyPath, WorkingCopyMode mode=WorkingCopyMode::CreateCopy)
 Convenience function to invoke TestApplication::workingCopyPathAs().
 
template<typename Optional , Traits::EnableIf< Traits::IsSpecializationOf< Optional, std::optional > > * = nullptr>
std::ostream & operator<< (std::ostream &out, const Optional &optional)
 Allows printing std::optional objects so those can be asserted using CPPUNIT_ASSERT_EQUAL.
 
template<typename T >
bool operator== (const AsHexNumber< T > &lhs, const AsHexNumber< T > &rhs)
 Provides operator == required by CPPUNIT_ASSERT_EQUAL.
 
template<typename T >
std::ostream & operator<< (std::ostream &out, const AsHexNumber< T > &value)
 Provides the actual formatting of the output for AsHexNumber class.
 
template<typename T >
AsHexNumber< T > asHexNumber (const T &value)
 Wraps a value to be printed using the hex system in the error case when asserted with cppunit (or similar test framework).
 
template<typename T , Traits::EnableIf< std::is_integral< T > > * = nullptr>
AsHexNumber< T > integralsAsHexNumber (const T &value)
 Wraps a value to be printed using the hex system in the error case when asserted with cppunit (or similar test framework).
 
template<typename T , Traits::DisableIf< std::is_integral< T > > * = nullptr>
const T & integralsAsHexNumber (const T &value)
 Wraps a value to be printed using the hex system in the error case when asserted with cppunit (or similar test framework).
 
template<typename Pair , CppUtilities::Traits::EnableIf< CppUtilities::Traits::IsSpecializationOf< Pair, std::pair > > * = nullptr>
std::ostream & operator<< (std::ostream &out, const Pair &pair)
 Allows printing pairs so key/values of maps/hashes can be asserted using CPPUNIT_ASSERT_EQUAL.
 
template<typename Iteratable , Traits::EnableIf< Traits::IsIteratable< Iteratable >, Traits::Not< Traits::IsString< Iteratable > > > * = nullptr>
std::ostream & operator<< (std::ostream &out, const Iteratable &iteratable)
 Allows printing iteratable objects so those can be asserted using CPPUNIT_ASSERT_EQUAL.
 
std::ostream & operator<< (std::ostream &os, const Wrapper &wrapper)
 
ArgumentfirstPresentUncombinableArg (const ArgumentVector &args, const Argument *except)
 This function return the first present and uncombinable argument of the given list of arguments.
 
bool compareArgs (const Argument *arg1, const Argument *arg2)
 Returns whether arg1 should be listed before arg2 when printing completion.
 
void insertSiblings (const ArgumentVector &siblings, list< const Argument * > &target)
 Inserts the specified siblings in the target list.
 
template<typename num1 , typename num2 , typename num3 >
constexpr bool inRangeInclMax (num1 val, num2 min, num3 max)
 
template<typename num1 , typename num2 , typename num3 >
constexpr bool inRangeExclMax (num1 val, num2 min, num3 max)
 
std::string_view fileName (std::string_view path)
 Returns the file name and extension of the specified path string.
 
std::string_view directory (std::string_view path)
 Returns the directory of the specified path string (including trailing slash).
 
std::string readFile (std::string_view path, std::string_view::size_type maxSize)
 Reads all contents of the specified file in a single call.
 
std::size_t computeDamerauLevenshteinDistance (const char *const str1, const size_t size1, const char *const str2, const size_t size2)
 Computes Damerau–Levenshtein distance with adjacent transpositions.
 
CPP_UTILITIES_EXPORT FileMap extractFiles (std::string_view archivePath, const FilePredicate &isFileRelevant)
 Extracts the specified archive.
 
CPP_UTILITIES_EXPORT void walkThroughArchive (std::string_view archivePath, const FilePredicate &isFileRelevant, FileHandler &&fileHandler, DirectoryHandler &&directoryHandler)
 Invokes callbacks for files and directories in the specified archive.
 
CPP_UTILITIES_EXPORT FileMap extractFilesFromBuffer (std::string_view archiveData, std::string_view archiveName, const FilePredicate &isFileRelevant)
 Extracts the specified archive.
 
CPP_UTILITIES_EXPORT void walkThroughArchiveFromBuffer (std::string_view archiveData, std::string_view archiveName, const FilePredicate &isFileRelevant, FileHandler &&fileHandler, DirectoryHandler &&directoryHandler)
 Invokes callbacks for files and directories in the specified archive.
 

Variables

CPP_UTILITIES_EXPORT ApplicationInfo applicationInfo
 Stores global application info used by ArgumentParser::printHelp() and AboutDialog.
 

Detailed Description

Contains all utilities provides by the c++utilities library.

Contains classes and functions utilizing creating of test applications.

Typedef Documentation

◆ ArgumentInitializerList

using CppUtilities::ArgumentInitializerList = std::initializer_list<Argument *>

Definition at line 68 of file argumentparser.h.

◆ ArgumentPredicate

using CppUtilities::ArgumentPredicate = std::function<bool(Argument *)>

Definition at line 70 of file argumentparser.h.

◆ ArgumentVector

using CppUtilities::ArgumentVector = std::vector<Argument *>

Definition at line 69 of file argumentparser.h.

◆ DirectoryHandler

using CppUtilities::DirectoryHandler = std::function<bool(std::string_view path)>

A function that is invoked by the walk-through-functions to return a directory.

Definition at line 74 of file archive.h.

◆ FileHandler

using CppUtilities::FileHandler = std::function<bool(std::string_view path, ArchiveFile &&file)>

A function that is invoked by the walk-through-functions to return a file.

Definition at line 76 of file archive.h.

◆ FileMap

using CppUtilities::FileMap = std::map<std::string, std::vector<ArchiveFile>>

A map of files extracted from an archive. Keys represent directories and values files within those directories.

Definition at line 70 of file archive.h.

◆ FilePredicate

using CppUtilities::FilePredicate = std::function<bool(const char *, const char *, mode_t)>

A function that is invoked for each file within an archive. If it returns true, the file is considered; otherwise the file is ignored.

Definition at line 72 of file archive.h.

◆ NativeFileStream

using CppUtilities::NativeFileStream = std::fstream

Definition at line 131 of file nativefilestream.h.

◆ NativePathString

using CppUtilities::NativePathString = std::basic_string<PathValueType>

The string type used to store paths in the native encoding.

Remarks
This type is used to store paths when interfacing with native APIs.

Definition at line 54 of file path.h.

◆ NativePathStringView

using CppUtilities::NativePathStringView = std::basic_string_view<PathValueType>

The string view type used to pass paths in the native encoding.

Remarks
This type is used to pass paths when interfacing with native APIs.

Definition at line 57 of file path.h.

◆ PathString

using CppUtilities::PathString = std::string

The string type used to store paths UTF-8 encoded.

Remarks
This type is used to store paths everywhere except when interfacing directly with native APIs.

Definition at line 60 of file path.h.

◆ PathStringView

using CppUtilities::PathStringView = std::string_view

The string view type used to pass paths UTF-8 encoded.

Remarks
This type is used to pass paths everywhere except when interfacing directly with native APIs.

Definition at line 63 of file path.h.

◆ PathValueType

Initial value:
char

The native type used by std::filesystem:path.

Remarks
The current implementation requires this to be always wchar_t on Windows and char otherwise.

Definition at line 41 of file path.h.

◆ StringData

using CppUtilities::StringData = std::pair<std::unique_ptr<char[], StringDataDeleter>, std::size_t>

Type used to return string encoding conversion result.

Definition at line 47 of file stringconversion.h.

Enumeration Type Documentation

◆ ArchiveFileType

enum class CppUtilities::ArchiveFileType
strong

The ArchiveFileType enum specifies the type of a file within an archive.

Enumerator
Regular 
Link 

Definition at line 47 of file archive.h.

◆ ArgumentDenotationType

The ArgumentDenotationType enum specifies the type of a given argument denotation.

Enumerator
Value 

parameter value

Abbreviation 

argument abbreviation

FullName 

full argument name

Definition at line 38 of file argumentparser.cpp.

◆ DatePart

enum class CppUtilities::DatePart
strong

Specifies the date part.

Remarks
Intended for internal use only.
See also
DateTime::getDatePart()
Enumerator
Year 

year

Month 

month

DayOfYear 

day of year

Day 

day

Definition at line 48 of file datetime.h.

◆ DateTimeOutputFormat

Specifies the output format.

See also
DateTime::toString()
Enumerator
DateAndTime 

date and time

DateOnly 

date only

TimeOnly 

time only

DateTimeAndWeekday 

date with weekday and time

DateTimeAndShortWeekday 

date with abbreviated weekday and time

Iso 

ISO format like DateTime::toIsoString()

IsoOmittingDefaultComponents 

ISO format like DateTime::toIsoString() omitting default components, e.g. just "2017" instead of "2017-01-01T00:00:00"

Definition at line 19 of file datetime.h.

◆ DateTimeParts

enum class CppUtilities::DateTimeParts : std::uint64_t
strong

The DateTimeParts enum specifies which parts of a timestamp are present.

Enumerator
None 

no parts are present

Year 

the year is present

Month 

the month is present

Day 

the day is present

Hour 

the hour is present

Minute 

the minute is present

Second 

the second is present

SubSecond 

the second contains a fractional part

DeltaHour 

the timezone-delta hour is present

DeltaMinute 

the timezone-delta minute is present

Date 

year, month and day are present

Time 

hour, minute and (sub)second are present

DateTime 

all parts a DateTime object can represent are present

TimeZoneDelta 

the timezone-delta hour and minute are present

All 

all parts a DateTime object can represent plus the full timezone-delta are present

Definition at line 145 of file datetime.h.

◆ DayOfWeek

enum class CppUtilities::DayOfWeek
strong

Specifies the day of the week.

See also
DateTime::dayOfWeek()
Enumerator
Monday 

Monday

Tuesday 

Tuesday

Wednesday 

Wednesday

Thursday 

Thursday

Friday 

Friday

Saturday 

Saturday

Sunday 

Sunday

Definition at line 33 of file datetime.h.

◆ EmptyPartsTreat

enum class CppUtilities::EmptyPartsTreat
strong

Specifies the role of empty parts when splitting strings.

Enumerator
Keep 

empty parts are kept

Omit 

empty parts are omitted

Merge 

empty parts are omitted but cause the adjacent parts being joined using the delimiter

Definition at line 145 of file stringconversion.h.

◆ IniFileFieldFlags

Enumerator
None 
HasValue 

Definition at line 68 of file inifile.h.

◆ IniFileMakeOptions

Enumerator
None 

Definition at line 64 of file inifile.h.

◆ IniFileParseOptions

Enumerator
None 

Definition at line 60 of file inifile.h.

◆ IniFileSectionFlags

Enumerator
None 
Implicit 
Truncated 

Definition at line 73 of file inifile.h.

◆ ParseArgumentBehavior

The ParseArgumentBehavior enum specifies the behavior when parsing arguments.

This concerns checking constraints, invoking callbacks and handling failures. The values are supposed to be combined using the |-operator. Note that ParseArgumentBehavior::ReadArguments is always implied.

Enumerator
ReadArguments 

reads the specified CLI arguments, equivalent to simply calling readArgs()

CheckConstraints 

whether the constraints should be checked after reading the arguments

InvokeCallbacks 

whether the callbacks should be invoked after reading the arguments and (maybe) checking the constraints

ExitOnFailure 

whether the parser should print an error message and terminate the application on failure (rather than throwing an exception)

Definition at line 88 of file argumentparser.h.

◆ Response

enum class CppUtilities::Response
strong

The Response enum is used to specify the default response for the confirmPrompt() method.

Enumerator
None 
Yes 
No 

Definition at line 19 of file commandlineutils.h.

◆ TimeSpanOutputFormat

Specifies the output format.

See also
TimeSpan::toString()
Enumerator
Normal 

the normal form of specifying a time interval: hh:mm:ss

WithMeasures 

measures are used, eg.: 34 d 5 h 10 min 7 s 31 ms

TotalSeconds 

total seconds (as returned by totalSeconds()), eg. 2304.342

Definition at line 19 of file timespan.h.

◆ UnknownArgumentBehavior

The UnknownArgumentBehavior enum specifies the behavior of the argument parser when an unknown argument is detected.

Enumerator
Ignore 

Unknown arguments are ignored without warnings.

Warn 

A warning is printed to std::cerr if an unknown argument is detected.

Fail 

Further parsing is aborted and a Failure instance with an error message is thrown.

Definition at line 76 of file argumentparser.h.

◆ ValueCompletionBehavior

enum class CppUtilities::ValueCompletionBehavior : unsigned char
strong

The ValueCompletionBehavior enum specifies the items to be considered when generating completion for an argument value.

Remarks
Enumerator
None 

no auto-completion

PreDefinedValues 

values assigned with Argument::setPreDefinedCompletionValues()

Files 

files

Directories 

directories

FileSystemIfNoPreDefinedValues 

files and directories but only if no values have been assigned (default behavior)

AppendEquationSign 

an equation sign is appended to values which not contain an equation sign already

InvokeCallback 

whether to invoke the callback before reading pre-defined values

Definition at line 117 of file argumentparser.h.

◆ WorkingCopyMode

enum class CppUtilities::WorkingCopyMode
strong

The WorkingCopyMode enum specifies additional options to influence behavior of TestApplication::workingCopyPath().

Enumerator
CreateCopy 

a working copy of the test file is created

NoCopy 

only the directory for the working copy is created but not the test file itself

Cleanup 

the directory for the working copy is created if needed or a previously existing file is deleted

Definition at line 28 of file testutils.h.

Function Documentation

◆ argsToString()

template<class StringType = std::string, class... Args>
StringType CppUtilities::argsToString ( Args &&... args)
inline

Definition at line 260 of file stringbuilder.h.

◆ asHexNumber()

template<typename T >
AsHexNumber< T > CppUtilities::asHexNumber ( const T & value)

Wraps a value to be printed using the hex system in the error case when asserted with cppunit (or similar test framework).

Definition at line 258 of file testutils.h.

◆ bitrateToString()

string CppUtilities::bitrateToString ( double bitrateInKbitsPerSecond,
bool useIecBinaryPrefixes )

Converts the specified bitrate in kbit/s to its equivalent std::string representation.

The unit with appropriate binary prefix will be appended.

Parameters
bitrateInKbitsPerSecondSpecifies the bitrate in kbit/s.
useIecBinaryPrefixesIndicates whether IEC binary prefixes should be used (eg. KiB/s).
See also
Binary prefix - Wikipedia

Definition at line 338 of file stringconversion.cpp.

◆ bufferToNumber()

template<typename IntegralType , class CharType , typename BaseType = IntegralType, Traits::EnableIf< std::is_integral< IntegralType >, std::is_unsigned< IntegralType > > * = nullptr>
IntegralType CppUtilities::bufferToNumber ( const CharType * string,
std::size_t size,
BaseType base = 10 )

Converts the given string of size characters to an unsigned numeric value using the specified base.

Converts the given string of size characters to a signed numeric value using the specified base.

Template Parameters
IntegralTypeThe data type used to store the converted value.
CharTypeThe character type.
Exceptions
AConversionException will be thrown if the provided string is not a valid number.
See also
numberToString(), stringToNumber()

Definition at line 544 of file stringconversion.h.

◆ charToDigit()

template<typename CharType >
CharType CppUtilities::charToDigit ( CharType character,
CharType base )

Returns number/digit of the specified character representation using the specified base.

Exceptions
AConversionException will be thrown if the provided character does not represent a valid digit for the specified base.

Definition at line 491 of file stringconversion.h.

◆ checkFlagEnum()

template<typename FlagEnumClass , Traits::EnableIf< IsFlagEnumClass< FlagEnumClass > > * = nullptr>
bool CppUtilities::checkFlagEnum ( FlagEnumClass flagVariable,
FlagEnumClass flagsToCheck )
constexpr

Returns whether the specified flagVariable has set all flags specified via flagsToCheck to true.

Definition at line 87 of file flagenumclass.h.

◆ compareArgs()

bool CppUtilities::compareArgs ( const Argument * arg1,
const Argument * arg2 )

Returns whether arg1 should be listed before arg2 when printing completion.

Arguments are sorted by name (ascending order). However, all arguments denoting an operation are listed before all other arguments.

Definition at line 1120 of file argumentparser.cpp.

◆ computeDamerauLevenshteinDistance() [1/4]

std::size_t CppUtilities::computeDamerauLevenshteinDistance ( const char *const str1,
const size_t size1,
const char *const str2,
const size_t size2 )

Computes Damerau–Levenshtein distance with adjacent transpositions.

Returns
Returns the number of editing steps required to turn str1 into str2. The following operations are considered as editing steps:
  • substitution: replace one character with another character
  • insertion: insert one character at any position
  • deletion: delete one character at any position
  • transposition: swap any pair of adjacent characters
Remarks
  • Computing "Optimal string alignment distance" is a different thing.
  • The algorithm operates on byte-level. So characters requiring more than one byte in the used character encoding (e.g. UTF-8 encoded German umlauts) are counted as multiple characters (e.g. substitution of those umlauts with non-umlauts requires 2 editing steps).
  • The memory consumption of this algorithm is considerably. The required memory increases with the product of size1 and size2. Pass only short words to this function!

Definition at line 125 of file levenshtein.cpp.

◆ computeDamerauLevenshteinDistance() [2/4]

std::size_t CppUtilities::computeDamerauLevenshteinDistance ( const char * str1,
const char * str2 )
inline

Definition at line 18 of file levenshtein.h.

◆ computeDamerauLevenshteinDistance() [3/4]

CPP_UTILITIES_EXPORT std::size_t CppUtilities::computeDamerauLevenshteinDistance ( const char * str1,
std::size_t size1,
const char * str2,
std::size_t size2 )

◆ computeDamerauLevenshteinDistance() [4/4]

std::size_t CppUtilities::computeDamerauLevenshteinDistance ( const std::string & str1,
const std::string & str2 )
inline

Definition at line 13 of file levenshtein.h.

◆ confirmPrompt()

bool CppUtilities::confirmPrompt ( const char * message,
Response defaultResponse = Response::None )

Prompts for confirmation displaying the specified message.

Definition at line 27 of file commandlineutils.cpp.

◆ containsSubstrings() [1/2]

template<typename StringType >
bool CppUtilities::containsSubstrings ( const StringType & str,
std::initializer_list< const typename StringType::value_type * > substrings )

Returns whether str contains the specified substrings.

Remarks
The substrings must occur in the specified order.

Definition at line 352 of file stringconversion.h.

◆ containsSubstrings() [2/2]

template<typename StringType >
bool CppUtilities::containsSubstrings ( const StringType & str,
std::initializer_list< StringType > substrings )

Returns whether str contains the specified substrings.

Remarks
The substrings must occur in the specified order.

Definition at line 335 of file stringconversion.h.

◆ convertLatin1ToUtf8()

StringData CppUtilities::convertLatin1ToUtf8 ( const char * inputBuffer,
std::size_t inputBufferSize )

Converts the specified Latin-1 string to UTF-8.

Definition at line 189 of file stringconversion.cpp.

◆ convertString()

StringData CppUtilities::convertString ( const char * fromCharset,
const char * toCharset,
const char * inputBuffer,
std::size_t inputBufferSize,
float outputBufferSizeFactor )

Converts the specified string from one character set to another.

Remarks
  • The term "size" refers here always to the actual number of bytes and not to the number of characters (eg. the size of the UTF-8 string "ö" is 2 and not 1).
  • The expected size of the output buffer can be specified via outputBufferSizeFactor. This hint helps to reduce buffer reallocations during the conversion (eg. for the conversion from Latin-1 to UTF-16 the factor would be 2, for the conversion from UTF-16 to Latin-1 the factor would be 0.5).

Definition at line 144 of file stringconversion.cpp.

◆ convertUtf16BEToUtf8()

StringData CppUtilities::convertUtf16BEToUtf8 ( const char * inputBuffer,
std::size_t inputBufferSize )

Converts the specified UTF-16 (big-endian) string to UTF-8.

Definition at line 180 of file stringconversion.cpp.

◆ convertUtf16LEToUtf8()

StringData CppUtilities::convertUtf16LEToUtf8 ( const char * inputBuffer,
std::size_t inputBufferSize )

Converts the specified UTF-16 (little-endian) string to UTF-8.

Definition at line 162 of file stringconversion.cpp.

◆ convertUtf8ToLatin1()

StringData CppUtilities::convertUtf8ToLatin1 ( const char * inputBuffer,
std::size_t inputBufferSize )

Converts the specified UTF-8 string to Latin-1.

Definition at line 198 of file stringconversion.cpp.

◆ convertUtf8ToUtf16BE()

StringData CppUtilities::convertUtf8ToUtf16BE ( const char * inputBuffer,
std::size_t inputBufferSize )

Converts the specified UTF-8 string to UTF-16 (big-endian).

Definition at line 171 of file stringconversion.cpp.

◆ convertUtf8ToUtf16LE()

StringData CppUtilities::convertUtf8ToUtf16LE ( const char * inputBuffer,
std::size_t inputBufferSize )

Converts the specified UTF-8 string to UTF-16 (little-endian).

Definition at line 153 of file stringconversion.cpp.

◆ dataSizeToString()

string CppUtilities::dataSizeToString ( std::uint64_t sizeInByte,
bool includeByte )

Converts the specified data size in byte to its equivalent std::string representation.

The unit with appropriate binary prefix will be appended.

Definition at line 306 of file stringconversion.cpp.

◆ decodeBase64()

std::pair< unique_ptr< std::uint8_t[]>, std::uint32_t > CppUtilities::decodeBase64 ( const char * encodedStr,
const std::uint32_t strSize )

Decodes the specified Base64 encoded string.

Exceptions
Throwsa ConversionException if the specified string is no valid Base64.
See also
RFC 4648

Definition at line 417 of file stringconversion.cpp.

◆ determineTerminalSize()

TerminalSize CppUtilities::determineTerminalSize ( )

Returns the current size of the terminal.

Remarks
Unknown members of the returned TerminalSize are set to zero.

Definition at line 73 of file commandlineutils.cpp.

◆ digitsum()

template<typename IntegralType , Traits::EnableIf< std::is_integral< IntegralType > > * = nullptr>
IntegralType CppUtilities::digitsum ( IntegralType number,
IntegralType base = 10 )
constexpr

Returns the digitsum of the given number using the specified base.

Definition at line 16 of file math.h.

◆ digitToChar()

template<typename CharType >
CharType CppUtilities::digitToChar ( CharType digit)
constexpr

Returns the character representation of the specified digit.

Remarks
  • Uses capital letters.
  • Valid values for digit: 0 <= digit <= 35

Definition at line 409 of file stringconversion.h.

◆ directory() [1/2]

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

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

Definition at line 25 of file path.cpp.

◆ directory() [2/2]

std::string_view CppUtilities::directory ( std::string_view path)

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

Definition at line 53 of file path.cpp.

◆ encodeBase64()

string CppUtilities::encodeBase64 ( const std::uint8_t * data,
std::uint32_t dataSize )

Encodes the specified data to Base64.

See also
RFC 4648

Definition at line 377 of file stringconversion.cpp.

◆ endsWith() [1/2]

template<typename StringType >
bool CppUtilities::endsWith ( const StringType & str,
const StringType & phrase )

Returns whether str ends with phrase.

Definition at line 299 of file stringconversion.h.

◆ endsWith() [2/2]

template<typename StringType >
bool CppUtilities::endsWith ( const StringType & str,
const typename StringType::value_type * phrase )

Returns whether str ends with phrase.

Definition at line 316 of file stringconversion.h.

◆ extractFiles()

FileMap CppUtilities::extractFiles ( std::string_view archivePath,
const FilePredicate & isFileRelevant = FilePredicate() )

Extracts the specified archive.

Definition at line 259 of file archive.cpp.

◆ extractFilesFromBuffer()

FileMap CppUtilities::extractFilesFromBuffer ( std::string_view archiveData,
std::string_view archiveName,
const FilePredicate & isFileRelevant = FilePredicate() )

Extracts the specified archive.

Definition at line 217 of file archive.cpp.

◆ extractNativePath()

PathStringView CppUtilities::extractNativePath ( NativePathStringView path)
inline

Returns path as UTF-8 string or string view.

See also
This is the opposite of makeNativePath() so checkout remarks of that function for details.

Definition at line 102 of file path.h.

◆ factorial()

template<typename IntegralType , Traits::EnableIf< std::is_integral< IntegralType > > * = nullptr>
IntegralType CppUtilities::factorial ( IntegralType number)
constexpr

Returns the factorial of the given number.

Definition at line 29 of file math.h.

◆ fileName() [1/2]

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

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

Definition at line 17 of file path.cpp.

◆ fileName() [2/2]

std::string_view CppUtilities::fileName ( std::string_view path)

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

Definition at line 33 of file path.cpp.

◆ findAndReplace() [1/4]

template<typename StringType >
void CppUtilities::findAndReplace ( StringType & str,
const typename StringType::value_type * find,
const typename StringType::value_type * replace )
inline

Replaces all occurrences of find with relpace in the specified str.

Definition at line 379 of file stringconversion.h.

◆ findAndReplace() [2/4]

template<typename StringType1 , typename StringType2 , typename StringType3 >
void CppUtilities::findAndReplace ( StringType1 & str,
const StringType2 & find,
const StringType3 & replace )

Replaces all occurrences of find with relpace in the specified str.

Definition at line 368 of file stringconversion.h.

◆ findAndReplace() [3/4]

template<typename StringType1 , typename StringType2 >
void CppUtilities::findAndReplace ( StringType1 & str,
const StringType2 & find,
const typename StringType1::value_type * replace )
inline

Replaces all occurrences of find with relpace in the specified str.

Definition at line 389 of file stringconversion.h.

◆ findAndReplace() [4/4]

template<typename StringType1 , typename StringType2 >
void CppUtilities::findAndReplace ( StringType1 & str,
const typename StringType1::value_type * find,
const StringType2 & replace )
inline

Replaces all occurrences of find with relpace in the specified str.

Definition at line 398 of file stringconversion.h.

◆ firstPresentUncombinableArg()

Argument * CppUtilities::firstPresentUncombinableArg ( const ArgumentVector & args,
const Argument * except )

This function return the first present and uncombinable argument of the given list of arguments.

The Argument except will be ignored.

Definition at line 592 of file argumentparser.cpp.

◆ inRangeExclMax()

template<typename num1 , typename num2 , typename num3 >
bool CppUtilities::inRangeExclMax ( num1 val,
num2 min,
num3 max )
constexpr

Definition at line 31 of file datetime.cpp.

◆ inRangeInclMax()

template<typename num1 , typename num2 , typename num3 >
bool CppUtilities::inRangeInclMax ( num1 val,
num2 min,
num3 max )
constexpr

Definition at line 26 of file datetime.cpp.

◆ insertSiblings()

void CppUtilities::insertSiblings ( const ArgumentVector & siblings,
list< const Argument * > & target )

Inserts the specified siblings in the target list.

Remarks
Only inserts siblings which could still occur at least once more.

Definition at line 1135 of file argumentparser.cpp.

◆ integralsAsHexNumber() [1/2]

template<typename T , Traits::EnableIf< std::is_integral< T > > * = nullptr>
AsHexNumber< T > CppUtilities::integralsAsHexNumber ( const T & value)

Wraps a value to be printed using the hex system in the error case when asserted with cppunit (or similar test framework).

Remarks
Only affects integral types. Values of other types are printed as usual.

Definition at line 268 of file testutils.h.

◆ integralsAsHexNumber() [2/2]

template<typename T , Traits::DisableIf< std::is_integral< T > > * = nullptr>
const T & CppUtilities::integralsAsHexNumber ( const T & value)

Wraps a value to be printed using the hex system in the error case when asserted with cppunit (or similar test framework).

Remarks
Only affects integral types. Values of other types are printed as usual.

Definition at line 278 of file testutils.h.

◆ interpretIntegerAsString()

template<typename T >
std::string CppUtilities::interpretIntegerAsString ( T integer,
int startOffset = 0 )

Interprets the given integer at the specified position as std::string using the specified byte order.

Example: interpretation of ID3v2 frame IDs (stored as 32-bit integer) as string

  • 0x54495432/1414091826 will be interpreted as "TIT2".
  • 0x00545432/5526578 will be interpreted as "TT2" using start offset 1 to omit the first byte.
Template Parameters
TThe data type of the integer to be interpreted.

Definition at line 715 of file stringconversion.h.

◆ inverseModulo()

template<typename IntegralType , Traits::EnableIf< std::is_integral< IntegralType >, std::is_unsigned< IntegralType > > * = nullptr>
IntegralType CppUtilities::inverseModulo ( IntegralType number,
IntegralType module )
constexpr

Computes the inverse of number modulo module.

Definition at line 61 of file math.h.

◆ isEnvVariableSet()

std::optional< bool > CppUtilities::isEnvVariableSet ( const char * variableName)

Returns whether the specified env variable is set to a non-zero and non-white-space-only value.

Definition at line 51 of file commandlineutils.cpp.

◆ joinStrings()

template<class Container = std::initializer_list<std::string>, class ReturnType = Detail::DefaultReturnTypeForContainer<Container>>
ReturnType CppUtilities::joinStrings ( const Container & strings,
Detail::StringParamForContainer< Container > delimiter = Detail::StringParamForContainer<Container>(),
bool omitEmpty = false,
Detail::StringParamForContainer< Container > leftClosure = Detail::StringParamForContainer<Container>(),
Detail::StringParamForContainer< Container > rightClosure = Detail::StringParamForContainer<Container>() )

Joins the given strings using the specified delimiter.

The strings will be enclosed using the provided closures leftClosure and rightClosure.

Parameters
stringsThe string parts to be joined.
delimiterSpecifies a delimiter to be used (empty string by default).
omitEmptyIndicates whether empty part should be omitted.
leftClosureSpecifies a string to be inserted before each string (empty string by default).
rightClosureSpecifies a string to be appended after each string (empty string by default).
Template Parameters
ContainerContainer The STL-container used to provide the strings.
ReturnTypeType to store the result; defaults to the container's element type.
Returns
Returns the joined string.

Definition at line 99 of file stringconversion.h.

◆ makeFixedSizeMultiArray()

template<typename ValueType , std::size_t size, typename... DimensionSizes>
auto CppUtilities::makeFixedSizeMultiArray ( DimensionSizes... dimensionSizes)
inline

Constructs a new N-dimensional array using a fixed size array as underlying container. The sizes for the dimensions are passed as arguments.

Remarks
The number of dimensions N is deduced from the number of dimensionSizes.

Definition at line 177 of file multiarray.h.

◆ makeMultiArray()

template<typename ValueType , typename... DimensionSizes>
auto CppUtilities::makeMultiArray ( DimensionSizes... dimensionSizes)
inline

Constructs a new N-dimensional array using an std::vector with std::allocator as underlying container. The sizes for the dimensions are passed as arguments.

Remarks
The number of dimensions N is deduced from the number of dimensionSizes.

Definition at line 169 of file multiarray.h.

◆ makeNativePath()

NativePathStringView CppUtilities::makeNativePath ( PathStringView path)
inline

Returns path in the platform's native encoding.

Remarks
  • On Windows we store paths internally as UTF-8 strings. So it is assumed that path is UTF-8 and a UTF-16 std::wstring is returned.
  • On any other platforms we store paths internally using the native format (usually UTF-8). So it is assumed that path is already encoded as intended and passed as-is.
  • This function does basically the same as libstdc++'s std::filesystem::u8path implementation. However, the C++ standard actually imposes a conversion to UTF-8 when a non-UTF-8 narrow encoding is used. That's not wanted here. Besides, that function is deprecated in C++ 20.

Definition at line 82 of file path.h.

◆ makeNoneOwningMultiArray()

template<typename ValueType , typename... DimensionSizes>
auto CppUtilities::makeNoneOwningMultiArray ( DimensionSizes... dimensionSizes)
inline

Constructs a new N-dimensional array using a caller-managed buffer as underlying container. The sizes for the dimensions are passed as arguments.

Remarks
The number of dimensions N is deduced from the number of dimensionSizes.

Definition at line 185 of file multiarray.h.

◆ max() [1/2]

template<typename T >
T CppUtilities::max ( T first,
T second )
constexpr

Returns the greatest of the given items.

Definition at line 100 of file math.h.

◆ max() [2/2]

template<typename T1 , typename... T2>
T1 CppUtilities::max ( T1 first,
T1 second,
T2... remaining )
constexpr

Returns the greatest of the given items.

Definition at line 106 of file math.h.

◆ min() [1/2]

template<typename T >
T CppUtilities::min ( T first,
T second )
constexpr

Returns the smallest of the given items.

Definition at line 88 of file math.h.

◆ min() [2/2]

template<typename T1 , typename... T2>
T1 CppUtilities::min ( T1 first,
T1 second,
T2... remaining )
constexpr

Returns the smallest of the given items.

Definition at line 94 of file math.h.

◆ modFlagEnum()

template<typename FlagEnumClass , Traits::EnableIf< IsFlagEnumClass< FlagEnumClass > > * = nullptr>
FlagEnumClass & CppUtilities::modFlagEnum ( FlagEnumClass & flagVariable,
FlagEnumClass relevantFlags,
bool value )
constexpr

Sets the specified relevantFlags in the specified flagVariable to the specified value.

Definition at line 78 of file flagenumclass.h.

◆ numberToString() [1/2]

template<typename FloatingType , class StringType = std::string, Traits::EnableIf< std::is_floating_point< FloatingType > > * = nullptr>
StringType CppUtilities::numberToString ( FloatingType number,
int base = 10 )

Converts the given number to its equivalent string representation using the specified base.

Template Parameters
FloatingTypeThe data type of the given number.
StringTypeThe string type (should be an instantiation of the basic_string class template).
Remarks
This function is using std::basic_stringstream internally and hence also has its limitations (eg. regarding base and types).
See also
stringToNumber(), bufferToNumber()

Definition at line 480 of file stringconversion.h.

◆ numberToString() [2/2]

template<typename IntegralType , class StringType = std::string, typename BaseType = IntegralType, CppUtilities::Traits::EnableIf< std::is_integral< IntegralType >, std::is_unsigned< IntegralType > > * = nullptr>
StringType CppUtilities::numberToString ( IntegralType number,
BaseType base = 10 )

Converts the given number to its equivalent string representation using the specified base.

Template Parameters
IntegralTypeThe data type of the given number.
StringTypeThe string type (should be an instantiation of the basic_string class template).
See also
stringToNumber()

Definition at line 422 of file stringconversion.h.

◆ operator%() [1/8]

template<class StringType , Traits::EnableIfAny< Traits::IsSpecializationOf< StringType, std::basic_string >, Traits::IsSpecializationOf< StringType, std::basic_string_view > > * = nullptr>
auto CppUtilities::operator% ( char lhs,
const StringType & rhs ) -> decltype(std::tuple<char, const StringType &>(lhs, rhs))
constexpr

Allows construction of string-tuples via %-operator, eg.

string1 % "string2" % string3.

Definition at line 345 of file stringbuilder.h.

◆ operator%() [2/8]

template<class StringType , Traits::EnableIfAny< Traits::IsSpecializationOf< StringType, std::basic_string >, Traits::IsSpecializationOf< StringType, std::basic_string_view > > * = nullptr>
auto CppUtilities::operator% ( const char * lhs,
const StringType & rhs ) -> decltype(std::tuple<const char *, const StringType &>(lhs, rhs))
constexpr

Allows construction of string-tuples via %-operator, eg.

string1 % "string2" % string3.

Definition at line 312 of file stringbuilder.h.

◆ operator%() [3/8]

template<class StringType , Traits::EnableIfAny< Traits::IsSpecializationOf< StringType, std::basic_string >, Traits::IsSpecializationOf< StringType, std::basic_string_view > > * = nullptr>
auto CppUtilities::operator% ( const StringType & lhs,
char rhs ) -> decltype(std::tuple<const StringType &, char>(lhs, rhs))
constexpr

Allows construction of string-tuples via %-operator, eg.

string1 % "string2" % string3.

Definition at line 334 of file stringbuilder.h.

◆ operator%() [4/8]

template<class StringType , Traits::EnableIfAny< Traits::IsSpecializationOf< StringType, std::basic_string >, Traits::IsSpecializationOf< StringType, std::basic_string_view > > * = nullptr>
auto CppUtilities::operator% ( const StringType & lhs,
const char * rhs ) -> decltype(std::tuple<const StringType &, const char *>(lhs, rhs))
constexpr

Allows construction of string-tuples via %-operator, eg.

string1 % "string2" % string3.

Definition at line 323 of file stringbuilder.h.

◆ operator%() [5/8]

template<class StringType , Traits::EnableIfAny< Traits::IsSpecializationOf< StringType, std::basic_string >, Traits::IsSpecializationOf< StringType, std::basic_string_view > > * = nullptr>
auto CppUtilities::operator% ( const StringType & lhs,
const StringType & rhs ) -> decltype(std::tuple<const StringType &, const StringType &>(lhs, rhs))
constexpr

Allows construction of string-tuples via %-operator, eg.

string1 % "string2" % string3.

Definition at line 301 of file stringbuilder.h.

◆ operator%() [6/8]

template<class Tuple , Traits::EnableIf< Traits::IsSpecializationOf< Tuple, std::tuple > > * = nullptr>
auto CppUtilities::operator% ( const Tuple & lhs,
const char * rhs ) -> decltype(std::tuple_cat(lhs, std::tuple<const char *>(rhs)))
constexpr

Allows construction of string-tuples via %-operator, eg.

string1 % "string2" % string3.

Definition at line 280 of file stringbuilder.h.

◆ operator%() [7/8]

template<class Tuple , class StringType , Traits::EnableIf< Traits::IsSpecializationOf< Tuple, std::tuple >, Traits::IsSpecializingAnyOf< StringType, std::basic_string, std::basic_string_view > > * = nullptr>
auto CppUtilities::operator% ( const Tuple & lhs,
const StringType & rhs ) -> decltype(std::tuple_cat(lhs, std::tuple<const StringType &>(rhs)))
constexpr

Allows construction of string-tuples via %-operator, eg.

string1 % "string2" % string3.

Definition at line 271 of file stringbuilder.h.

◆ operator%() [8/8]

template<class Tuple , typename IntegralType , Traits::EnableIf< Traits::IsSpecializationOf< Tuple, std::tuple >, std::is_integral< IntegralType > > * = nullptr>
auto CppUtilities::operator% ( const Tuple & lhs,
IntegralType rhs ) -> decltype(std::tuple_cat(lhs, std::tuple<IntegralType>(rhs)))
constexpr

Allows construction of string-tuples via %-operator, eg.

string1 % "string2" % string3.

Definition at line 290 of file stringbuilder.h.

◆ operator+() [1/4]

template<class Tuple , Traits::EnableIf< Traits::IsSpecializationOf< Tuple, std::tuple > > * = nullptr>
std::string CppUtilities::operator+ ( const Tuple & lhs,
const char * rhs )
inline

Allows construction of final string from previously constructed string-tuple and trailing string via +-operator.

This is meant to be used for fast string building without multiple heap allocation, eg.

printVelocity("velocity: " % numberToString(velocityExample) % " km/h (" % numberToString(velocityExample / 3.6) + " m/s)"));
StringType numberToString(IntegralType number, BaseType base=10)
Converts the given number to its equivalent string representation using the specified base.

Definition at line 378 of file stringbuilder.h.

◆ operator+() [2/4]

template<class Tuple , class StringType , Traits::EnableIf< Traits::IsSpecializationOf< Tuple, std::tuple >, Traits::Any< Traits::IsSpecializationOf< StringType, std::basic_string >, Traits::IsSpecializationOf< StringType, std::basic_string_view > > > * = nullptr>
std::string CppUtilities::operator+ ( const Tuple & lhs,
const StringType & rhs )
inline

Allows construction of final string from previously constructed string-tuple and trailing string via +-operator.

This is meant to be used for fast string building without multiple heap allocation, eg.

printVelocity("velocity: " % numberToString(velocityExample) % " km/h (" % numberToString(velocityExample / 3.6) + " m/s)"));

Definition at line 363 of file stringbuilder.h.

◆ operator+() [3/4]

template<class Tuple , typename IntegralType , Traits::EnableIf< Traits::IsSpecializationOf< Tuple, std::tuple >, std::is_integral< IntegralType > > * = nullptr>
std::string CppUtilities::operator+ ( const Tuple & lhs,
IntegralType rhs )
inline

Allows construction of final string from previously constructed string-tuple and trailing char via +-operator.

This is meant to be used for fast string building without multiple heap allocation, eg.

printVelocity("velocity: " % numberToString(velocityExample) % " km/h (" % numberToString(velocityExample / 3.6) + " m/s)"));

Definition at line 394 of file stringbuilder.h.

◆ operator+() [4/4]

DateTime CppUtilities::operator+ ( DateTime begin,
Period period )

Adds the specified period to the specified date.

Exceptions
Mightthrow ConversionException if resulting DateTime would be out-of-range.
Remarks
  • The order in which the years(), month() and days() are added matters. See the overall class description.
  • Since the accuracy of Period is only one day, the DateTime::timeOfDay() of the result always equals begin.timeOfDay().

Definition at line 60 of file period.cpp.

◆ operator<<() [1/7]

std::ostream & CppUtilities::operator<< ( std::ostream & o,
const ParseError & failure )

Prints an error message "Unable to parse arguments: ..." for the specified failure.

Definition at line 26 of file parseerror.cpp.

◆ operator<<() [2/7]

ostream & CppUtilities::operator<< ( std::ostream & os,
const Wrapper & wrapper )

Definition at line 407 of file argumentparser.cpp.

◆ operator<<() [3/7]

template<typename T >
std::ostream & CppUtilities::operator<< ( std::ostream & out,
const AsHexNumber< T > & value )

Provides the actual formatting of the output for AsHexNumber class.

Definition at line 249 of file testutils.h.

◆ operator<<() [4/7]

template<typename Iteratable , Traits::EnableIf< Traits::IsIteratable< Iteratable >, Traits::Not< Traits::IsString< Iteratable > > > * = nullptr>
std::ostream & CppUtilities::operator<< ( std::ostream & out,
const Iteratable & iteratable )
inline

Allows printing iteratable objects so those can be asserted using CPPUNIT_ASSERT_EQUAL.

Definition at line 354 of file testutils.h.

◆ operator<<() [5/7]

template<typename Optional , Traits::EnableIf< Traits::IsSpecializationOf< Optional, std::optional > > * = nullptr>
std::ostream & CppUtilities::operator<< ( std::ostream & out,
const Optional & optional )
inline

Allows printing std::optional objects so those can be asserted using CPPUNIT_ASSERT_EQUAL.

Definition at line 215 of file testutils.h.

◆ operator<<() [6/7]

template<typename Pair , CppUtilities::Traits::EnableIf< CppUtilities::Traits::IsSpecializationOf< Pair, std::pair > > * = nullptr>
std::ostream & CppUtilities::operator<< ( std::ostream & out,
const Pair & pair )
inline

Allows printing pairs so key/values of maps/hashes can be asserted using CPPUNIT_ASSERT_EQUAL.

Definition at line 345 of file testutils.h.

◆ operator<<() [7/7]

CPP_UTILITIES_EXPORT std::ostream & CppUtilities::operator<< ( std::ostream & out,
Indentation indentation )
inline

Definition at line 88 of file commandlineutils.h.

◆ operator==()

template<typename T >
bool CppUtilities::operator== ( const AsHexNumber< T > & lhs,
const AsHexNumber< T > & rhs )

Provides operator == required by CPPUNIT_ASSERT_EQUAL.

Definition at line 241 of file testutils.h.

◆ orderModulo()

template<typename IntegralType , Traits::EnableIf< std::is_integral< IntegralType >, std::is_unsigned< IntegralType > > * = nullptr>
IntegralType CppUtilities::orderModulo ( const IntegralType number,
const IntegralType module )
constexpr

Computes the order of number modulo module.

Definition at line 79 of file math.h.

◆ powerModulo()

template<typename IntegralType , Traits::EnableIf< std::is_integral< IntegralType >, std::is_unsigned< IntegralType > > * = nullptr>
IntegralType CppUtilities::powerModulo ( const IntegralType base,
const IntegralType exponent,
const IntegralType module )
constexpr

Computes base power exponent modulo module.

Definition at line 42 of file math.h.

◆ readFile() [1/2]

std::string CppUtilities::readFile ( const std::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 17 of file misc.cpp.

◆ readFile() [2/2]

std::string CppUtilities::readFile ( std::string_view path,
std::string_view::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 47 of file misc.cpp.

◆ removeInvalidChars()

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

Removes invalid characters from the specified fileName.

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

Definition at line 75 of file path.cpp.

◆ splitString()

template<class Container = std::list<std::string>>
Container CppUtilities::splitString ( Detail::StringParamForContainer< Container > string,
Detail::StringParamForContainer< Container > delimiter,
EmptyPartsTreat emptyPartsRole = EmptyPartsTreat::Keep,
int maxParts = -1 )

Splits the given string at the specified delimiter.

Parameters
stringThe string to be split.
delimiterSpecifies the delimiter which must not be empty.
emptyPartsRoleSpecifies the treatment of empty parts.
maxPartsSpecifies the maximal number of parts. Values less or equal zero indicate an unlimited number of parts.
Template Parameters
ContainerThe STL-container used to return the parts.
Returns
Returns the parts.

Definition at line 161 of file stringconversion.h.

◆ splitStringSimple()

template<class Container = std::list<std::string>>
Container CppUtilities::splitStringSimple ( Detail::StringParamForContainer< Container > string,
Detail::StringParamForContainer< Container > delimiter,
int maxParts = -1 )

Splits the given string (which might also be a string view) at the specified delimiter.

Parameters
stringThe string to be split.
delimiterSpecifies the delimiter which must not be empty.
maxPartsSpecifies the maximal number of parts. Values less or equal zero indicate an unlimited number of parts.
Template Parameters
ContainerThe STL-container used to return the parts.
Returns
Returns the parts.
Remarks
This is a simplified version of splitString() where emptyPartsRole is always EmptyPartsTreat::Keep.

Definition at line 213 of file stringconversion.h.

◆ startsWith() [1/2]

template<typename StringType >
bool CppUtilities::startsWith ( const StringType & str,
const StringType & phrase )

Returns whether str starts with phrase.

Definition at line 262 of file stringconversion.h.

◆ startsWith() [2/2]

template<typename StringType >
bool CppUtilities::startsWith ( const StringType & str,
const typename StringType::value_type * phrase )

Returns whether str starts with phrase.

Definition at line 282 of file stringconversion.h.

◆ stringToNumber() [1/6]

template<typename IntegralType , typename CharType , typename BaseType = IntegralType, Traits::EnableIf< std::is_integral< IntegralType >, std::is_unsigned< IntegralType > > * = nullptr>
IntegralType CppUtilities::stringToNumber ( const CharType * string,
BaseType base = 10 )

Converts the given null-terminated string to an unsigned numeric value using the specified base.

Template Parameters
IntegralTypeThe data type used to store the converted value.
CharTypeThe character type.
Exceptions
AConversionException will be thrown if the provided string is not a valid number.
See also
numberToString(), bufferToNumber()

Definition at line 652 of file stringconversion.h.

◆ stringToNumber() [2/6]

template<typename FloatingType , class CharType , Traits::EnableIf< std::is_floating_point< FloatingType > > * = nullptr>
FloatingType CppUtilities::stringToNumber ( const CharType * string,
int base = 10 )

Converts the given null-terminated string to a number assuming string uses the specified base.

Template Parameters
FloatingTypeThe data type used to store the converted value.
CharTypeThe character type.
Exceptions
AConversionException will be thrown if the provided string is not a valid number.
Remarks
This function is using std::basic_stringstream internally and hence also has its limitations (eg. regarding base and types).
See also
numberToString(), bufferToNumber()

Definition at line 671 of file stringconversion.h.

◆ stringToNumber() [3/6]

template<typename IntegralType , typename CharType , typename BaseType = IntegralType, Traits::EnableIf< std::is_integral< IntegralType >, std::is_signed< IntegralType > > * = nullptr>
IntegralType CppUtilities::stringToNumber ( const CharType * string,
IntegralType base = 10 )

Converts the given null-terminated string to a signed numeric value using the specified base.

Template Parameters
IntegralTypeThe data type used to store the converted value.
CharTypeThe character type.
Exceptions
AConversionException will be thrown if the provided string is not a valid number.
See also
numberToString(), bufferToNumber()

Definition at line 685 of file stringconversion.h.

◆ stringToNumber() [4/6]

template<typename IntegralType , class StringType , typename BaseType = IntegralType, Traits::EnableIf< std::is_integral< IntegralType >, Traits::Not< std::is_scalar< std::decay_t< StringType > > > > * = nullptr>
IntegralType CppUtilities::stringToNumber ( const StringType & string,
BaseType base = 10 )

Converts the given string to an unsigned/signed number assuming string uses the specified base.

Template Parameters
IntegralTypeThe data type used to store the converted value.
StringTypeThe string type (should be an instantiation of the basic_string class template).
Exceptions
AConversionException will be thrown if the provided string is not a valid number.
See also
numberToString(), bufferToNumber()

Definition at line 593 of file stringconversion.h.

◆ stringToNumber() [5/6]

template<typename FloatingType , class StringType , Traits::EnableIf< std::is_floating_point< FloatingType >, Traits::Not< std::is_scalar< std::decay_t< StringType > > >, Traits::Not< Traits::IsSpecializationOf< StringType, std::basic_string_view > > > * = nullptr>
FloatingType CppUtilities::stringToNumber ( const StringType & string,
int base = 10 )

Converts the given string to a number assuming string uses the specified base.

Template Parameters
FloatingTypeThe data type used to store the converted value.
StringTypeThe string type (should be an instantiation of the basic_string class template).
Exceptions
AConversionException will be thrown if the provided string is not a valid number.
Remarks
This function is using std::basic_stringstream internally and hence also has its limitations (eg. regarding base and types).
See also
numberToString(), bufferToNumber()

Definition at line 637 of file stringconversion.h.

◆ stringToNumber() [6/6]

template<typename FloatingType , class StringViewType , Traits::EnableIf< std::is_floating_point< FloatingType >, Traits::IsSpecializationOf< StringViewType, std::basic_string_view > > * = nullptr>
FloatingType CppUtilities::stringToNumber ( StringViewType stringView,
int base = 10 )

Converts the given stringView to a number assuming stringView uses the specified base.

Template Parameters
FloatingTypeThe data type used to store the converted value.
StringViewTypeThe string view type (must be an instantiation of the basic_string_view class template).
Exceptions
AConversionException will be thrown if the provided string is not a valid number.
Remarks
This function is using std::basic_stringstream internally and hence also has its limitations (eg. regarding base and types).
See also
numberToString(), bufferToNumber()

Definition at line 609 of file stringconversion.h.

◆ swapOrder() [1/6]

CPP_UTILITIES_EXPORT constexpr std::int16_t CppUtilities::swapOrder ( std::int16_t value)
constexpr

Swaps the byte order of the specified 16-bit integer.

Definition at line 174 of file binaryconversion.h.

◆ swapOrder() [2/6]

CPP_UTILITIES_EXPORT constexpr std::int32_t CppUtilities::swapOrder ( std::int32_t value)
constexpr

Swaps the byte order of the specified 32-bit integer.

Definition at line 182 of file binaryconversion.h.

◆ swapOrder() [3/6]

CPP_UTILITIES_EXPORT constexpr std::int64_t CppUtilities::swapOrder ( std::int64_t value)
constexpr

Swaps the byte order of the specified 64-bit integer.

Definition at line 191 of file binaryconversion.h.

◆ swapOrder() [4/6]

CPP_UTILITIES_EXPORT constexpr std::uint16_t CppUtilities::swapOrder ( std::uint16_t value)
constexpr

Swaps the byte order of the specified 16-bit unsigned integer.

Definition at line 148 of file binaryconversion.h.

◆ swapOrder() [5/6]

CPP_UTILITIES_EXPORT constexpr std::uint32_t CppUtilities::swapOrder ( std::uint32_t value)
constexpr

Swaps the byte order of the specified 32-bit unsigned integer.

Definition at line 156 of file binaryconversion.h.

◆ swapOrder() [6/6]

CPP_UTILITIES_EXPORT constexpr std::uint64_t CppUtilities::swapOrder ( std::uint64_t value)
constexpr

Swaps the byte order of the specified 64-bit unsigned integer.

Definition at line 164 of file binaryconversion.h.

◆ testDirPath()

CPP_UTILITIES_EXPORT std::string CppUtilities::testDirPath ( const std::string & relativeTestDirPath)
inline

Convenience function to invoke TestApplication::testDirPath().

Remarks
A TestApplication must be present.

Definition at line 170 of file testutils.h.

◆ testFilePath()

CPP_UTILITIES_EXPORT std::string CppUtilities::testFilePath ( const std::string & relativeTestFilePath)
inline

Convenience function to invoke TestApplication::testFilePath().

Remarks
A TestApplication must be present.

Definition at line 161 of file testutils.h.

◆ toArrayOfLines()

template<class Container = std::vector<std::string>>
auto CppUtilities::toArrayOfLines ( const std::string & multilineString)
inline

Converts the specified multilineString to an array of lines.

Definition at line 254 of file stringconversion.h.

◆ toFixed16()

CPP_UTILITIES_EXPORT constexpr std::uint32_t CppUtilities::toFixed16 ( float float32value)
constexpr

Returns the 16.16 fixed point representation converted from the specified 32-bit floating point number.

Definition at line 102 of file binaryconversion.h.

◆ toFixed8()

CPP_UTILITIES_EXPORT constexpr std::uint16_t CppUtilities::toFixed8 ( float float32value)
constexpr

Returns the 8.8 fixed point representation converted from the specified 32-bit floating point number.

Definition at line 86 of file binaryconversion.h.

◆ toFloat32() [1/2]

CPP_UTILITIES_EXPORT constexpr float CppUtilities::toFloat32 ( std::uint16_t fixed8value)
constexpr

Returns a 32-bit floating point number converted from the specified 8.8 fixed point representation.

Definition at line 94 of file binaryconversion.h.

◆ toFloat32() [2/2]

CPP_UTILITIES_EXPORT constexpr float CppUtilities::toFloat32 ( std::uint32_t fixed16value)
constexpr

Returns a 32-bit floating point number converted from the specified 16.16 fixed point representation.

Definition at line 110 of file binaryconversion.h.

◆ toMultiline()

template<class Container = std::initializer_list<std::string>>
auto CppUtilities::toMultiline ( const Container & arrayOfLines)
inline

Converts the specified arrayOfLines to a multiline string.

Definition at line 137 of file stringconversion.h.

◆ toNormalInt()

CPP_UTILITIES_EXPORT constexpr std::uint32_t CppUtilities::toNormalInt ( std::uint32_t synchsafeInt)
constexpr

Returns a normal 32-bit integer converted from a 32-bit synchsafe integer.

Remarks
Synchsafe integers appear in ID3 tags that are attached to an MP3 file.
See also
ID3 tag version 2.4.0 - Main Structure

Definition at line 130 of file binaryconversion.h.

◆ toSynchsafeInt()

CPP_UTILITIES_EXPORT constexpr std::uint32_t CppUtilities::toSynchsafeInt ( std::uint32_t normalInt)
constexpr

Returns a 32-bit synchsafe integer converted from a normal 32-bit integer.

Remarks
Synchsafe integers appear in ID3 tags that are attached to an MP3 file.
See also
ID3 tag version 2.4.0 - Main Structure

Definition at line 120 of file binaryconversion.h.

◆ truncateString()

void CppUtilities::truncateString ( std::string & str,
char terminationChar = '\0' )

Truncates all characters after the first occurrence of the specified terminationChar and the termination character as well.

Definition at line 293 of file stringconversion.cpp.

◆ tupleToString()

template<class StringType = std::string, class... Args>
StringType CppUtilities::tupleToString ( const std::tuple< Args... > & tuple)
inline

Concatenates all strings hold by the specified tuple.

Definition at line 252 of file stringbuilder.h.

◆ walkThroughArchive()

void CppUtilities::walkThroughArchive ( std::string_view archivePath,
const FilePredicate & isFileRelevant = FilePredicate(),
FileHandler && fileHandler = FileHandler(),
DirectoryHandler && directoryHandler = DirectoryHandler() )

Invokes callbacks for files and directories in the specified archive.

Definition at line 227 of file archive.cpp.

◆ walkThroughArchiveFromBuffer()

void CppUtilities::walkThroughArchiveFromBuffer ( std::string_view archiveData,
std::string_view archiveName,
const FilePredicate & isFileRelevant = FilePredicate(),
FileHandler && fileHandler = FileHandler(),
DirectoryHandler && directoryHandler = DirectoryHandler() )

Invokes callbacks for files and directories in the specified archive.

Definition at line 192 of file archive.cpp.

◆ workingCopyPath()

CPP_UTILITIES_EXPORT std::string CppUtilities::workingCopyPath ( const std::string & relativeTestFilePath,
WorkingCopyMode mode = WorkingCopyMode::CreateCopy )
inline

Convenience function to invoke TestApplication::workingCopyPath().

Remarks
A TestApplication must be present.

Definition at line 179 of file testutils.h.

◆ workingCopyPathAs()

CPP_UTILITIES_EXPORT std::string CppUtilities::workingCopyPathAs ( const std::string & relativeTestFilePath,
const std::string & relativeWorkingCopyPath,
WorkingCopyMode mode = WorkingCopyMode::CreateCopy )
inline

Convenience function to invoke TestApplication::workingCopyPathAs().

Remarks
A TestApplication must be present.

Definition at line 188 of file testutils.h.

◆ writeFile()

void CppUtilities::writeFile ( std::string_view path,
std::string_view contents )

Writes all contents to the specified file in a single call.

Exceptions
Throwsstd::ios_base::failure when an error occurs.
Remarks
Closing the file manually to prevent flushing the file within the d'tor which would suppress an exception

Definition at line 58 of file misc.cpp.

Variable Documentation

◆ applicationInfo

CPP_UTILITIES_EXPORT ApplicationInfo CppUtilities::applicationInfo

Stores global application info used by ArgumentParser::printHelp() and AboutDialog.

Definition at line 436 of file argumentparser.cpp.