C++ Utilities  5.5.0
Useful C++ classes and routines such as argument parser, IO and conversion utilities
Namespaces | Classes | Typedefs | Enumerations | Functions | Variables
CppUtilities Namespace Reference

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

Namespaces

 BE
 Encapsulates binary conversion functions using the big endian byte order.
 
 EscapeCodes
 Encapsulates functions for formatted terminal output using ANSI escape codes.
 
 FlagEnumClassOperations
 The FlagEnumClassOperations namespace contains operations for flag enums.
 
 LE
 Encapsulates binary conversion functions using the little endian byte order.
 
 Literals
 Contains literals to ease asserting with CPPUNIT_ASSERT_EQUAL.
 
 Traits
 Contains traits for conveniently exploiting SFINAE.
 
 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  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  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...
 
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 \tp T. 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. More...
 
using NativeFileStream = std::fstream
 

Enumerations

enum  UnknownArgumentBehavior { UnknownArgumentBehavior::Ignore, UnknownArgumentBehavior::Warn, UnknownArgumentBehavior::Fail }
 The UnknownArgumentBehavior enum specifies the behavior of the argument parser when an unknown argument is detected. More...
 
enum  ParseArgumentBehavior { ParseArgumentBehavior::ReadArguments = 0x0, ParseArgumentBehavior::CheckConstraints = 0x1, ParseArgumentBehavior::InvokeCallbacks = 0x2, ParseArgumentBehavior::ExitOnFailure = 0x4 }
 The ParseArgumentBehavior enum specifies the behavior when parsing arguments. More...
 
enum  ValueCompletionBehavior : unsigned char {
  ValueCompletionBehavior::None = 0, ValueCompletionBehavior::PreDefinedValues = 2, ValueCompletionBehavior::Files = 4, ValueCompletionBehavior::Directories = 8,
  ValueCompletionBehavior::FileSystemIfNoPreDefinedValues = 16, ValueCompletionBehavior::AppendEquationSign = 32, ValueCompletionBehavior::InvokeCallback = 64
}
 The ValueCompletionBehavior enum specifies the items to be considered when generating completion for an argument value. More...
 
enum  Response { Response::None, Response::Yes, Response::No }
 The Response enum is used to specify the default response for the confirmPrompt() method. More...
 
enum  DateTimeOutputFormat {
  DateTimeOutputFormat::DateAndTime, DateTimeOutputFormat::DateOnly, DateTimeOutputFormat::TimeOnly, DateTimeOutputFormat::DateTimeAndWeekday,
  DateTimeOutputFormat::DateTimeAndShortWeekday, DateTimeOutputFormat::Iso, DateTimeOutputFormat::IsoOmittingDefaultComponents
}
 Specifies the output format. More...
 
enum  DayOfWeek {
  DayOfWeek::Monday, DayOfWeek::Tuesday, DayOfWeek::Wednesday, DayOfWeek::Thursday,
  DayOfWeek::Friday, DayOfWeek::Saturday, DayOfWeek::Sunday
}
 Specifies the day of the week. More...
 
enum  DatePart { DatePart::Year, DatePart::Month, DatePart::DayOfYear, DatePart::Day }
 Specifies the date part. More...
 
enum  TimeSpanOutputFormat { TimeSpanOutputFormat::Normal, TimeSpanOutputFormat::WithMeasures, TimeSpanOutputFormat::TotalSeconds }
 Specifies the output format. More...
 
enum  EmptyPartsTreat { EmptyPartsTreat::Keep, EmptyPartsTreat::Omit, EmptyPartsTreat::Merge }
 Specifies the role of empty parts when splitting strings. More...
 
enum  IniFileParseOptions { IniFileParseOptions::None = 0 }
 
enum  IniFileMakeOptions { IniFileMakeOptions::None = 0 }
 
enum  IniFileFieldFlags { IniFileFieldFlags::None = 0, IniFileFieldFlags::HasValue = (1 << 0) }
 
enum  IniFileSectionFlags { IniFileSectionFlags::None = 0, IniFileSectionFlags::Implicit = (1 << 0), IniFileSectionFlags::Truncated = (1 << 1) }
 
enum  WorkingCopyMode { WorkingCopyMode::CreateCopy, WorkingCopyMode::NoCopy }
 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...
 

Functions

CPP_UTILITIES_EXPORT bool confirmPrompt (const char *message, Response defaultResponse)
 Prompts for confirmation displaying the specified message. More...
 
CPP_UTILITIES_EXPORT TerminalSize determineTerminalSize ()
 Returns the current size of the terminal. More...
 
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. More...
 
constexpr CPP_UTILITIES_EXPORT std::uint16_t toFixed8 (float float32value)
 Returns the 8.8 fixed point representation converted from the specified 32-bit floating point number. More...
 
constexpr CPP_UTILITIES_EXPORT float toFloat32 (std::uint16_t fixed8value)
 Returns a 32-bit floating point number converted from the specified 8.8 fixed point representation. More...
 
constexpr CPP_UTILITIES_EXPORT std::uint32_t toFixed16 (float float32value)
 Returns the 16.16 fixed point representation converted from the specified 32-bit floating point number. More...
 
constexpr CPP_UTILITIES_EXPORT float toFloat32 (std::uint32_t fixed16value)
 Returns a 32-bit floating point number converted from the specified 16.16 fixed point representation. More...
 
constexpr CPP_UTILITIES_EXPORT std::uint32_t toSynchsafeInt (std::uint32_t normalInt)
 Returns a 32-bit synchsafe integer converted from a normal 32-bit integer. More...
 
constexpr CPP_UTILITIES_EXPORT std::uint32_t toNormalInt (std::uint32_t synchsafeInt)
 Returns a normal 32-bit integer converted from a 32-bit synchsafe integer. More...
 
constexpr CPP_UTILITIES_EXPORT std::uint16_t swapOrder (std::uint16_t value)
 Swaps the byte order of the specified 16-bit unsigned integer. More...
 
constexpr CPP_UTILITIES_EXPORT std::uint32_t swapOrder (std::uint32_t value)
 Swaps the byte order of the specified 32-bit unsigned integer. More...
 
constexpr CPP_UTILITIES_EXPORT std::uint64_t swapOrder (std::uint64_t value)
 Swaps the byte order of the specified 64-bit unsigned integer. More...
 
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. More...
 
CPP_UTILITIES_EXPORT StringData convertUtf8ToUtf16LE (const char *inputBuffer, std::size_t inputBufferSize)
 Converts the specified UTF-8 string to UTF-16 (little-endian). More...
 
CPP_UTILITIES_EXPORT StringData convertUtf16LEToUtf8 (const char *inputBuffer, std::size_t inputBufferSize)
 Converts the specified UTF-16 (little-endian) string to UTF-8. More...
 
CPP_UTILITIES_EXPORT StringData convertUtf8ToUtf16BE (const char *inputBuffer, std::size_t inputBufferSize)
 Converts the specified UTF-8 string to UTF-16 (big-endian). More...
 
CPP_UTILITIES_EXPORT StringData convertUtf16BEToUtf8 (const char *inputBuffer, std::size_t inputBufferSize)
 Converts the specified UTF-16 (big-endian) string to UTF-8. More...
 
CPP_UTILITIES_EXPORT StringData convertLatin1ToUtf8 (const char *inputBuffer, std::size_t inputBufferSize)
 Converts the specified Latin-1 string to UTF-8. More...
 
CPP_UTILITIES_EXPORT StringData convertUtf8ToLatin1 (const char *inputBuffer, std::size_t inputBufferSize)
 Converts the specified UTF-8 string to Latin-1. More...
 
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. More...
 
template<class Container = std::initializer_list<std::string>>
Container::value_type joinStrings (const Container &strings, const typename Container::value_type &delimiter=typename Container::value_type(), bool omitEmpty=false, const typename Container::value_type &leftClosure=typename Container::value_type(), const typename Container::value_type &rightClosure=typename Container::value_type())
 Joins the given strings using the specified delimiter. More...
 
template<class Container = std::initializer_list<std::string>>
std::vector< std::string > toMultiline (const Container &arrayOfLines)
 Converts the specified arrayOfLines to a multiline string. More...
 
template<class Container = std::list<std::string>>
Container splitString (const typename Container::value_type &string, const typename Container::value_type &delimiter, EmptyPartsTreat emptyPartsRole=EmptyPartsTreat::Keep, int maxParts=-1)
 Splits the given string at the specified delimiter. More...
 
template<class Container = std::list<std::string>>
Container splitStringSimple (const typename Container::value_type &string, const typename Container::value_type &delimiter, int maxParts=-1)
 Splits the given string (which might also be a string view) at the specified delimiter. More...
 
template<class Container = std::vector<std::string>>
std::vector< std::string > toArrayOfLines (const std::string &multilineString)
 Converts the specified multilineString to an array of lines. More...
 
template<typename StringType >
bool startsWith (const StringType &str, const StringType &phrase)
 Returns whether str starts with phrase. More...
 
template<typename StringType >
bool startsWith (const StringType &str, const typename StringType::value_type *phrase)
 Returns whether str starts with phrase. More...
 
template<typename StringType >
bool endsWith (const StringType &str, const StringType &phrase)
 Returns whether str ends with phrase. More...
 
template<typename StringType >
bool endsWith (const StringType &str, const typename StringType::value_type *phrase)
 Returns whether str ends with phrase. More...
 
template<typename StringType >
bool containsSubstrings (const StringType &str, std::initializer_list< StringType > substrings)
 Returns whether str contains the specified substrings. More...
 
template<typename StringType >
bool containsSubstrings (const StringType &str, std::initializer_list< const typename StringType::value_type * > substrings)
 Returns whether str contains the specified substrings. More...
 
template<typename StringType >
void findAndReplace (StringType &str, const StringType &find, const StringType &replace)
 Replaces all occurences of find with relpace in the specified str. More...
 
template<typename CharType >
constexpr CharType digitToChar (CharType digit)
 Returns the character representation of the specified digit. More...
 
template<typename IntegralType , class StringType = std::string, CppUtilities::Traits::EnableIf< std::is_integral< IntegralType >, std::is_unsigned< IntegralType >> * = nullptr>
StringType numberToString (IntegralType number, typename StringType::value_type base=10)
 Converts the given number to its equivalent string representation using the specified base. More...
 
template<typename FloatingType , class StringType = std::string, Traits::EnableIf< std::is_floating_point< FloatingType >> * = nullptr>
StringType numberToString (FloatingType number, typename StringType::value_type base=10)
 Converts the given number to its equivalent string representation using the specified base. More...
 
template<typename CharType >
CharType charToDigit (CharType character, CharType base)
 Returns number/digit of the specified character representation using the specified base. More...
 
template<typename IntegralType , typename StringType , Traits::EnableIf< std::is_integral< IntegralType >, std::is_unsigned< IntegralType >> * = nullptr>
IntegralType stringToNumber (const StringType &string, typename StringType::value_type base=10)
 Converts the given string to an unsigned number assuming string uses the specified base. More...
 
template<typename FloatingType , class StringType , Traits::EnableIf< std::is_floating_point< FloatingType >> * = nullptr>
FloatingType stringToNumber (const StringType &string, typename StringType::value_type base=10)
 Converts the given string to a number assuming string uses the specified base. More...
 
template<typename IntegralType , class CharType , Traits::EnableIf< std::is_integral< IntegralType >, std::is_unsigned< IntegralType >> * = nullptr>
IntegralType stringToNumber (const CharType *string, unsigned char base=10)
 Converts the given null-terminated string to an unsigned numeric value using the specified base. More...
 
template<typename FloatingType , class CharType , Traits::EnableIf< std::is_floating_point< FloatingType >> * = nullptr>
FloatingType stringToNumber (const CharType *string, unsigned char base=10)
 Converts the given null-terminated string to a number assuming string uses the specified base. More...
 
template<typename IntegralType , class CharType , Traits::EnableIf< std::is_integral< IntegralType >, std::is_unsigned< IntegralType >> * = nullptr>
IntegralType bufferToNumber (const CharType *string, std::size_t size, unsigned char base=10)
 Converts the given string of size characters to an unsigned numeric value using the specified base. More...
 
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. More...
 
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. More...
 
CPP_UTILITIES_EXPORT std::string bitrateToString (double bitrateInKbitsPerSecond, bool useIecBinaryPrefixes)
 Converts the specified bitrate in kbit/s to its equivalent std::string representation. More...
 
CPP_UTILITIES_EXPORT std::string encodeBase64 (const std::uint8_t *data, std::uint32_t dataSize)
 Encodes the specified data to Base64. More...
 
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. More...
 
template<class StringType = std::string, class... Args>
StringType tupleToString (const std::tuple< Args... > &tuple)
 Concatenates all strings hold by the specified tuple. More...
 
template<class StringType = std::string, class... Args>
StringType argsToString (Args &&... args)
 
template<class Tuple , class StringType , Traits::EnableIfAny< Traits::IsSpecializationOf< StringType, std::basic_string >, Traits::IsSpecializationOf< StringType, std::basic_string_view >> * = nullptr>
constexpr auto operator% (const Tuple &lhs, const StringType &rhs) -> decltype(std::tuple_cat(lhs, std::make_tuple(&rhs)))
 Allows construction of string-tuples via %-operator, eg. More...
 
template<class Tuple >
constexpr auto operator% (const Tuple &lhs, const char *rhs) -> decltype(std::tuple_cat(lhs, std::make_tuple(rhs)))
 Allows construction of string-tuples via %-operator, eg. More...
 
template<class Tuple , typename IntegralType , Traits::EnableIf< std::is_integral< IntegralType >> * = nullptr>
constexpr auto operator% (const Tuple &lhs, IntegralType rhs) -> decltype(std::tuple_cat(lhs, std::make_tuple(rhs)))
 Allows construction of string-tuples via %-operator, eg. More...
 
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::make_tuple(&lhs, &rhs))
 Allows construction of string-tuples via %-operator, eg. More...
 
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::make_tuple(lhs, &rhs))
 Allows construction of string-tuples via %-operator, eg. More...
 
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::make_tuple(&lhs, rhs))
 Allows construction of string-tuples via %-operator, eg. More...
 
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::make_tuple(&lhs, rhs))
 Allows construction of string-tuples via %-operator, eg. More...
 
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::make_tuple(lhs, &rhs))
 Allows construction of string-tuples via %-operator, eg. More...
 
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. More...
 
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. More...
 
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. More...
 
CPP_UTILITIES_EXPORT std::string fileName (const string &path)
 Returns the file name and extension of the specified path string. More...
 
CPP_UTILITIES_EXPORT std::string directory (const string &path)
 Returns the directory of the specified path string (including trailing slash). More...
 
CPP_UTILITIES_EXPORT void removeInvalidChars (std::string &fileName)
 Removes invalid characters from the specified fileName. More...
 
CPP_UTILITIES_EXPORT std::string readFile (const std::string &path, std::string::size_type maxSize)
 Reads all contents of the specified file in a single call. More...
 
CPP_UTILITIES_EXPORT void writeFile (std::string_view path, std::string_view contents)
 Writes all contents to the specified file in a single call. More...
 
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. More...
 
template<typename IntegralType , Traits::EnableIf< std::is_integral< IntegralType >> * = nullptr>
constexpr IntegralType factorial (IntegralType number)
 Returns the factorial of the given number. More...
 
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. More...
 
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. More...
 
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. More...
 
template<typename T >
constexpr T min (T first, T second)
 Returns the smallest of the given items. More...
 
template<typename T1 , typename... T2>
constexpr T1 min (T1 first, T1 second, T2... remaining)
 Returns the smallest of the given items. More...
 
template<typename T >
constexpr T max (T first, T second)
 Returns the greatest of the given items. More...
 
template<typename T1 , typename... T2>
constexpr T1 max (T1 first, T1 second, T2... remaining)
 Returns the greatest of the given items. More...
 
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. More...
 
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. More...
 
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. More...
 
CPP_UTILITIES_EXPORT std::ostream & operator<< (std::ostream &o, const ParseError &failure)
 Prints an error message "Unable to parse arguments: ..." for the specified failure. More...
 
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(). More...
 
CPP_UTILITIES_EXPORT std::string workingCopyPath (const std::string &relativeTestFilePath, WorkingCopyMode mode=WorkingCopyMode::CreateCopy)
 Convenience function to invoke TestApplication::workingCopyPath(). More...
 
CPP_UTILITIES_EXPORT std::string workingCopyPathAs (const std::string &relativeTestFilePath, const std::string &relativeWorkingCopyPath, WorkingCopyMode mode=WorkingCopyMode::CreateCopy)
 Convenience function to invoke TestApplication::workingCopyPathAs(). More...
 
template<typename T >
bool operator== (const AsHexNumber< T > &lhs, const AsHexNumber< T > &rhs)
 Provides operator == required by CPPUNIT_ASSERT_EQUAL. More...
 
template<typename T >
std::ostream & operator<< (std::ostream &out, const AsHexNumber< T > &value)
 Provides the actual formatting of the output for AsHexNumber class. More...
 
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). More...
 
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). More...
 
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). More...
 
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. More...
 
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. More...
 
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. More...
 
bool compareArgs (const Argument *arg1, const Argument *arg2)
 Returns whether arg1 should be listed before arg2 when printing completion. More...
 
void insertSiblings (const ArgumentVector &siblings, list< const Argument * > &target)
 Inserts the specified siblings in the target list. More...
 
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::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. More...
 

Variables

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

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 = typedef std::initializer_list<Argument *>

Definition at line 67 of file argumentparser.h.

◆ ArgumentPredicate

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

Definition at line 69 of file argumentparser.h.

◆ ArgumentVector

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

Definition at line 68 of file argumentparser.h.

◆ NativeFileStream

using CppUtilities::NativeFileStream = typedef std::fstream

Definition at line 108 of file nativefilestream.h.

◆ StringData

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

Type used to return string encoding conversion result.

Definition at line 39 of file stringconversion.h.

Enumeration Type Documentation

◆ 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

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 46 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 17 of file datetime.h.

◆ DayOfWeek

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 31 of file datetime.h.

◆ EmptyPartsTreat

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 122 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 87 of file argumentparser.h.

◆ Response

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

Enumerator
None 
Yes 
No 

Definition at line 18 of file commandlineutils.h.

◆ TimeSpanOutputFormat

Specifies the output format.

See also
TimeSpan::toString()
Enumerator
Normal 

the normal form of specifing 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 75 of file argumentparser.h.

◆ ValueCompletionBehavior

enum 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 116 of file argumentparser.h.

◆ WorkingCopyMode

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

Definition at line 16 of file testutils.h.

Function Documentation

◆ argsToString()

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

Definition at line 258 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 222 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 302 of file stringconversion.cpp.

◆ bufferToNumber()

template<typename IntegralType , class CharType , Traits::EnableIf< std::is_integral< IntegralType >, std::is_unsigned< IntegralType >> * = nullptr>
IntegralType CppUtilities::bufferToNumber ( const CharType *  string,
std::size_t  size,
unsigned char  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 568 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.
Todo:
Provide an alternative using std::expected (when switching to C++17).

Definition at line 408 of file stringconversion.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 1078 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 117 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 21 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 301 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 284 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 179 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" referes 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 134 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 170 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 152 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 188 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 161 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 143 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 270 of file stringconversion.cpp.

◆ decodeBase64()

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 381 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 46 of file commandlineutils.cpp.

◆ digitsum()

template<typename IntegralType , Traits::EnableIf< std::is_integral< IntegralType >> * = nullptr>
constexpr 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 >
constexpr 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 329 of file stringconversion.h.

◆ directory()

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

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

Definition at line 35 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 341 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 250 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 266 of file stringconversion.h.

◆ factorial()

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

Returns the factorial of the given number.

Definition at line 29 of file math.h.

◆ fileName()

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

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

Definition at line 15 of file path.cpp.

◆ findAndReplace()

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

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

Definition at line 316 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 576 of file argumentparser.cpp.

◆ inRangeExclMax()

template<typename num1 , typename num2 , typename num3 >
constexpr 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 >
constexpr 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 1093 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 232 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 242 of file testutils.h.

◆ interpretIntegerAsString()

template<typename T >
std::string CppUtilities::interpretIntegerAsString ( 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 657 of file stringconversion.h.

◆ inverseModulo()

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

Computes the inverse of number modulo module.

Definition at line 61 of file math.h.

◆ joinStrings()

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

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 appendend after each string (empty string by default).
Template Parameters
ContainerThe STL-container used to provide the strings.
Returns
Returns the joined string.

Definition at line 75 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 174 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 166 of file multiarray.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 182 of file multiarray.h.

◆ max() [1/2]

template<typename T >
constexpr T CppUtilities::max ( first,
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>
constexpr 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 >
constexpr T CppUtilities::min ( first,
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>
constexpr 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.

◆ numberToString() [1/2]

template<typename FloatingType , class StringType = std::string, Traits::EnableIf< std::is_floating_point< FloatingType >> * = nullptr>
StringType CppUtilities::numberToString ( FloatingType  number,
typename StringType::value_type  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 interanlly and hence also has its limitations (eg. regarding base and types).
See also
stringToNumber(), bufferToNumber()

Definition at line 396 of file stringconversion.h.

◆ numberToString() [2/2]

template<typename IntegralType , class StringType = std::string, CppUtilities::Traits::EnableIf< std::is_integral< IntegralType >, std::is_unsigned< IntegralType >> * = nullptr>
StringType CppUtilities::numberToString ( IntegralType  number,
typename StringType::value_type  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 342 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>
constexpr auto CppUtilities::operator% ( char  lhs,
const StringType &  rhs 
) -> decltype(std::make_tuple(lhs, &rhs))
constexpr

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

string1 % "string2" % string3.

Definition at line 341 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>
constexpr auto CppUtilities::operator% ( const char *  lhs,
const StringType &  rhs 
) -> decltype(std::make_tuple(lhs, &rhs))
constexpr

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

string1 % "string2" % string3.

Definition at line 308 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>
constexpr auto CppUtilities::operator% ( const StringType &  lhs,
char  rhs 
) -> decltype(std::make_tuple(&lhs, rhs))
constexpr

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

string1 % "string2" % string3.

Definition at line 330 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>
constexpr auto CppUtilities::operator% ( const StringType &  lhs,
const char *  rhs 
) -> decltype(std::make_tuple(&lhs, rhs))
constexpr

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

string1 % "string2" % string3.

Definition at line 319 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>
constexpr auto CppUtilities::operator% ( const StringType &  lhs,
const StringType &  rhs 
) -> decltype(std::make_tuple(&lhs, &rhs))
constexpr

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

string1 % "string2" % string3.

Definition at line 297 of file stringbuilder.h.

◆ operator%() [6/8]

template<class Tuple >
constexpr auto CppUtilities::operator% ( const Tuple &  lhs,
const char *  rhs 
) -> decltype(std::tuple_cat(lhs, std::make_tuple(rhs)))
constexpr

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

string1 % "string2" % string3.

Definition at line 277 of file stringbuilder.h.

◆ operator%() [7/8]

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

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

string1 % "string2" % string3.

Definition at line 269 of file stringbuilder.h.

◆ operator%() [8/8]

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

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

string1 % "string2" % string3.

Definition at line 286 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)"));

Definition at line 374 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 359 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 390 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/6]

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/6]

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

Definition at line 403 of file argumentparser.cpp.

◆ operator<<() [3/6]

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 213 of file testutils.h.

◆ operator<<() [4/6]

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 293 of file testutils.h.

◆ operator<<() [5/6]

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 284 of file testutils.h.

◆ operator<<() [6/6]

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

Definition at line 83 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 205 of file testutils.h.

◆ orderModulo()

template<typename IntegralType , Traits::EnableIf< std::is_integral< IntegralType >, std::is_unsigned< IntegralType >> * = nullptr>
constexpr 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>
constexpr 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()

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.
Todo:
Use std::string_view to pass path in v6.

Definition at line 16 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 57 of file path.cpp.

◆ splitString()

template<class Container = std::list<std::string>>
Container CppUtilities::splitString ( const typename Container::value_type &  string,
const typename Container::value_type &  delimiter,
EmptyPartsTreat  emptyPartsRole = EmptyPartsTreat::Keep,
int  maxParts = -1 
)

Splits the given string at the specified delimiter.

Parameters
stringThe string to be splitted.
delimiterSpecifies the delimiter.
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 138 of file stringconversion.h.

◆ splitStringSimple()

template<class Container = std::list<std::string>>
Container CppUtilities::splitStringSimple ( const typename Container::value_type &  string,
const typename Container::value_type &  delimiter,
int  maxParts = -1 
)

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

Parameters
stringThe string to be splitted.
delimiterSpecifies the delimiter.
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 185 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 213 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 233 of file stringconversion.h.

◆ stringToNumber() [1/4]

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

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

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()
Todo:
Provide an alternative using std::expected (when switching to C++17).
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 520 of file stringconversion.h.

◆ stringToNumber() [2/4]

template<typename FloatingType , class CharType , Traits::EnableIf< std::is_floating_point< FloatingType >> * = nullptr>
FloatingType CppUtilities::stringToNumber ( const CharType *  string,
unsigned char  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 interanlly and hence also has its limitations (eg. regarding base and types).
See also
numberToString(), bufferToNumber()
Todo:
Provide an alternative using std::expected (when switching to C++17).

Definition at line 544 of file stringconversion.h.

◆ stringToNumber() [3/4]

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

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

Converts the given string to a 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()
Todo:
Provide an alternative using std::expected (when switching to C++17).
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()
Todo:
Provide an alternative using std::expected (when switching to C++17).

Definition at line 438 of file stringconversion.h.

◆ stringToNumber() [4/4]

template<typename FloatingType , class StringType , Traits::EnableIf< std::is_floating_point< FloatingType >> * = nullptr>
FloatingType CppUtilities::stringToNumber ( const StringType &  string,
typename StringType::value_type  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 interanlly and hence also has its limitations (eg. regarding base and types).
See also
numberToString(), bufferToNumber()
Todo:
Provide an alternative using std::expected (when switching to C++17).

Definition at line 495 of file stringconversion.h.

◆ swapOrder() [1/3]

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

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

Definition at line 154 of file binaryconversion.h.

◆ swapOrder() [2/3]

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

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

Definition at line 162 of file binaryconversion.h.

◆ swapOrder() [3/3]

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

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

Definition at line 170 of file binaryconversion.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 147 of file testutils.h.

◆ toArrayOfLines()

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

Converts the specified multilineString to an array of lines.

Definition at line 205 of file stringconversion.h.

◆ toFixed16()

constexpr CPP_UTILITIES_EXPORT 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 117 of file binaryconversion.h.

◆ toFixed8()

constexpr CPP_UTILITIES_EXPORT 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 101 of file binaryconversion.h.

◆ toFloat32() [1/2]

constexpr CPP_UTILITIES_EXPORT 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 109 of file binaryconversion.h.

◆ toFloat32() [2/2]

constexpr CPP_UTILITIES_EXPORT 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 125 of file binaryconversion.h.

◆ toMultiline()

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

Converts the specified arrayOfLines to a multiline string.

Definition at line 114 of file stringconversion.h.

◆ toNormalInt()

constexpr CPP_UTILITIES_EXPORT 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 145 of file binaryconversion.h.

◆ toSynchsafeInt()

constexpr CPP_UTILITIES_EXPORT 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 135 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 257 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 250 of file stringbuilder.h.

◆ 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 156 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 165 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 39 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 432 of file argumentparser.cpp.

CppUtilities::numberToString
StringType numberToString(IntegralType number, typename StringType::value_type base=10)
Converts the given number to its equivalent string representation using the specified base.
Definition: stringconversion.h:342