Apply clang-format
This commit is contained in:
parent
7e49d3994f
commit
59e20b1043
|
@ -3,17 +3,17 @@
|
|||
#include "./commandlineutils.h"
|
||||
#include "./failure.h"
|
||||
|
||||
#include "../conversion/stringconversion.h"
|
||||
#include "../conversion/stringbuilder.h"
|
||||
#include "../io/path.h"
|
||||
#include "../conversion/stringconversion.h"
|
||||
#include "../io/ansiescapecodes.h"
|
||||
#include "../io/path.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <cstring>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
using namespace std::placeholders;
|
||||
|
@ -41,16 +41,17 @@ enum ArgumentDenotationType : unsigned char {
|
|||
* - For meaning of parameter see documentation of corresponding member variables.
|
||||
* - Results are stored in specified \a args and assigned sub arguments.
|
||||
*/
|
||||
ArgumentReader::ArgumentReader(ArgumentParser &parser, const char * const *argv, const char * const *end, bool completionMode) :
|
||||
parser(parser),
|
||||
args(parser.m_mainArgs),
|
||||
index(0),
|
||||
argv(argv),
|
||||
end(end),
|
||||
lastArg(nullptr),
|
||||
argDenotation(nullptr),
|
||||
completionMode(completionMode)
|
||||
{}
|
||||
ArgumentReader::ArgumentReader(ArgumentParser &parser, const char *const *argv, const char *const *end, bool completionMode)
|
||||
: parser(parser)
|
||||
, args(parser.m_mainArgs)
|
||||
, index(0)
|
||||
, argv(argv)
|
||||
, end(end)
|
||||
, lastArg(nullptr)
|
||||
, argDenotation(nullptr)
|
||||
, completionMode(completionMode)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Resets the ArgumentReader to continue reading new \a argv.
|
||||
|
@ -111,8 +112,7 @@ void ArgumentReader::read(ArgumentVector &args)
|
|||
}
|
||||
abbreviationFound = false;
|
||||
argDenotationType = Value;
|
||||
*argDenotation == '-' && (++argDenotation, ++argDenotationType)
|
||||
&& *argDenotation == '-' && (++argDenotation, ++argDenotationType);
|
||||
*argDenotation == '-' && (++argDenotation, ++argDenotationType) && *argDenotation == '-' && (++argDenotation, ++argDenotationType);
|
||||
}
|
||||
|
||||
// try to find matching Argument instance
|
||||
|
@ -120,7 +120,8 @@ void ArgumentReader::read(ArgumentVector &args)
|
|||
size_t argDenotationLength;
|
||||
if (argDenotationType != Value) {
|
||||
const char *const equationPos = strchr(argDenotation, '=');
|
||||
for(argDenotationLength = equationPos ? static_cast<size_t>(equationPos - argDenotation) : strlen(argDenotation); argDenotationLength; matchingArg = nullptr) {
|
||||
for (argDenotationLength = equationPos ? static_cast<size_t>(equationPos - argDenotation) : strlen(argDenotation);
|
||||
argDenotationLength; matchingArg = nullptr) {
|
||||
// search for arguments by abbreviation or name depending on the previously determined denotation type
|
||||
if (argDenotationType == Abbreviation) {
|
||||
for (Argument *arg : args) {
|
||||
|
@ -132,7 +133,8 @@ void ArgumentReader::read(ArgumentVector &args)
|
|||
}
|
||||
} else {
|
||||
for (Argument *arg : args) {
|
||||
if(arg->name() && !strncmp(arg->name(), argDenotation, argDenotationLength) && *(arg->name() + argDenotationLength) == '\0') {
|
||||
if (arg->name() && !strncmp(arg->name(), argDenotation, argDenotationLength)
|
||||
&& *(arg->name() + argDenotationLength) == '\0') {
|
||||
matchingArg = arg;
|
||||
break;
|
||||
}
|
||||
|
@ -208,7 +210,8 @@ void ArgumentReader::read(ArgumentVector &args)
|
|||
if (!matchingArg && (!completionMode || (argv + 1 != end))) {
|
||||
const bool uncombinableMainArgPresent = parentArg ? false : parser.isUncombinableMainArgPresent();
|
||||
for (Argument *arg : args) {
|
||||
if(arg->isImplicit() && !arg->isPresent() && !arg->wouldConflictWithArgument() && (!uncombinableMainArgPresent || !arg->isMainArgument())) {
|
||||
if (arg->isImplicit() && !arg->isPresent() && !arg->wouldConflictWithArgument()
|
||||
&& (!uncombinableMainArgPresent || !arg->isMainArgument())) {
|
||||
(matchingArg = arg)->m_occurrences.emplace_back(index, parentPath, parentArg);
|
||||
break;
|
||||
}
|
||||
|
@ -299,28 +302,31 @@ inline bool notEmpty(const char *str)
|
|||
* The \a name and the abbreviation mustn't contain any whitespaces.
|
||||
* The \a name mustn't be empty. The \a abbreviation and the \a description might be empty.
|
||||
*/
|
||||
Argument::Argument(const char *name, char abbreviation, const char *description, const char *example) :
|
||||
m_name(name),
|
||||
m_abbreviation(abbreviation),
|
||||
m_environmentVar(nullptr),
|
||||
m_description(description),
|
||||
m_example(example),
|
||||
m_minOccurrences(0),
|
||||
m_maxOccurrences(1),
|
||||
m_combinable(false),
|
||||
m_denotesOperation(false),
|
||||
m_requiredValueCount(0),
|
||||
m_implicit(false),
|
||||
m_isMainArg(false),
|
||||
m_valueCompletionBehavior(ValueCompletionBehavior::PreDefinedValues | ValueCompletionBehavior::Files | ValueCompletionBehavior::Directories | ValueCompletionBehavior::FileSystemIfNoPreDefinedValues),
|
||||
m_preDefinedCompletionValues(nullptr)
|
||||
{}
|
||||
Argument::Argument(const char *name, char abbreviation, const char *description, const char *example)
|
||||
: m_name(name)
|
||||
, m_abbreviation(abbreviation)
|
||||
, m_environmentVar(nullptr)
|
||||
, m_description(description)
|
||||
, m_example(example)
|
||||
, m_minOccurrences(0)
|
||||
, m_maxOccurrences(1)
|
||||
, m_combinable(false)
|
||||
, m_denotesOperation(false)
|
||||
, m_requiredValueCount(0)
|
||||
, m_implicit(false)
|
||||
, m_isMainArg(false)
|
||||
, m_valueCompletionBehavior(ValueCompletionBehavior::PreDefinedValues | ValueCompletionBehavior::Files | ValueCompletionBehavior::Directories
|
||||
| ValueCompletionBehavior::FileSystemIfNoPreDefinedValues)
|
||||
, m_preDefinedCompletionValues(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Destroys the Argument.
|
||||
*/
|
||||
Argument::~Argument()
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Returns the first parameter value of the first occurrence of the argument.
|
||||
|
@ -536,12 +542,13 @@ void Argument::resetRecursively()
|
|||
/*!
|
||||
* \brief Constructs a new ArgumentParser.
|
||||
*/
|
||||
ArgumentParser::ArgumentParser() :
|
||||
m_actualArgc(0),
|
||||
m_executable(nullptr),
|
||||
m_unknownArgBehavior(UnknownArgumentBehavior::Fail),
|
||||
m_defaultArg(nullptr)
|
||||
{}
|
||||
ArgumentParser::ArgumentParser()
|
||||
: m_actualArgc(0)
|
||||
, m_executable(nullptr)
|
||||
, m_unknownArgBehavior(UnknownArgumentBehavior::Fail)
|
||||
, m_defaultArg(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the main arguments for the parser. The parser will use these argument definitions
|
||||
|
@ -685,7 +692,9 @@ void ArgumentParser::readArgs(int argc, const char * const *argv)
|
|||
}
|
||||
|
||||
// read specified arguments
|
||||
ArgumentReader reader(*this, argv, argv + (completionMode ? min(static_cast<unsigned int>(argc), currentWordIndex + 1) : static_cast<unsigned int>(argc)), completionMode);
|
||||
ArgumentReader reader(*this, argv,
|
||||
argv + (completionMode ? min(static_cast<unsigned int>(argc), currentWordIndex + 1) : static_cast<unsigned int>(argc)),
|
||||
completionMode);
|
||||
try {
|
||||
reader.read();
|
||||
} catch (const Failure &) {
|
||||
|
@ -841,7 +850,8 @@ void ArgumentParser::printBashCompletion(int argc, const char *const *argv, unsi
|
|||
if (argc) {
|
||||
lastSpecifiedArgIndex = static_cast<unsigned int>(argc) - 1;
|
||||
lastSpecifiedArg = argv + lastSpecifiedArgIndex;
|
||||
for(; lastSpecifiedArg >= argv && **lastSpecifiedArg == '\0'; --lastSpecifiedArg, --lastSpecifiedArgIndex);
|
||||
for (; lastSpecifiedArg >= argv && **lastSpecifiedArg == '\0'; --lastSpecifiedArg, --lastSpecifiedArgIndex)
|
||||
;
|
||||
}
|
||||
|
||||
// determine arguments relevant for completion
|
||||
|
@ -857,13 +867,15 @@ void ArgumentParser::printBashCompletion(int argc, const char *const *argv, unsi
|
|||
if (lastDetectedArg->valueCompletionBehaviour() & ValueCompletionBehavior::PreDefinedValues) {
|
||||
relevantPreDefinedValues.push_back(lastDetectedArg);
|
||||
}
|
||||
if(!(lastDetectedArg->valueCompletionBehaviour() & ValueCompletionBehavior::FileSystemIfNoPreDefinedValues) || !lastDetectedArg->preDefinedCompletionValues()) {
|
||||
if (!(lastDetectedArg->valueCompletionBehaviour() & ValueCompletionBehavior::FileSystemIfNoPreDefinedValues)
|
||||
|| !lastDetectedArg->preDefinedCompletionValues()) {
|
||||
completeFiles = completeFiles || lastDetectedArg->valueCompletionBehaviour() & ValueCompletionBehavior::Files;
|
||||
completeDirs = completeDirs || lastDetectedArg->valueCompletionBehaviour() & ValueCompletionBehavior::Directories;
|
||||
}
|
||||
}
|
||||
|
||||
if(lastDetectedArg->requiredValueCount() == static_cast<size_t>(-1) || lastDetectedArg->values(lastDetectedArg->occurrences() - 1).size() >= lastDetectedArg->requiredValueCount()) {
|
||||
if (lastDetectedArg->requiredValueCount() == static_cast<size_t>(-1)
|
||||
|| lastDetectedArg->values(lastDetectedArg->occurrences() - 1).size() >= lastDetectedArg->requiredValueCount()) {
|
||||
// sub arguments of the last arg are possible completions
|
||||
for (const Argument *subArg : lastDetectedArg->subArguments()) {
|
||||
if (subArg->occurrences() < subArg->maxOccurrences()) {
|
||||
|
@ -920,8 +932,7 @@ void ArgumentParser::printBashCompletion(int argc, const char *const *argv, unsi
|
|||
} else {
|
||||
opening = *lastSpecifiedArg;
|
||||
}
|
||||
*opening == '-' && (++opening, ++openingDenotationType)
|
||||
&& *opening == '-' && (++opening, ++openingDenotationType);
|
||||
*opening == '-' && (++opening, ++openingDenotationType) && *opening == '-' && (++opening, ++openingDenotationType);
|
||||
openingLen = strlen(opening);
|
||||
}
|
||||
|
||||
|
@ -940,7 +951,8 @@ void ArgumentParser::printBashCompletion(int argc, const char *const *argv, unsi
|
|||
for (const char *i = arg->preDefinedCompletionValues(), *end = opening + openingLen; *i;) {
|
||||
if (wordStart) {
|
||||
const char *i1 = i, *i2 = opening;
|
||||
for(; *i1 && i2 != end && *i1 == *i2; ++i1, ++i2);
|
||||
for (; *i1 && i2 != end && *i1 == *i2; ++i1, ++i2)
|
||||
;
|
||||
if ((ok = (i2 == end))) {
|
||||
cout << '\'';
|
||||
}
|
||||
|
@ -966,7 +978,9 @@ void ArgumentParser::printBashCompletion(int argc, const char *const *argv, unsi
|
|||
}
|
||||
++i, ++wordIndex;
|
||||
switch (*i) {
|
||||
case ' ': case '\n': case '\0':
|
||||
case ' ':
|
||||
case '\n':
|
||||
case '\0':
|
||||
if (appendEquationSign && !equationSignAlreadyPresent) {
|
||||
cout << '=';
|
||||
noWhitespace = true;
|
||||
|
@ -995,7 +1009,9 @@ void ArgumentParser::printBashCompletion(int argc, const char *const *argv, unsi
|
|||
case '=':
|
||||
equationSignAlreadyPresent = true;
|
||||
break;
|
||||
case ' ': case '\n': case '\0':
|
||||
case ' ':
|
||||
case '\n':
|
||||
case '\0':
|
||||
if (appendEquationSign && !equationSignAlreadyPresent) {
|
||||
cout << '=';
|
||||
equationSignAlreadyPresent = false;
|
||||
|
@ -1139,10 +1155,12 @@ void ArgumentParser::checkConstraints(const ArgumentVector &args)
|
|||
for (const Argument *arg : args) {
|
||||
const auto occurrences = arg->occurrences();
|
||||
if (arg->isParentPresent() && occurrences > arg->maxOccurrences()) {
|
||||
throw Failure("The argument \""s % arg->name() % "\" mustn't be specified more than "s % arg->maxOccurrences() + (arg->maxOccurrences() == 1 ? " time."s : " times."s));
|
||||
throw Failure(argsToString("The argument \"", arg->name(), "\" mustn't be specified more than ", arg->maxOccurrences(),
|
||||
(arg->maxOccurrences() == 1 ? " time." : " times.")));
|
||||
}
|
||||
if (arg->isParentPresent() && occurrences < arg->minOccurrences()) {
|
||||
throw Failure("The argument \""s % arg->name() % "\" must be specified at least "s % arg->minOccurrences() + (arg->minOccurrences() == 1 ? " time."s : " times."s));
|
||||
throw Failure(argsToString("The argument \"", arg->name(), "\" must be specified at least ", arg->minOccurrences(),
|
||||
(arg->minOccurrences() == 1 ? " time." : " times.")));
|
||||
}
|
||||
Argument *conflictingArgument = nullptr;
|
||||
if (arg->isMainArgument()) {
|
||||
|
@ -1153,7 +1171,7 @@ void ArgumentParser::checkConstraints(const ArgumentVector &args)
|
|||
conflictingArgument = arg->conflictsWithArgument();
|
||||
}
|
||||
if (conflictingArgument) {
|
||||
throw Failure("The argument \""s % conflictingArgument->name() % "\" can not be combined with \""s + arg->name() + "\"."s);
|
||||
throw Failure(argsToString("The argument \"", conflictingArgument->name(), "\" can not be combined with \"", arg->name(), "\"."));
|
||||
}
|
||||
for (size_t i = 0; i != occurrences; ++i) {
|
||||
if (!arg->allRequiredValuesPresent(i)) {
|
||||
|
@ -1211,8 +1229,8 @@ void ArgumentParser::invokeCallbacks(const ArgumentVector &args)
|
|||
/*!
|
||||
* \brief Constructs a new help argument for the specified parser.
|
||||
*/
|
||||
HelpArgument::HelpArgument(ArgumentParser &parser) :
|
||||
Argument("help", 'h', "shows this information")
|
||||
HelpArgument::HelpArgument(ArgumentParser &parser)
|
||||
: Argument("help", 'h', "shows this information")
|
||||
{
|
||||
setCallback([&parser](const ArgumentOccurrence &) {
|
||||
CMD_UTILS_START_CONSOLE;
|
||||
|
@ -1230,5 +1248,4 @@ HelpArgument::HelpArgument(ArgumentParser &parser) :
|
|||
* \brief The ConfigValueArgument class is an Argument where setCombinable() is true by default.
|
||||
* \sa ConfigValueArgument::ConfigValueArgument()
|
||||
*/
|
||||
|
||||
}
|
||||
|
|
|
@ -3,9 +3,9 @@
|
|||
|
||||
#include "../global.h"
|
||||
|
||||
#include <vector>
|
||||
#include <initializer_list>
|
||||
#include <functional>
|
||||
#include <initializer_list>
|
||||
#include <vector>
|
||||
#ifdef DEBUG_BUILD
|
||||
#include <cassert>
|
||||
#endif
|
||||
|
@ -27,11 +27,9 @@ CPP_UTILITIES_EXPORT extern std::initializer_list<const char *> dependencyVersio
|
|||
* \remarks Reads those data from the config header so "config.h" must be included.
|
||||
*/
|
||||
#ifndef APP_STATICALLY_LINKED
|
||||
#define SET_DEPENDENCY_INFO \
|
||||
::ApplicationUtilities::dependencyVersions = DEPENCENCY_VERSIONS
|
||||
#define SET_DEPENDENCY_INFO ::ApplicationUtilities::dependencyVersions = DEPENCENCY_VERSIONS
|
||||
#else
|
||||
#define SET_DEPENDENCY_INFO \
|
||||
::ApplicationUtilities::dependencyVersions = STATIC_DEPENCENCY_VERSIONS
|
||||
#define SET_DEPENDENCY_INFO ::ApplicationUtilities::dependencyVersions = STATIC_DEPENCENCY_VERSIONS
|
||||
#endif
|
||||
|
||||
/*!
|
||||
|
@ -44,7 +42,7 @@ CPP_UTILITIES_EXPORT extern std::initializer_list<const char *> dependencyVersio
|
|||
::ApplicationUtilities::applicationAuthor = APP_AUTHOR; \
|
||||
::ApplicationUtilities::applicationVersion = APP_VERSION; \
|
||||
::ApplicationUtilities::applicationUrl = APP_URL; \
|
||||
SET_DEPENDENCY_INFO \
|
||||
SET_DEPENDENCY_INFO
|
||||
|
||||
CPP_UTILITIES_EXPORT extern void (*exitFunction)(int);
|
||||
|
||||
|
@ -60,8 +58,7 @@ typedef std::function<bool (Argument *)> ArgumentPredicate;
|
|||
* \brief The UnknownArgumentBehavior enum specifies the behavior of the argument parser when an unknown
|
||||
* argument is detected.
|
||||
*/
|
||||
enum class UnknownArgumentBehavior
|
||||
{
|
||||
enum class UnknownArgumentBehavior {
|
||||
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 an ApplicationUtilities::Failure instance with an error message is thrown. */
|
||||
|
@ -70,8 +67,7 @@ enum class UnknownArgumentBehavior
|
|||
/*!
|
||||
* \brief The ValueCompletionBehavior enum specifies the items to be considered when generating completion for an argument value.
|
||||
*/
|
||||
enum class ValueCompletionBehavior : unsigned char
|
||||
{
|
||||
enum class ValueCompletionBehavior : unsigned char {
|
||||
None = 0, /**< no auto-completion */
|
||||
PreDefinedValues = 2, /**< values assigned with Argument::setPreDefinedCompletionValues() */
|
||||
Files = 4, /**< files */
|
||||
|
@ -97,8 +93,7 @@ Argument CPP_UTILITIES_EXPORT *firstPresentUncombinableArg(const ArgumentVector
|
|||
/*!
|
||||
* \brief The ArgumentOccurrence struct holds argument values for an occurrence of an argument.
|
||||
*/
|
||||
struct CPP_UTILITIES_EXPORT ArgumentOccurrence
|
||||
{
|
||||
struct CPP_UTILITIES_EXPORT ArgumentOccurrence {
|
||||
ArgumentOccurrence(std::size_t index);
|
||||
ArgumentOccurrence(std::size_t index, const std::vector<Argument *> parentPath, Argument *parent);
|
||||
|
||||
|
@ -122,9 +117,10 @@ struct CPP_UTILITIES_EXPORT ArgumentOccurrence
|
|||
/*!
|
||||
* \brief Constructs an argument occurrence for the specified \a index.
|
||||
*/
|
||||
inline ArgumentOccurrence::ArgumentOccurrence(std::size_t index) :
|
||||
index(index)
|
||||
{}
|
||||
inline ArgumentOccurrence::ArgumentOccurrence(std::size_t index)
|
||||
: index(index)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs an argument occurrence.
|
||||
|
@ -134,17 +130,16 @@ inline ArgumentOccurrence::ArgumentOccurrence(std::size_t index) :
|
|||
*
|
||||
* The path of the new occurrence is built from the specified \a parentPath and \a parent.
|
||||
*/
|
||||
inline ArgumentOccurrence::ArgumentOccurrence(std::size_t index, const std::vector<Argument *> parentPath, Argument *parent) :
|
||||
index(index),
|
||||
path(parentPath)
|
||||
inline ArgumentOccurrence::ArgumentOccurrence(std::size_t index, const std::vector<Argument *> parentPath, Argument *parent)
|
||||
: index(index)
|
||||
, path(parentPath)
|
||||
{
|
||||
if (parent) {
|
||||
path.push_back(parent);
|
||||
}
|
||||
}
|
||||
|
||||
class CPP_UTILITIES_EXPORT Argument
|
||||
{
|
||||
class CPP_UTILITIES_EXPORT Argument {
|
||||
friend ArgumentParser;
|
||||
friend ArgumentReader;
|
||||
|
||||
|
@ -227,8 +222,7 @@ private:
|
|||
const char *m_preDefinedCompletionValues;
|
||||
};
|
||||
|
||||
class CPP_UTILITIES_EXPORT ArgumentParser
|
||||
{
|
||||
class CPP_UTILITIES_EXPORT ArgumentParser {
|
||||
friend ArgumentParserTests;
|
||||
friend ArgumentReader;
|
||||
|
||||
|
@ -314,8 +308,8 @@ inline char Argument::abbreviation() const
|
|||
*/
|
||||
inline void Argument::setAbbreviation(char abbreviation)
|
||||
{
|
||||
IF_DEBUG_BUILD(assert(abbreviation != ' ' && abbreviation != '=' && abbreviation != '-'
|
||||
&& abbreviation != '\'' && abbreviation != '"' && abbreviation != '\n' && abbreviation != '\r'));
|
||||
IF_DEBUG_BUILD(assert(abbreviation != ' ' && abbreviation != '=' && abbreviation != '-' && abbreviation != '\'' && abbreviation != '"'
|
||||
&& abbreviation != '\n' && abbreviation != '\r'));
|
||||
m_abbreviation = abbreviation;
|
||||
}
|
||||
|
||||
|
@ -816,41 +810,39 @@ inline void ArgumentParser::invokeCallbacks()
|
|||
invokeCallbacks(m_mainArgs);
|
||||
}
|
||||
|
||||
class CPP_UTILITIES_EXPORT HelpArgument : public Argument
|
||||
{
|
||||
class CPP_UTILITIES_EXPORT HelpArgument : public Argument {
|
||||
public:
|
||||
HelpArgument(ArgumentParser &parser);
|
||||
};
|
||||
|
||||
class CPP_UTILITIES_EXPORT OperationArgument : public Argument
|
||||
{
|
||||
class CPP_UTILITIES_EXPORT OperationArgument : public Argument {
|
||||
public:
|
||||
OperationArgument(const char *name, char abbreviation = '\0', const char *description = nullptr, const char *example = nullptr);
|
||||
};
|
||||
|
||||
inline OperationArgument::OperationArgument(const char *name, char abbreviation, const char *description, const char *example) :
|
||||
Argument(name, abbreviation, description, example)
|
||||
inline OperationArgument::OperationArgument(const char *name, char abbreviation, const char *description, const char *example)
|
||||
: Argument(name, abbreviation, description, example)
|
||||
{
|
||||
setDenotesOperation(true);
|
||||
}
|
||||
|
||||
class CPP_UTILITIES_EXPORT ConfigValueArgument : public Argument
|
||||
{
|
||||
class CPP_UTILITIES_EXPORT ConfigValueArgument : public Argument {
|
||||
public:
|
||||
ConfigValueArgument(const char *name, char abbreviation = '\0', const char *description = nullptr, std::initializer_list<const char *> valueNames = std::initializer_list<const char *>());
|
||||
ConfigValueArgument(const char *name, char abbreviation = '\0', const char *description = nullptr,
|
||||
std::initializer_list<const char *> valueNames = std::initializer_list<const char *>());
|
||||
};
|
||||
|
||||
/*!
|
||||
* \brief Constructs a new ConfigValueArgument with the specified parameter. The initial value of requiredValueCount() is set to size of specified \a valueNames.
|
||||
*/
|
||||
inline ConfigValueArgument::ConfigValueArgument(const char *name, char abbreviation, const char *description, std::initializer_list<const char *> valueNames) :
|
||||
Argument(name, abbreviation, description)
|
||||
inline ConfigValueArgument::ConfigValueArgument(
|
||||
const char *name, char abbreviation, const char *description, std::initializer_list<const char *> valueNames)
|
||||
: Argument(name, abbreviation, description)
|
||||
{
|
||||
setCombinable(true);
|
||||
setRequiredValueCount(valueNames.size());
|
||||
setValueNames(valueNames);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // APPLICATION_UTILITIES_ARGUMENTPARSER_H
|
||||
|
|
|
@ -3,8 +3,7 @@
|
|||
|
||||
namespace ApplicationUtilities {
|
||||
|
||||
struct CPP_UTILITIES_EXPORT ArgumentReader
|
||||
{
|
||||
struct CPP_UTILITIES_EXPORT ArgumentReader {
|
||||
ArgumentReader(ArgumentParser &parser, const char *const *argv, const char *const *end, bool completionMode = false);
|
||||
ApplicationUtilities::ArgumentReader &reset(const char *const *argv, const char *const *end);
|
||||
void read();
|
||||
|
@ -31,7 +30,6 @@ struct CPP_UTILITIES_EXPORT ArgumentReader
|
|||
/// \brief Whether completion mode is enabled. In this case reading args will be continued even if an denotation is unknown (regardless of unknownArgumentBehavior()).
|
||||
bool completionMode;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // APPLICATION_UTILITIES_ARGUMENTPARSER_PRIVATE_H
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
#include "./commandlineutils.h"
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#ifdef PLATFORM_WINDOWS
|
||||
# include <windows.h>
|
||||
#include <fcntl.h>
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
|
|
|
@ -15,20 +15,14 @@ namespace ApplicationUtilities {
|
|||
/*!
|
||||
* \brief The Response enum is used to specify the default response for the confirmPrompt() method.
|
||||
*/
|
||||
enum class Response
|
||||
{
|
||||
None,
|
||||
Yes,
|
||||
No
|
||||
};
|
||||
enum class Response { None, Yes, No };
|
||||
|
||||
bool CPP_UTILITIES_EXPORT confirmPrompt(const char *message, Response defaultResponse = Response::None);
|
||||
|
||||
#ifdef PLATFORM_WINDOWS
|
||||
void CPP_UTILITIES_EXPORT startConsole();
|
||||
std::pair<std::vector<std::unique_ptr<char[]> >, std::vector<char *> > CPP_UTILITIES_EXPORT convertArgsToUtf8();
|
||||
# define CMD_UTILS_START_CONSOLE \
|
||||
::ApplicationUtilities::startConsole();
|
||||
#define CMD_UTILS_START_CONSOLE ::ApplicationUtilities::startConsole();
|
||||
#define CMD_UTILS_CONVERT_ARGS_TO_UTF8 \
|
||||
auto utf8Args = ::ApplicationUtilities::convertArgsToUtf8(); \
|
||||
argv = utf8Args.second.data(); \
|
||||
|
@ -41,13 +35,13 @@ std::pair<std::vector<std::unique_ptr<char[]> >, std::vector<char *> > CPP_UTILI
|
|||
/*!
|
||||
* \brief The Indentation class allows printing indentation conveniently, eg. cout << Indentation(4) << ...
|
||||
*/
|
||||
class CPP_UTILITIES_EXPORT Indentation
|
||||
{
|
||||
class CPP_UTILITIES_EXPORT Indentation {
|
||||
public:
|
||||
Indentation(unsigned char level = 4, char character = ' ') :
|
||||
level(level),
|
||||
character(character)
|
||||
{}
|
||||
Indentation(unsigned char level = 4, char character = ' ')
|
||||
: level(level)
|
||||
, character(character)
|
||||
{
|
||||
}
|
||||
|
||||
Indentation operator+(unsigned char level)
|
||||
{
|
||||
|
|
|
@ -12,23 +12,26 @@ namespace ApplicationUtilities {
|
|||
/*!
|
||||
* Constructs a new Failure.
|
||||
*/
|
||||
Failure::Failure() :
|
||||
m_what("unspecified parsing exception")
|
||||
{}
|
||||
Failure::Failure()
|
||||
: m_what("unspecified parsing exception")
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* Constructs a new Failure. \a what is a std::string
|
||||
* describing the cause of the Failure.
|
||||
*/
|
||||
Failure::Failure(const std::string &what) :
|
||||
m_what(what)
|
||||
{}
|
||||
Failure::Failure(const std::string &what)
|
||||
: m_what(what)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* Destroys the Failure.
|
||||
*/
|
||||
Failure::~Failure() USE_NOTHROW
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* Returns a C-style character string describing the cause
|
||||
|
@ -38,7 +41,4 @@ const char *Failure::what() const USE_NOTHROW
|
|||
{
|
||||
return m_what.c_str();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -8,8 +8,7 @@
|
|||
|
||||
namespace ApplicationUtilities {
|
||||
|
||||
class CPP_UTILITIES_EXPORT Failure : public std::exception
|
||||
{
|
||||
class CPP_UTILITIES_EXPORT Failure : public std::exception {
|
||||
public:
|
||||
Failure();
|
||||
Failure(const std::string &what);
|
||||
|
@ -20,7 +19,6 @@ public:
|
|||
private:
|
||||
std::string m_what;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // APPLICATION_UTILITIES_FAILURE_H
|
||||
|
|
|
@ -11,10 +11,12 @@ namespace ApplicationUtilities {
|
|||
/*!
|
||||
* \brief Constructs new fake Qt-config arguments.
|
||||
*/
|
||||
FakeQtConfigArguments::FakeQtConfigArguments() :
|
||||
m_qtWidgetsGuiArg("qt-widgets-gui", 'g', "shows a Qt widgets based graphical user interface (the application has not been built with Qt widgets support)"),
|
||||
m_qtQuickGuiArg("qt-quick-gui", 'q', "shows a Qt quick based graphical user interface (the application has not been built with Qt quick support)")
|
||||
{}
|
||||
FakeQtConfigArguments::FakeQtConfigArguments()
|
||||
: m_qtWidgetsGuiArg(
|
||||
"qt-widgets-gui", 'g', "shows a Qt widgets based graphical user interface (the application has not been built with Qt widgets support)")
|
||||
, m_qtQuickGuiArg(
|
||||
"qt-quick-gui", 'q', "shows a Qt quick based graphical user interface (the application has not been built with Qt quick support)")
|
||||
{
|
||||
}
|
||||
|
||||
} // namespace ApplicationUtilities
|
||||
|
||||
|
|
|
@ -5,8 +5,7 @@
|
|||
|
||||
namespace ApplicationUtilities {
|
||||
|
||||
class CPP_UTILITIES_EXPORT FakeQtConfigArguments
|
||||
{
|
||||
class CPP_UTILITIES_EXPORT FakeQtConfigArguments {
|
||||
public:
|
||||
FakeQtConfigArguments();
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
#include "./datetime.h"
|
||||
|
||||
#include "../conversion/stringconversion.h"
|
||||
#include "../conversion/stringbuilder.h"
|
||||
#include "../conversion/stringconversion.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
|
||||
#if defined(PLATFORM_UNIX)
|
||||
|
@ -27,14 +27,12 @@ const int DateTime::m_daysToMonth366[13] = {0, 31, 60, 91, 121, 152, 182, 213, 2
|
|||
const int DateTime::m_daysInMonth365[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
|
||||
const int DateTime::m_daysInMonth366[12] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
|
||||
|
||||
template<typename num1, typename num2, typename num3>
|
||||
inline bool inRangeInclMax(num1 val, num2 min, num3 max)
|
||||
template <typename num1, typename num2, typename num3> inline bool inRangeInclMax(num1 val, num2 min, num3 max)
|
||||
{
|
||||
return (val) >= (min) && (val) <= (max);
|
||||
}
|
||||
|
||||
template<typename num1, typename num2, typename num3>
|
||||
inline bool inRangeExclMax(num1 val, num2 min, num3 max)
|
||||
template <typename num1, typename num2, typename num3> inline bool inRangeExclMax(num1 val, num2 min, num3 max)
|
||||
{
|
||||
return (val) >= (min) && (val) < (max);
|
||||
}
|
||||
|
@ -59,8 +57,8 @@ DateTime DateTime::fromTimeStamp(time_t timeStamp)
|
|||
{
|
||||
if (timeStamp) {
|
||||
struct tm *timeinfo = localtime(&timeStamp);
|
||||
return DateTime::fromDateAndTime(timeinfo->tm_year + 1900, timeinfo->tm_mon + 1, timeinfo->tm_mday,
|
||||
timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec < 60 ? timeinfo->tm_sec : 59, 0);
|
||||
return DateTime::fromDateAndTime(timeinfo->tm_year + 1900, timeinfo->tm_mon + 1, timeinfo->tm_mday, timeinfo->tm_hour, timeinfo->tm_min,
|
||||
timeinfo->tm_sec < 60 ? timeinfo->tm_sec : 59, 0);
|
||||
} else {
|
||||
return DateTime();
|
||||
}
|
||||
|
@ -102,7 +100,7 @@ DateTime DateTime::fromString(const char *str)
|
|||
} else if (c == '\0') {
|
||||
break;
|
||||
} else {
|
||||
throw ConversionException("unexpected "s + c);
|
||||
throw ConversionException(argsToString("unexpected ", c));
|
||||
}
|
||||
}
|
||||
return DateTime::fromDateAndTime(values[0], values[1], *dayIndex, values[3], values[4], *secondsIndex, miliSeconds);
|
||||
|
@ -167,11 +165,12 @@ std::pair<DateTime, TimeSpan> DateTime::fromIsoString(const char *str)
|
|||
} else if (c == '\0') {
|
||||
break;
|
||||
} else {
|
||||
throw ConversionException("unexpected \""s % c + '\"');
|
||||
throw ConversionException(argsToString("unexpected \"", c, '\"'));
|
||||
}
|
||||
}
|
||||
deltaNegative && (*deltaHourIndex = -*deltaHourIndex);
|
||||
return make_pair(DateTime::fromDateAndTime(values[0], values[1], *dayIndex, *hourIndex, values[4], *secondsIndex, miliSeconds), TimeSpan::fromMinutes(*deltaHourIndex * 60 + values[8]));
|
||||
return make_pair(DateTime::fromDateAndTime(values[0], values[1], *dayIndex, *hourIndex, values[4], *secondsIndex, miliSeconds),
|
||||
TimeSpan::fromMinutes(*deltaHourIndex * 60 + values[8]));
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -195,21 +194,15 @@ void DateTime::toString(string &result, DateTimeOutputFormat format, bool noMill
|
|||
{
|
||||
stringstream s(stringstream::in | stringstream::out);
|
||||
s << setfill('0');
|
||||
if(format == DateTimeOutputFormat::DateTimeAndWeekday
|
||||
|| format == DateTimeOutputFormat::DateTimeAndShortWeekday)
|
||||
if (format == DateTimeOutputFormat::DateTimeAndWeekday || format == DateTimeOutputFormat::DateTimeAndShortWeekday)
|
||||
s << printDayOfWeek(dayOfWeek(), format == DateTimeOutputFormat::DateTimeAndShortWeekday) << ' ';
|
||||
if(format == DateTimeOutputFormat::DateOnly
|
||||
|| format == DateTimeOutputFormat::DateAndTime
|
||||
|| format == DateTimeOutputFormat::DateTimeAndWeekday
|
||||
if (format == DateTimeOutputFormat::DateOnly || format == DateTimeOutputFormat::DateAndTime || format == DateTimeOutputFormat::DateTimeAndWeekday
|
||||
|| format == DateTimeOutputFormat::DateTimeAndShortWeekday)
|
||||
s << setw(4) << year() << '-' << setw(2) << month() << '-' << setw(2) << day();
|
||||
if(format == DateTimeOutputFormat::DateAndTime
|
||||
|| format == DateTimeOutputFormat::DateTimeAndWeekday
|
||||
if (format == DateTimeOutputFormat::DateAndTime || format == DateTimeOutputFormat::DateTimeAndWeekday
|
||||
|| format == DateTimeOutputFormat::DateTimeAndShortWeekday)
|
||||
s << " ";
|
||||
if(format == DateTimeOutputFormat::TimeOnly
|
||||
|| format == DateTimeOutputFormat::DateAndTime
|
||||
|| format == DateTimeOutputFormat::DateTimeAndWeekday
|
||||
if (format == DateTimeOutputFormat::TimeOnly || format == DateTimeOutputFormat::DateAndTime || format == DateTimeOutputFormat::DateTimeAndWeekday
|
||||
|| format == DateTimeOutputFormat::DateTimeAndShortWeekday) {
|
||||
s << setw(2) << hour() << ':' << setw(2) << minute() << ':' << setw(2) << second();
|
||||
int ms = millisecond();
|
||||
|
@ -228,8 +221,8 @@ string DateTime::toIsoString(TimeSpan timeZoneDelta) const
|
|||
{
|
||||
stringstream s(stringstream::in | stringstream::out);
|
||||
s << setfill('0');
|
||||
s << setw(4) << year() << '-' << setw(2) << month() << '-' << setw(2) << day()
|
||||
<< 'T' << setw(2) << hour() << ':' << setw(2) << minute() << ':' << setw(2) << second() << '.' << setw(3) << millisecond();
|
||||
s << setw(4) << year() << '-' << setw(2) << month() << '-' << setw(2) << day() << 'T' << setw(2) << hour() << ':' << setw(2) << minute() << ':'
|
||||
<< setw(2) << second() << '.' << setw(3) << millisecond();
|
||||
if (!timeZoneDelta.isNull()) {
|
||||
s << (timeZoneDelta.isNegative() ? '-' : '+');
|
||||
s << setw(2) << timeZoneDelta.hours() << ':' << setw(2) << timeZoneDelta.minutes();
|
||||
|
@ -293,7 +286,8 @@ DateTime DateTime::exactGmtNow()
|
|||
{
|
||||
struct timespec t;
|
||||
clock_gettime(CLOCK_REALTIME, &t);
|
||||
return DateTime(DateTime::unixEpochStart().totalTicks() + static_cast<uint64>(t.tv_sec) * TimeSpan::ticksPerSecond + static_cast<uint64>(t.tv_nsec) / 100);
|
||||
return DateTime(
|
||||
DateTime::unixEpochStart().totalTicks() + static_cast<uint64>(t.tv_sec) * TimeSpan::ticksPerSecond + static_cast<uint64>(t.tv_nsec) / 100);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -309,7 +303,8 @@ uint64 DateTime::dateToTicks(int year, int month, int day)
|
|||
if (inRangeInclMax(day, 1, daysToMonth[month] - daysToMonth[passedMonth])) {
|
||||
int passedYears = year - 1;
|
||||
int passedDays = day - 1;
|
||||
return (passedYears * m_daysPerYear + passedYears / 4 - passedYears / 100 + passedYears / 400 + daysToMonth[passedMonth] + passedDays) * TimeSpan::ticksPerDay;
|
||||
return (passedYears * m_daysPerYear + passedYears / 4 - passedYears / 100 + passedYears / 400 + daysToMonth[passedMonth] + passedDays)
|
||||
* TimeSpan::ticksPerDay;
|
||||
} else {
|
||||
throw ConversionException("day is out of range");
|
||||
}
|
||||
|
@ -339,7 +334,8 @@ uint64 DateTime::timeToTicks(int hour, int minute, int second, double millisecon
|
|||
if (!inRangeExclMax(millisecond, 0.0, 1000.0)) {
|
||||
throw ConversionException("millisecond is out of range");
|
||||
}
|
||||
return (hour * TimeSpan::ticksPerHour) + (minute * TimeSpan::ticksPerMinute) + (second * TimeSpan::ticksPerSecond) + (uint64)(millisecond * (double)TimeSpan::ticksPerMillisecond);
|
||||
return (hour * TimeSpan::ticksPerHour) + (minute * TimeSpan::ticksPerMinute) + (second * TimeSpan::ticksPerSecond)
|
||||
+ (uint64)(millisecond * (double)TimeSpan::ticksPerMillisecond);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
|
@ -5,19 +5,17 @@
|
|||
|
||||
#include "../conversion/types.h"
|
||||
|
||||
#include <string>
|
||||
#include <limits>
|
||||
#include <ctime>
|
||||
#include <limits>
|
||||
#include <string>
|
||||
|
||||
namespace ChronoUtilities
|
||||
{
|
||||
namespace ChronoUtilities {
|
||||
|
||||
/*!
|
||||
* \brief Specifies the output format.
|
||||
* \sa DateTime::toString()
|
||||
*/
|
||||
enum class DateTimeOutputFormat
|
||||
{
|
||||
enum class DateTimeOutputFormat {
|
||||
DateAndTime, /**< date and time */
|
||||
DateOnly, /**< date only */
|
||||
TimeOnly, /**< time only */
|
||||
|
@ -29,8 +27,7 @@ enum class DateTimeOutputFormat
|
|||
* \brief Specifies the day of the week.
|
||||
* \sa DateTime::dayOfWeek()
|
||||
*/
|
||||
enum class DayOfWeek
|
||||
{
|
||||
enum class DayOfWeek {
|
||||
Monday, /**< Monday */
|
||||
Tuesday, /**< Tuesday */
|
||||
Wednesday, /**< Wednesday */
|
||||
|
@ -44,16 +41,14 @@ enum class DayOfWeek
|
|||
* \brief Specifies the date part.
|
||||
* \sa DateTime::getDatePart()
|
||||
*/
|
||||
enum class DatePart
|
||||
{
|
||||
enum class DatePart {
|
||||
Year, /**< year */
|
||||
Month, /**< month */
|
||||
DayOfYear, /**< day of year */
|
||||
Day /**< day */
|
||||
};
|
||||
|
||||
class CPP_UTILITIES_EXPORT DateTime
|
||||
{
|
||||
class CPP_UTILITIES_EXPORT DateTime {
|
||||
public:
|
||||
explicit constexpr DateTime();
|
||||
explicit constexpr DateTime(uint64 ticks);
|
||||
|
@ -130,21 +125,21 @@ private:
|
|||
static const int m_daysInMonth366[12];
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
* \brief Constructs a DateTime.
|
||||
*/
|
||||
constexpr inline DateTime::DateTime() :
|
||||
m_ticks(0)
|
||||
{}
|
||||
constexpr inline DateTime::DateTime()
|
||||
: m_ticks(0)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a DateTime with the specified number of \a ticks.
|
||||
*/
|
||||
constexpr inline DateTime::DateTime(uint64 ticks) :
|
||||
m_ticks(ticks)
|
||||
{}
|
||||
constexpr inline DateTime::DateTime(uint64 ticks)
|
||||
: m_ticks(ticks)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a DateTime to the specified \a year, \a month, and \a day.
|
||||
|
@ -321,11 +316,7 @@ constexpr inline bool DateTime::isEternity() const
|
|||
*/
|
||||
constexpr inline bool DateTime::isLeapYear(int year)
|
||||
{
|
||||
return (year % 4 != 0)
|
||||
? false
|
||||
: ((year % 100 == 0)
|
||||
? (year % 400 == 0)
|
||||
: true);
|
||||
return (year % 4 != 0) ? false : ((year % 100 == 0) ? (year % 400 == 0) : true);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -333,11 +324,7 @@ constexpr inline bool DateTime::isLeapYear(int year)
|
|||
*/
|
||||
inline int DateTime::daysInMonth(int year, int month)
|
||||
{
|
||||
return (month >= 1 && month <= 12)
|
||||
? (isLeapYear(year)
|
||||
? m_daysInMonth366[month - 1]
|
||||
: m_daysInMonth365[month - 1])
|
||||
: (0);
|
||||
return (month >= 1 && month <= 12) ? (isLeapYear(year) ? m_daysInMonth366[month - 1] : m_daysInMonth365[month - 1]) : (0);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -483,12 +470,10 @@ inline DateTime &DateTime::operator -=(const TimeSpan &timeSpan)
|
|||
m_ticks -= timeSpan.m_ticks;
|
||||
return *this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace std {
|
||||
template<> struct hash<ChronoUtilities::DateTime>
|
||||
{
|
||||
template <> struct hash<ChronoUtilities::DateTime> {
|
||||
inline size_t operator()(const ChronoUtilities::DateTime &dateTime) const
|
||||
{
|
||||
return hash<decltype(dateTime.totalTicks())>()(dateTime.totalTicks());
|
||||
|
|
|
@ -27,7 +27,4 @@ Period::Period(const DateTime &beg, const DateTime &end)
|
|||
--m_years;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -5,13 +5,13 @@
|
|||
|
||||
namespace ChronoUtilities {
|
||||
|
||||
class CPP_UTILITIES_EXPORT Period
|
||||
{
|
||||
class CPP_UTILITIES_EXPORT Period {
|
||||
public:
|
||||
Period(const DateTime &beg, const DateTime &end);
|
||||
int years() const;
|
||||
int months() const;
|
||||
int days() const;
|
||||
|
||||
private:
|
||||
int m_years;
|
||||
int m_months;
|
||||
|
@ -41,7 +41,6 @@ inline int Period::days() const
|
|||
{
|
||||
return m_days;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // CHRONO_UTILITIES_PERIOD_H
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
|
||||
#include "../conversion/stringconversion.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <cmath>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
@ -111,5 +111,3 @@ void TimeSpan::toString(string &result, TimeSpanOutputFormat format, bool noMill
|
|||
}
|
||||
result = s.str().substr(0, static_cast<string::size_type>(s.tellp()) - 1);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,17 +1,16 @@
|
|||
#ifndef CHRONO_UTILITIES_TIMESPAN_H
|
||||
#define CHRONO_UTILITIES_TIMESPAN_H
|
||||
|
||||
#include "../global.h"
|
||||
#include "../conversion/types.h"
|
||||
#include "../global.h"
|
||||
|
||||
#include <string>
|
||||
#include <limits>
|
||||
#include <string>
|
||||
|
||||
/*!
|
||||
* \brief Contains classes providing a means for handling date and time information.
|
||||
*/
|
||||
namespace ChronoUtilities
|
||||
{
|
||||
namespace ChronoUtilities {
|
||||
|
||||
class DateTime;
|
||||
|
||||
|
@ -19,15 +18,14 @@ class DateTime;
|
|||
* \brief Specifies the output format.
|
||||
* \sa TimeSpan::toString()
|
||||
*/
|
||||
enum class TimeSpanOutputFormat
|
||||
{
|
||||
enum class TimeSpanOutputFormat {
|
||||
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 */
|
||||
};
|
||||
|
||||
class CPP_UTILITIES_EXPORT TimeSpan
|
||||
{
|
||||
class CPP_UTILITIES_EXPORT TimeSpan {
|
||||
friend class DateTime;
|
||||
|
||||
public:
|
||||
explicit constexpr TimeSpan();
|
||||
explicit constexpr TimeSpan(int64 ticks);
|
||||
|
@ -86,14 +84,18 @@ private:
|
|||
/*!
|
||||
* \brief Constructs a new instance of the TimeSpan class with zero ticks.
|
||||
*/
|
||||
constexpr inline TimeSpan::TimeSpan() : m_ticks(0)
|
||||
{}
|
||||
constexpr inline TimeSpan::TimeSpan()
|
||||
: m_ticks(0)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a new instance of the TimeSpan class with the specified number of ticks.
|
||||
*/
|
||||
constexpr inline TimeSpan::TimeSpan(int64 ticks) : m_ticks(ticks)
|
||||
{}
|
||||
constexpr inline TimeSpan::TimeSpan(int64 ticks)
|
||||
: m_ticks(ticks)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a new instance of the TimeSpan class with the specified number of miliseconds.
|
||||
|
@ -360,12 +362,10 @@ constexpr inline bool TimeSpan::isInfinity() const
|
|||
{
|
||||
return m_ticks == std::numeric_limits<decltype(m_ticks)>::max();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace std {
|
||||
template<> struct hash<ChronoUtilities::TimeSpan>
|
||||
{
|
||||
template <> struct hash<ChronoUtilities::TimeSpan> {
|
||||
inline size_t operator()(const ChronoUtilities::TimeSpan &timeSpan) const
|
||||
{
|
||||
return hash<decltype(timeSpan.totalTicks())>()(timeSpan.totalTicks());
|
||||
|
|
|
@ -31,7 +31,8 @@
|
|||
#endif
|
||||
#if defined(__BYTE_ORDER__) && defined(__FLOAT_WORD_ORDER__)
|
||||
#else
|
||||
# if defined(__i386) || defined(__i386__) || defined(_M_IX86) || defined(__x86_64) || defined(__x86_64__) || defined(__amd64) || defined(_M_X64) || defined(__LITTLE_ENDIAN__) || defined(_little_endian__) || defined(_LITTLE_ENDIAN) || defined(_WIN32_WCE) || defined(WINAPI_FAMILY)
|
||||
#if defined(__i386) || defined(__i386__) || defined(_M_IX86) || defined(__x86_64) || defined(__x86_64__) || defined(__amd64) || defined(_M_X64) \
|
||||
|| defined(__LITTLE_ENDIAN__) || defined(_little_endian__) || defined(_LITTLE_ENDIAN) || defined(_WIN32_WCE) || defined(WINAPI_FAMILY)
|
||||
#ifndef __BYTE_ORDER__
|
||||
#define CONVERSION_UTILITIES_IS_BYTE_ORDER_LITTLE_ENDIAN true
|
||||
#define CONVERSION_UTILITIES_IS_BYTE_ORDER_BIG_ENDIAN false
|
||||
|
@ -61,8 +62,7 @@
|
|||
#error "Middle endian byte order is not supported!"
|
||||
#endif
|
||||
|
||||
namespace ConversionUtilities
|
||||
{
|
||||
namespace ConversionUtilities {
|
||||
|
||||
/*!
|
||||
* \brief Encapsulates binary conversion functions using the big endian byte order.
|
||||
|
@ -77,7 +77,6 @@ namespace BE {
|
|||
#endif
|
||||
#include "./binaryconversionprivate.h"
|
||||
#undef CONVERSION_UTILITIES_BINARY_CONVERSION_INTERNAL
|
||||
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -93,7 +92,6 @@ namespace LE {
|
|||
#endif
|
||||
#include "./binaryconversionprivate.h"
|
||||
#undef CONVERSION_UTILITIES_BINARY_CONVERSION_INTERNAL
|
||||
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -135,10 +133,7 @@ CPP_UTILITIES_EXPORT constexpr float32 toFloat32(uint32 fixed16value)
|
|||
*/
|
||||
CPP_UTILITIES_EXPORT constexpr uint32 toSynchsafeInt(uint32 normalInt)
|
||||
{
|
||||
return ((normalInt & 0x0000007fu) )
|
||||
| ((normalInt & 0x00003f80u) << 1)
|
||||
| ((normalInt & 0x001fc000u) << 2)
|
||||
| ((normalInt & 0x0fe00000u) << 3);
|
||||
return ((normalInt & 0x0000007fu)) | ((normalInt & 0x00003f80u) << 1) | ((normalInt & 0x001fc000u) << 2) | ((normalInt & 0x0fe00000u) << 3);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -148,9 +143,7 @@ CPP_UTILITIES_EXPORT constexpr uint32 toSynchsafeInt(uint32 normalInt)
|
|||
*/
|
||||
CPP_UTILITIES_EXPORT constexpr uint32 toNormalInt(uint32 synchsafeInt)
|
||||
{
|
||||
return ((synchsafeInt & 0x0000007fu) )
|
||||
| ((synchsafeInt & 0x00007f00u) >> 1)
|
||||
| ((synchsafeInt & 0x007f0000u) >> 2)
|
||||
return ((synchsafeInt & 0x0000007fu)) | ((synchsafeInt & 0x00007f00u) >> 1) | ((synchsafeInt & 0x007f0000u) >> 2)
|
||||
| ((synchsafeInt & 0x7f000000u) >> 3);
|
||||
}
|
||||
|
||||
|
@ -167,10 +160,7 @@ CPP_UTILITIES_EXPORT constexpr uint16 swapOrder(uint16 value)
|
|||
*/
|
||||
CPP_UTILITIES_EXPORT constexpr uint32 swapOrder(uint32 value)
|
||||
{
|
||||
return (value >> 24)
|
||||
| ((value & 0x00FF0000) >> 8)
|
||||
| ((value & 0x0000FF00) << 8)
|
||||
| (value << 24);
|
||||
return (value >> 24) | ((value & 0x00FF0000) >> 8) | ((value & 0x0000FF00) << 8) | (value << 24);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -178,16 +168,10 @@ CPP_UTILITIES_EXPORT constexpr uint32 swapOrder(uint32 value)
|
|||
*/
|
||||
CPP_UTILITIES_EXPORT constexpr uint64 swapOrder(uint64 value)
|
||||
{
|
||||
return(value >> (7 * 8))
|
||||
| ((value & 0x00FF000000000000) >> (5 * 8))
|
||||
| ((value & 0x0000FF0000000000) >> (3 * 8))
|
||||
| ((value & 0x000000FF00000000) >> (1 * 8))
|
||||
| ((value & 0x00000000FF000000) << (1 * 8))
|
||||
| ((value & 0x0000000000FF0000) << (3 * 8))
|
||||
| ((value & 0x000000000000FF00) << (5 * 8))
|
||||
| ((value) << (7 * 8));
|
||||
return (value >> (7 * 8)) | ((value & 0x00FF000000000000) >> (5 * 8)) | ((value & 0x0000FF0000000000) >> (3 * 8))
|
||||
| ((value & 0x000000FF00000000) >> (1 * 8)) | ((value & 0x00000000FF000000) << (1 * 8)) | ((value & 0x0000000000FF0000) << (3 * 8))
|
||||
| ((value & 0x000000000000FF00) << (5 * 8)) | ((value) << (7 * 8));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // CONVERSION_UTILITIES_BINARY_CONVERSION_H
|
||||
|
|
|
@ -12,11 +12,9 @@
|
|||
CPP_UTILITIES_EXPORT inline int16 toInt16(const char *value)
|
||||
{
|
||||
#if CONVERSION_UTILITIES_BINARY_CONVERSION_INTERNAL == 0
|
||||
return (static_cast<int16>(value[0]) << 8 & 0xFF00)
|
||||
| (static_cast<int16>(value[1]) & 0x00FF);
|
||||
return (static_cast<int16>(value[0]) << 8 & 0xFF00) | (static_cast<int16>(value[1]) & 0x00FF);
|
||||
#else
|
||||
return (static_cast<int16>(value[1]) << 8 & 0xFF00)
|
||||
| (static_cast<int16>(value[0]) & 0x00FF);
|
||||
return (static_cast<int16>(value[1]) << 8 & 0xFF00) | (static_cast<int16>(value[0]) & 0x00FF);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -26,11 +24,9 @@ CPP_UTILITIES_EXPORT inline int16 toInt16(const char *value)
|
|||
CPP_UTILITIES_EXPORT inline uint16 toUInt16(const char *value)
|
||||
{
|
||||
#if CONVERSION_UTILITIES_BINARY_CONVERSION_INTERNAL == 0
|
||||
return (static_cast<uint16>(value[0]) << 8 & 0xFF00)
|
||||
| (static_cast<uint16>(value[1]) & 0x00FF);
|
||||
return (static_cast<uint16>(value[0]) << 8 & 0xFF00) | (static_cast<uint16>(value[1]) & 0x00FF);
|
||||
#else
|
||||
return (static_cast<uint16>(value[1]) << 8 & 0xFF00)
|
||||
| (static_cast<uint16>(value[0]) & 0x00FF);
|
||||
return (static_cast<uint16>(value[1]) << 8 & 0xFF00) | (static_cast<uint16>(value[0]) & 0x00FF);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -40,15 +36,11 @@ CPP_UTILITIES_EXPORT inline uint16 toUInt16(const char *value)
|
|||
CPP_UTILITIES_EXPORT inline int32 toInt32(const char *value)
|
||||
{
|
||||
#if CONVERSION_UTILITIES_BINARY_CONVERSION_INTERNAL == 0
|
||||
return (static_cast<int32>(value[0]) << 24 & 0xFF000000)
|
||||
| (static_cast<int32>(value[1]) << 16 & 0x00FF0000)
|
||||
| (static_cast<int32>(value[2]) << 8 & 0x0000FF00)
|
||||
| (static_cast<int32>(value[3]) & 0x000000FF);
|
||||
return (static_cast<int32>(value[0]) << 24 & 0xFF000000) | (static_cast<int32>(value[1]) << 16 & 0x00FF0000)
|
||||
| (static_cast<int32>(value[2]) << 8 & 0x0000FF00) | (static_cast<int32>(value[3]) & 0x000000FF);
|
||||
#else
|
||||
return (static_cast<int32>(value[3]) << 24 & 0xFF000000)
|
||||
| (static_cast<int32>(value[2]) << 16 & 0x00FF0000)
|
||||
| (static_cast<int32>(value[1]) << 8 & 0x0000FF00)
|
||||
| (static_cast<int32>(value[0]) & 0x000000FF);
|
||||
return (static_cast<int32>(value[3]) << 24 & 0xFF000000) | (static_cast<int32>(value[2]) << 16 & 0x00FF0000)
|
||||
| (static_cast<int32>(value[1]) << 8 & 0x0000FF00) | (static_cast<int32>(value[0]) & 0x000000FF);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -58,12 +50,10 @@ CPP_UTILITIES_EXPORT inline int32 toInt32(const char *value)
|
|||
CPP_UTILITIES_EXPORT inline uint32 toUInt24(const char *value)
|
||||
{
|
||||
#if CONVERSION_UTILITIES_BINARY_CONVERSION_INTERNAL == 0
|
||||
return (static_cast<uint32>(value[0]) << 16 & 0x00FF0000)
|
||||
| (static_cast<uint32>(value[1]) << 8 & 0x0000FF00)
|
||||
return (static_cast<uint32>(value[0]) << 16 & 0x00FF0000) | (static_cast<uint32>(value[1]) << 8 & 0x0000FF00)
|
||||
| (static_cast<uint32>(value[2]) & 0x000000FF);
|
||||
#else
|
||||
return (static_cast<uint32>(value[2]) << 16 & 0x00FF0000)
|
||||
| (static_cast<uint32>(value[1]) << 8 & 0x0000FF00)
|
||||
return (static_cast<uint32>(value[2]) << 16 & 0x00FF0000) | (static_cast<uint32>(value[1]) << 8 & 0x0000FF00)
|
||||
| (static_cast<uint32>(value[0]) & 0x000000FF);
|
||||
#endif
|
||||
}
|
||||
|
@ -74,15 +64,11 @@ CPP_UTILITIES_EXPORT inline uint32 toUInt24(const char *value)
|
|||
CPP_UTILITIES_EXPORT inline uint32 toUInt32(const char *value)
|
||||
{
|
||||
#if CONVERSION_UTILITIES_BINARY_CONVERSION_INTERNAL == 0
|
||||
return (static_cast<uint32>(value[0]) << 24 & 0xFF000000)
|
||||
| (static_cast<uint32>(value[1]) << 16 & 0x00FF0000)
|
||||
| (static_cast<uint32>(value[2]) << 8 & 0x0000FF00)
|
||||
| (static_cast<uint32>(value[3]) & 0x000000FF);
|
||||
return (static_cast<uint32>(value[0]) << 24 & 0xFF000000) | (static_cast<uint32>(value[1]) << 16 & 0x00FF0000)
|
||||
| (static_cast<uint32>(value[2]) << 8 & 0x0000FF00) | (static_cast<uint32>(value[3]) & 0x000000FF);
|
||||
#else
|
||||
return (static_cast<uint32>(value[3]) << 24 & 0xFF000000)
|
||||
| (static_cast<uint32>(value[2]) << 16 & 0x00FF0000)
|
||||
| (static_cast<uint32>(value[1]) << 8 & 0x0000FF00)
|
||||
| (static_cast<uint32>(value[0]) & 0x000000FF);
|
||||
return (static_cast<uint32>(value[3]) << 24 & 0xFF000000) | (static_cast<uint32>(value[2]) << 16 & 0x00FF0000)
|
||||
| (static_cast<uint32>(value[1]) << 8 & 0x0000FF00) | (static_cast<uint32>(value[0]) & 0x000000FF);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -92,23 +78,15 @@ CPP_UTILITIES_EXPORT inline uint32 toUInt32(const char *value)
|
|||
CPP_UTILITIES_EXPORT inline int64 toInt64(const char *value)
|
||||
{
|
||||
#if CONVERSION_UTILITIES_BINARY_CONVERSION_INTERNAL == 0
|
||||
return (static_cast<int64>(value[0]) << 56 & 0xFF00000000000000)
|
||||
| (static_cast<int64>(value[1]) << 48 & 0x00FF000000000000)
|
||||
| (static_cast<int64>(value[2]) << 40 & 0x0000FF0000000000)
|
||||
| (static_cast<int64>(value[3]) << 32 & 0x000000FF00000000)
|
||||
| (static_cast<int64>(value[4]) << 24 & 0x00000000FF000000)
|
||||
| (static_cast<int64>(value[5]) << 16 & 0x0000000000FF0000)
|
||||
| (static_cast<int64>(value[6]) << 8 & 0x000000000000FF00)
|
||||
| (static_cast<int64>(value[7]) & 0x00000000000000FF);
|
||||
return (static_cast<int64>(value[0]) << 56 & 0xFF00000000000000) | (static_cast<int64>(value[1]) << 48 & 0x00FF000000000000)
|
||||
| (static_cast<int64>(value[2]) << 40 & 0x0000FF0000000000) | (static_cast<int64>(value[3]) << 32 & 0x000000FF00000000)
|
||||
| (static_cast<int64>(value[4]) << 24 & 0x00000000FF000000) | (static_cast<int64>(value[5]) << 16 & 0x0000000000FF0000)
|
||||
| (static_cast<int64>(value[6]) << 8 & 0x000000000000FF00) | (static_cast<int64>(value[7]) & 0x00000000000000FF);
|
||||
#else
|
||||
return (static_cast<int64>(value[7]) << 56 & 0xFF00000000000000)
|
||||
| (static_cast<int64>(value[6]) << 48 & 0x00FF000000000000)
|
||||
| (static_cast<int64>(value[5]) << 40 & 0x0000FF0000000000)
|
||||
| (static_cast<int64>(value[4]) << 32 & 0x000000FF00000000)
|
||||
| (static_cast<int64>(value[3]) << 24 & 0x00000000FF000000)
|
||||
| (static_cast<int64>(value[2]) << 16 & 0x0000000000FF0000)
|
||||
| (static_cast<int64>(value[1]) << 8 & 0x000000000000FF00)
|
||||
| (static_cast<int64>(value[0]) & 0x00000000000000FF);
|
||||
return (static_cast<int64>(value[7]) << 56 & 0xFF00000000000000) | (static_cast<int64>(value[6]) << 48 & 0x00FF000000000000)
|
||||
| (static_cast<int64>(value[5]) << 40 & 0x0000FF0000000000) | (static_cast<int64>(value[4]) << 32 & 0x000000FF00000000)
|
||||
| (static_cast<int64>(value[3]) << 24 & 0x00000000FF000000) | (static_cast<int64>(value[2]) << 16 & 0x0000000000FF0000)
|
||||
| (static_cast<int64>(value[1]) << 8 & 0x000000000000FF00) | (static_cast<int64>(value[0]) & 0x00000000000000FF);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -118,23 +96,15 @@ CPP_UTILITIES_EXPORT inline int64 toInt64(const char *value)
|
|||
CPP_UTILITIES_EXPORT inline uint64 toUInt64(const char *value)
|
||||
{
|
||||
#if CONVERSION_UTILITIES_BINARY_CONVERSION_INTERNAL == 0
|
||||
return (static_cast<uint64>(value[0]) << 56 & 0xFF00000000000000)
|
||||
| (static_cast<uint64>(value[1]) << 48 & 0x00FF000000000000)
|
||||
| (static_cast<uint64>(value[2]) << 40 & 0x0000FF0000000000)
|
||||
| (static_cast<uint64>(value[3]) << 32 & 0x000000FF00000000)
|
||||
| (static_cast<uint64>(value[4]) << 24 & 0x00000000FF000000)
|
||||
| (static_cast<uint64>(value[5]) << 16 & 0x0000000000FF0000)
|
||||
| (static_cast<uint64>(value[6]) << 8 & 0x000000000000FF00)
|
||||
| (static_cast<uint64>(value[7]) & 0x00000000000000FF);
|
||||
return (static_cast<uint64>(value[0]) << 56 & 0xFF00000000000000) | (static_cast<uint64>(value[1]) << 48 & 0x00FF000000000000)
|
||||
| (static_cast<uint64>(value[2]) << 40 & 0x0000FF0000000000) | (static_cast<uint64>(value[3]) << 32 & 0x000000FF00000000)
|
||||
| (static_cast<uint64>(value[4]) << 24 & 0x00000000FF000000) | (static_cast<uint64>(value[5]) << 16 & 0x0000000000FF0000)
|
||||
| (static_cast<uint64>(value[6]) << 8 & 0x000000000000FF00) | (static_cast<uint64>(value[7]) & 0x00000000000000FF);
|
||||
#else
|
||||
return (static_cast<uint64>(value[7]) << 56 & 0xFF00000000000000)
|
||||
| (static_cast<uint64>(value[6]) << 48 & 0x00FF000000000000)
|
||||
| (static_cast<uint64>(value[5]) << 40 & 0x0000FF0000000000)
|
||||
| (static_cast<uint64>(value[4]) << 32 & 0x000000FF00000000)
|
||||
| (static_cast<uint64>(value[3]) << 24 & 0x00000000FF000000)
|
||||
| (static_cast<uint64>(value[2]) << 16 & 0x0000000000FF0000)
|
||||
| (static_cast<uint64>(value[1]) << 8 & 0x000000000000FF00)
|
||||
| (static_cast<uint64>(value[0]) & 0x00000000000000FF);
|
||||
return (static_cast<uint64>(value[7]) << 56 & 0xFF00000000000000) | (static_cast<uint64>(value[6]) << 48 & 0x00FF000000000000)
|
||||
| (static_cast<uint64>(value[5]) << 40 & 0x0000FF0000000000) | (static_cast<uint64>(value[4]) << 32 & 0x000000FF00000000)
|
||||
| (static_cast<uint64>(value[3]) << 24 & 0x00000000FF000000) | (static_cast<uint64>(value[2]) << 16 & 0x0000000000FF0000)
|
||||
| (static_cast<uint64>(value[1]) << 8 & 0x000000000000FF00) | (static_cast<uint64>(value[0]) & 0x00000000000000FF);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -11,22 +11,22 @@ namespace ConversionUtilities {
|
|||
/*!
|
||||
* \brief Constructs a new ConversionException.
|
||||
*/
|
||||
ConversionException::ConversionException() USE_NOTHROW :
|
||||
runtime_error("unable to convert")
|
||||
{}
|
||||
ConversionException::ConversionException() USE_NOTHROW : runtime_error("unable to convert")
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a new ConversionException. \a what is a std::string
|
||||
* describing the cause of the ConversionException.
|
||||
*/
|
||||
ConversionException::ConversionException(const std::string &what) USE_NOTHROW :
|
||||
runtime_error(what)
|
||||
{}
|
||||
ConversionException::ConversionException(const std::string &what) USE_NOTHROW : runtime_error(what)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Destroys the ConversionException.
|
||||
*/
|
||||
ConversionException::~ConversionException() USE_NOTHROW
|
||||
{}
|
||||
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,14 +8,12 @@
|
|||
|
||||
namespace ConversionUtilities {
|
||||
|
||||
class CPP_UTILITIES_EXPORT ConversionException : public std::runtime_error
|
||||
{
|
||||
class CPP_UTILITIES_EXPORT ConversionException : public std::runtime_error {
|
||||
public:
|
||||
ConversionException() USE_NOTHROW;
|
||||
ConversionException(const std::string &what) USE_NOTHROW;
|
||||
~ConversionException() USE_NOTHROW;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // CONVERSION_UTILITIES_CONVERSIONEXCEPTION_H
|
||||
|
|
|
@ -1,26 +1,23 @@
|
|||
#ifndef CONVERSION_UTILITIES_STRINGBUILDER_H
|
||||
#define CONVERSION_UTILITIES_STRINGBUILDER_H
|
||||
|
||||
#include "./stringconversion.h"
|
||||
#include "../misc/traits.h"
|
||||
#include "./stringconversion.h"
|
||||
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
|
||||
namespace ConversionUtilities
|
||||
{
|
||||
namespace ConversionUtilities {
|
||||
|
||||
/// \cond
|
||||
namespace Helper {
|
||||
|
||||
template<class StringType, Traits::EnableIf<std::is_class<StringType> >...>
|
||||
std::size_t computeTupleElementSize(const StringType *str)
|
||||
template <class StringType, Traits::EnableIf<std::is_class<StringType> >...> std::size_t computeTupleElementSize(const StringType *str)
|
||||
{
|
||||
return str->size();
|
||||
}
|
||||
|
||||
template<class StringType, Traits::EnableIf<std::is_class<StringType> >...>
|
||||
std::size_t computeTupleElementSize(const StringType &str)
|
||||
template <class StringType, Traits::EnableIf<std::is_class<StringType> >...> std::size_t computeTupleElementSize(const StringType &str)
|
||||
{
|
||||
return str.size();
|
||||
}
|
||||
|
@ -37,30 +34,32 @@ constexpr std::size_t computeTupleElementSize(CharType)
|
|||
return 1;
|
||||
}
|
||||
|
||||
template <class StringType, typename IntegralType, Traits::EnableIf<Traits::Not<std::is_same<typename StringType::value_type, IntegralType> >, std::is_integral<IntegralType>, std::is_unsigned<IntegralType> >...>
|
||||
template <class StringType, typename IntegralType, Traits::EnableIf<Traits::Not<std::is_same<typename StringType::value_type, IntegralType> >,
|
||||
std::is_integral<IntegralType>, std::is_unsigned<IntegralType> >...>
|
||||
std::size_t computeTupleElementSize(IntegralType number, typename StringType::value_type base = 10)
|
||||
{
|
||||
std::size_t size = 0;
|
||||
for(auto n = number; n; n /= base, ++size);
|
||||
for (auto n = number; n; n /= base, ++size)
|
||||
;
|
||||
return size;
|
||||
}
|
||||
|
||||
template <class StringType, typename IntegralType, Traits::EnableIf<Traits::Not<std::is_same<typename StringType::value_type, IntegralType> >, std::is_integral<IntegralType>, std::is_signed<IntegralType> >...>
|
||||
template <class StringType, typename IntegralType, Traits::EnableIf<Traits::Not<std::is_same<typename StringType::value_type, IntegralType> >,
|
||||
std::is_integral<IntegralType>, std::is_signed<IntegralType> >...>
|
||||
std::size_t computeTupleElementSize(IntegralType number, typename StringType::value_type base = 10)
|
||||
{
|
||||
std::size_t size = number < 0 ? 1 : 0;
|
||||
for(auto n = number; n; n /= base, ++size);
|
||||
for (auto n = number; n; n /= base, ++size)
|
||||
;
|
||||
return size;
|
||||
}
|
||||
|
||||
template<class StringType, Traits::EnableIf<std::is_class<StringType> >...>
|
||||
void append(StringType &target, const StringType *str)
|
||||
template <class StringType, Traits::EnableIf<std::is_class<StringType> >...> void append(StringType &target, const StringType *str)
|
||||
{
|
||||
target.append(*str);
|
||||
}
|
||||
|
||||
template<class StringType, Traits::EnableIf<std::is_class<StringType> >...>
|
||||
void append(StringType &target, const StringType &str)
|
||||
template <class StringType, Traits::EnableIf<std::is_class<StringType> >...> void append(StringType &target, const StringType &str)
|
||||
{
|
||||
target.append(str);
|
||||
}
|
||||
|
@ -77,7 +76,8 @@ void append(StringType &target, CharType c)
|
|||
target += c;
|
||||
}
|
||||
|
||||
template <class StringType, typename IntegralType, Traits::EnableIf<Traits::Not<std::is_same<typename StringType::value_type, IntegralType> >, std::is_integral<IntegralType>, std::is_unsigned<IntegralType> >...>
|
||||
template <class StringType, typename IntegralType, Traits::EnableIf<Traits::Not<std::is_same<typename StringType::value_type, IntegralType> >,
|
||||
std::is_integral<IntegralType>, std::is_unsigned<IntegralType> >...>
|
||||
void append(StringType &target, IntegralType number, typename StringType::value_type base = 10)
|
||||
{
|
||||
const auto start = target.begin() + target.size();
|
||||
|
@ -87,7 +87,8 @@ void append(StringType &target, IntegralType number, typename StringType::value_
|
|||
} while (number);
|
||||
}
|
||||
|
||||
template <class StringType, typename IntegralType, Traits::EnableIf<Traits::Not<std::is_same<typename StringType::value_type, IntegralType> >, std::is_integral<IntegralType>, std::is_signed<IntegralType> >...>
|
||||
template <class StringType, typename IntegralType, Traits::EnableIf<Traits::Not<std::is_same<typename StringType::value_type, IntegralType> >,
|
||||
std::is_integral<IntegralType>, std::is_signed<IntegralType> >...>
|
||||
void append(StringType &target, IntegralType number, typename StringType::value_type base = 10)
|
||||
{
|
||||
if (number < 0) {
|
||||
|
@ -101,8 +102,7 @@ void append(StringType &target, IntegralType number, typename StringType::value_
|
|||
} while (number);
|
||||
}
|
||||
|
||||
template<class StringType, class Tuple, std::size_t N>
|
||||
struct TupleToString {
|
||||
template <class StringType, class Tuple, std::size_t N> struct TupleToString {
|
||||
static std::size_t precomputeSize(const Tuple &tuple)
|
||||
{
|
||||
return TupleToString<StringType, Tuple, N - 1>::precomputeSize(tuple) + computeTupleElementSize<StringType>(std::get<N - 1>(tuple));
|
||||
|
@ -115,8 +115,7 @@ struct TupleToString {
|
|||
}
|
||||
};
|
||||
|
||||
template<class StringType, class Tuple>
|
||||
struct TupleToString<StringType, Tuple, 1> {
|
||||
template <class StringType, class Tuple> struct TupleToString<StringType, Tuple, 1> {
|
||||
static std::size_t precomputeSize(const Tuple &tuple)
|
||||
{
|
||||
return computeTupleElementSize<StringType>(std::get<0>(tuple));
|
||||
|
@ -127,15 +126,13 @@ struct TupleToString<StringType, Tuple, 1> {
|
|||
Helper::append(str, std::get<0>(tuple));
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
/// \endcond
|
||||
|
||||
/*!
|
||||
* \brief Concatenates all strings hold by the specified \a tuple.
|
||||
*/
|
||||
template<class StringType = std::string, class... Args>
|
||||
StringType tupleToString(const std::tuple<Args...> &tuple)
|
||||
template <class StringType = std::string, class... Args> StringType tupleToString(const std::tuple<Args...> &tuple)
|
||||
{
|
||||
StringType res;
|
||||
res.reserve(Helper::TupleToString<StringType, decltype(tuple), sizeof...(Args)>::precomputeSize(tuple));
|
||||
|
@ -143,8 +140,7 @@ StringType tupleToString(const std::tuple<Args...> &tuple)
|
|||
return res;
|
||||
}
|
||||
|
||||
template<class StringType = std::string, class... Args>
|
||||
constexpr StringType argsToString(Args&&... args)
|
||||
template <class StringType = std::string, class... Args> constexpr StringType argsToString(Args &&... args)
|
||||
{
|
||||
return tupleToString(std::make_tuple(args...));
|
||||
}
|
||||
|
@ -152,8 +148,7 @@ constexpr StringType argsToString(Args&&... args)
|
|||
/*!
|
||||
* \brief Allows construction of string-tuples via %-operator, eg. string1 % "string2" % string3.
|
||||
*/
|
||||
template<class Tuple>
|
||||
constexpr auto operator %(const Tuple &lhs, const std::string &rhs) -> decltype(std::tuple_cat(lhs, std::make_tuple(&rhs)))
|
||||
template <class Tuple> constexpr auto operator%(const Tuple &lhs, const std::string &rhs) -> decltype(std::tuple_cat(lhs, std::make_tuple(&rhs)))
|
||||
{
|
||||
return std::tuple_cat(lhs, std::make_tuple(&rhs));
|
||||
}
|
||||
|
@ -161,8 +156,7 @@ constexpr auto operator %(const Tuple &lhs, const std::string &rhs) -> decltype(
|
|||
/*!
|
||||
* \brief Allows construction of string-tuples via %-operator, eg. string1 % "string2" % string3.
|
||||
*/
|
||||
template<class Tuple>
|
||||
constexpr auto operator %(const Tuple &lhs, const char *rhs) -> decltype(std::tuple_cat(lhs, std::make_tuple(rhs)))
|
||||
template <class Tuple> constexpr auto operator%(const Tuple &lhs, const char *rhs) -> decltype(std::tuple_cat(lhs, std::make_tuple(rhs)))
|
||||
{
|
||||
return std::tuple_cat(lhs, std::make_tuple(rhs));
|
||||
}
|
||||
|
@ -260,7 +254,6 @@ inline std::string operator +(const Tuple &lhs, IntegralType rhs)
|
|||
{
|
||||
return tupleToString(std::tuple_cat(lhs, std::make_tuple(rhs)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // CONVERSION_UTILITIES_STRINGBUILDER_H
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
#include "./stringconversion.h"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <iomanip>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <cstdlib>
|
||||
|
||||
#include <iconv.h>
|
||||
#include <errno.h>
|
||||
#include <iconv.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
@ -17,36 +17,52 @@ using namespace std;
|
|||
* binaryconversion.h declares functions which convert base data types to an array of bytes and vice versa.
|
||||
* stringconversion.h declares different functions around string conversion such as converting a number to a string and vice versa.
|
||||
*/
|
||||
namespace ConversionUtilities
|
||||
{
|
||||
namespace ConversionUtilities {
|
||||
|
||||
/// \cond
|
||||
|
||||
struct Keep { size_t operator()(size_t value) { return value; } };
|
||||
struct Double { size_t operator()(size_t value) { return value + value; } };
|
||||
struct Half { size_t operator()(size_t value) { return value / 2; } };
|
||||
struct Keep {
|
||||
size_t operator()(size_t value)
|
||||
{
|
||||
return value;
|
||||
}
|
||||
};
|
||||
struct Double {
|
||||
size_t operator()(size_t value)
|
||||
{
|
||||
return value + value;
|
||||
}
|
||||
};
|
||||
struct Half {
|
||||
size_t operator()(size_t value)
|
||||
{
|
||||
return value / 2;
|
||||
}
|
||||
};
|
||||
struct Factor {
|
||||
Factor(float factor) : factor(factor) {};
|
||||
size_t operator()(size_t value) { return value * factor; }
|
||||
Factor(float factor)
|
||||
: factor(factor){};
|
||||
size_t operator()(size_t value)
|
||||
{
|
||||
return value * factor;
|
||||
}
|
||||
float factor;
|
||||
};
|
||||
|
||||
template<class OutputSizeHint>
|
||||
class ConversionDescriptor
|
||||
{
|
||||
template <class OutputSizeHint> class ConversionDescriptor {
|
||||
public:
|
||||
ConversionDescriptor(const char *fromCharset, const char *toCharset) :
|
||||
m_ptr(iconv_open(toCharset, fromCharset)),
|
||||
m_outputSizeHint(OutputSizeHint())
|
||||
ConversionDescriptor(const char *fromCharset, const char *toCharset)
|
||||
: m_ptr(iconv_open(toCharset, fromCharset))
|
||||
, m_outputSizeHint(OutputSizeHint())
|
||||
{
|
||||
if (m_ptr == reinterpret_cast<iconv_t>(-1)) {
|
||||
throw ConversionException("Unable to allocate descriptor for character set conversion.");
|
||||
}
|
||||
}
|
||||
|
||||
ConversionDescriptor(const char *fromCharset, const char *toCharset, OutputSizeHint outputSizeHint) :
|
||||
m_ptr(iconv_open(toCharset, fromCharset)),
|
||||
m_outputSizeHint(outputSizeHint)
|
||||
ConversionDescriptor(const char *fromCharset, const char *toCharset, OutputSizeHint outputSizeHint)
|
||||
: m_ptr(iconv_open(toCharset, fromCharset))
|
||||
, m_outputSizeHint(outputSizeHint)
|
||||
{
|
||||
if (m_ptr == reinterpret_cast<iconv_t>(-1)) {
|
||||
throw ConversionException("Unable to allocate descriptor for character set conversion.");
|
||||
|
@ -110,7 +126,8 @@ private:
|
|||
* 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).
|
||||
*/
|
||||
StringData convertString(const char *fromCharset, const char *toCharset, const char *inputBuffer, std::size_t inputBufferSize, float outputBufferSizeFactor)
|
||||
StringData convertString(
|
||||
const char *fromCharset, const char *toCharset, const char *inputBuffer, std::size_t inputBufferSize, float outputBufferSizeFactor)
|
||||
{
|
||||
return ConversionDescriptor<Factor>(fromCharset, toCharset, outputBufferSizeFactor).convertString(inputBuffer, inputBufferSize);
|
||||
}
|
||||
|
@ -346,5 +363,4 @@ pair<unique_ptr<byte[]>, uint32> decodeBase64(const char *encodedStr, const uint
|
|||
}
|
||||
return make_pair(move(buffer), decodedSize);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,22 +1,21 @@
|
|||
#ifndef CONVERSION_UTILITIES_STRINGCONVERSION_H
|
||||
#define CONVERSION_UTILITIES_STRINGCONVERSION_H
|
||||
|
||||
#include "./conversionexception.h"
|
||||
#include "./binaryconversion.h"
|
||||
#include "./conversionexception.h"
|
||||
|
||||
#include "../misc/traits.h"
|
||||
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <initializer_list>
|
||||
#include <iomanip>
|
||||
#include <list>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace ConversionUtilities
|
||||
{
|
||||
namespace ConversionUtilities {
|
||||
|
||||
/*!
|
||||
* \brief The StringDataDeleter struct deletes the data of a StringData instance.
|
||||
|
@ -38,7 +37,8 @@ struct CPP_UTILITIES_EXPORT StringDataDeleter {
|
|||
typedef std::pair<std::unique_ptr<char[], StringDataDeleter>, std::size_t> StringData;
|
||||
//typedef std::pair<std::unique_ptr<char>, std::size_t> StringData; // might work too
|
||||
|
||||
CPP_UTILITIES_EXPORT StringData convertString(const char *fromCharset, const char *toCharset, const char *inputBuffer, std::size_t inputBufferSize, float outputBufferSizeFactor = 1.0f);
|
||||
CPP_UTILITIES_EXPORT StringData convertString(
|
||||
const char *fromCharset, const char *toCharset, const char *inputBuffer, std::size_t inputBufferSize, float outputBufferSizeFactor = 1.0f);
|
||||
CPP_UTILITIES_EXPORT StringData convertUtf8ToUtf16LE(const char *inputBuffer, std::size_t inputBufferSize);
|
||||
CPP_UTILITIES_EXPORT StringData convertUtf16LEToUtf8(const char *inputBuffer, std::size_t inputBufferSize);
|
||||
CPP_UTILITIES_EXPORT StringData convertUtf8ToUtf16BE(const char *inputBuffer, std::size_t inputBufferSize);
|
||||
|
@ -62,7 +62,10 @@ CPP_UTILITIES_EXPORT void truncateString(std::string &str, char terminationChar
|
|||
* \returns Returns the joined string.
|
||||
*/
|
||||
template <class Container = std::initializer_list<std::string> >
|
||||
typename 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())
|
||||
typename 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())
|
||||
{
|
||||
typename Container::value_type res;
|
||||
if (strings.size()) {
|
||||
|
@ -94,8 +97,7 @@ typename Container::value_type joinStrings(const Container &strings, const typen
|
|||
/*!
|
||||
* \brief Specifies the role of empty parts when splitting strings.
|
||||
*/
|
||||
enum class EmptyPartsTreat
|
||||
{
|
||||
enum class EmptyPartsTreat {
|
||||
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 */
|
||||
|
@ -111,7 +113,8 @@ enum class EmptyPartsTreat
|
|||
* \returns Returns the parts.
|
||||
*/
|
||||
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)
|
||||
Container splitString(const typename Container::value_type &string, const typename Container::value_type &delimiter,
|
||||
EmptyPartsTreat emptyPartsRole = EmptyPartsTreat::Keep, int maxParts = -1)
|
||||
{
|
||||
--maxParts;
|
||||
Container res;
|
||||
|
@ -150,8 +153,7 @@ Container splitString(const typename Container::value_type &string, const typena
|
|||
/*!
|
||||
* \brief Returns whether \a str starts with \a phrase.
|
||||
*/
|
||||
template <typename StringType>
|
||||
bool startsWith(const StringType &str, const StringType &phrase)
|
||||
template <typename StringType> bool startsWith(const StringType &str, const StringType &phrase)
|
||||
{
|
||||
if (str.size() < phrase.size()) {
|
||||
return false;
|
||||
|
@ -169,8 +171,7 @@ bool startsWith(const StringType &str, const StringType &phrase)
|
|||
/*!
|
||||
* \brief Returns whether \a str starts with \a phrase.
|
||||
*/
|
||||
template <typename StringType>
|
||||
bool startsWith(const StringType &str, const typename StringType::value_type *phrase)
|
||||
template <typename StringType> bool startsWith(const StringType &str, const typename StringType::value_type *phrase)
|
||||
{
|
||||
for (auto stri = str.cbegin(), strend = str.cend(); stri != strend; ++stri, ++phrase) {
|
||||
if (!*phrase) {
|
||||
|
@ -186,8 +187,7 @@ bool startsWith(const StringType &str, const typename StringType::value_type *ph
|
|||
* \brief Returns whether \a str contains the specified \a substrings.
|
||||
* \remarks The \a substrings must occur in the specified order.
|
||||
*/
|
||||
template <typename StringType>
|
||||
bool containsSubstrings(const StringType &str, std::initializer_list<StringType> substrings)
|
||||
template <typename StringType> bool containsSubstrings(const StringType &str, std::initializer_list<StringType> substrings)
|
||||
{
|
||||
typename StringType::size_type currentPos = 0;
|
||||
for (const auto &substr : substrings) {
|
||||
|
@ -219,8 +219,7 @@ bool containsSubstrings(const StringType &str, std::initializer_list<const typen
|
|||
/*!
|
||||
* \brief Replaces all occurences of \a find with \a relpace in the specified \a str.
|
||||
*/
|
||||
template <typename StringType>
|
||||
void findAndReplace(StringType &str, const StringType &find, const StringType &replace)
|
||||
template <typename StringType> void findAndReplace(StringType &str, const StringType &find, const StringType &replace)
|
||||
{
|
||||
for (typename StringType::size_type i = 0; (i = str.find(find, i)) != StringType::npos; i += replace.size()) {
|
||||
str.replace(i, find.size(), replace);
|
||||
|
@ -233,8 +232,7 @@ void findAndReplace(StringType &str, const StringType &find, const StringType &r
|
|||
* - Uses capital letters.
|
||||
* - Valid values for \a digit: 0 <= \a digit <= 35
|
||||
*/
|
||||
template <typename CharType>
|
||||
CharType digitToChar(CharType digit)
|
||||
template <typename CharType> CharType digitToChar(CharType digit)
|
||||
{
|
||||
CharType res;
|
||||
if (digit <= 9) {
|
||||
|
@ -251,11 +249,13 @@ CharType digitToChar(CharType digit)
|
|||
* \tparam StringType The string type (should be an instantiation of the basic_string class template).
|
||||
* \sa stringToNumber()
|
||||
*/
|
||||
template <typename IntegralType, class StringType = std::string, Traits::EnableIf<std::is_integral<IntegralType>, Traits::Not<std::is_signed<IntegralType> > >...>
|
||||
template <typename IntegralType, class StringType = std::string,
|
||||
Traits::EnableIf<std::is_integral<IntegralType>, Traits::Not<std::is_signed<IntegralType> > >...>
|
||||
StringType numberToString(IntegralType number, typename StringType::value_type base = 10)
|
||||
{
|
||||
std::size_t resSize = 0;
|
||||
for(auto n = number; n; n /= base, ++resSize);
|
||||
for (auto n = number; n; n /= base, ++resSize)
|
||||
;
|
||||
StringType res;
|
||||
res.reserve(resSize);
|
||||
do {
|
||||
|
@ -281,7 +281,8 @@ StringType numberToString(IntegralType number, typename StringType::value_type b
|
|||
} else {
|
||||
resSize = 0;
|
||||
}
|
||||
for(auto n = number; n; n /= base, ++resSize);
|
||||
for (auto n = number; n; n /= base, ++resSize)
|
||||
;
|
||||
StringType res;
|
||||
res.reserve(resSize);
|
||||
do {
|
||||
|
@ -314,8 +315,7 @@ StringType numberToString(FloatingType number, typename StringType::value_type b
|
|||
* \brief Returns number/digit of the specified \a character representation using the specified \a base.
|
||||
* \throws A ConversionException will be thrown if the provided \a character does not represent a valid digit for the specified \a base.
|
||||
*/
|
||||
template <typename CharType>
|
||||
CharType charToDigit(CharType character, CharType base)
|
||||
template <typename CharType> CharType charToDigit(CharType character, CharType base)
|
||||
{
|
||||
CharType res;
|
||||
if (character >= '0' && character <= '9') {
|
||||
|
@ -464,8 +464,7 @@ IntegralType stringToNumber(const CharType *string, unsigned char base = 10)
|
|||
*
|
||||
* \tparam T The data type of the integer to be interpreted.
|
||||
*/
|
||||
template <typename T>
|
||||
std::string interpretIntegerAsString(T integer, int startOffset = 0)
|
||||
template <typename T> std::string interpretIntegerAsString(T integer, int startOffset = 0)
|
||||
{
|
||||
char buffer[sizeof(T)];
|
||||
ConversionUtilities::BE::getBytes(integer, buffer);
|
||||
|
@ -476,7 +475,6 @@ CPP_UTILITIES_EXPORT std::string dataSizeToString(uint64 sizeInByte, bool includ
|
|||
CPP_UTILITIES_EXPORT std::string bitrateToString(double speedInKbitsPerSecond, bool useByteInsteadOfBits = false);
|
||||
CPP_UTILITIES_EXPORT std::string encodeBase64(const byte *data, uint32 dataSize);
|
||||
CPP_UTILITIES_EXPORT std::pair<std::unique_ptr<byte[]>, uint32> decodeBase64(const char *encodedStr, const uint32 strSize);
|
||||
|
||||
}
|
||||
|
||||
#endif // CONVERSION_UTILITIES_STRINGCONVERSION_H
|
||||
|
|
|
@ -3,30 +3,29 @@
|
|||
|
||||
#include "../global.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <locale>
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
#include <locale>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace ConversionUtilities
|
||||
{
|
||||
namespace ConversionUtilities {
|
||||
|
||||
/*!
|
||||
* \brief Converts a std::string to a wide string using the specified locale.
|
||||
* \deprecated Might be removed in future release because not used anymore. Use iconv based string converion functions instead.
|
||||
*/
|
||||
template <class E, class T = std::char_traits<E>, class A = std::allocator<E> >
|
||||
class CPP_UTILITIES_EXPORT Widen : public std::unary_function<const std::string &, std::basic_string<E, T, A> >
|
||||
{
|
||||
class CPP_UTILITIES_EXPORT Widen : public std::unary_function<const std::string &, std::basic_string<E, T, A> > {
|
||||
public:
|
||||
/*!
|
||||
* \brief Constructs a new instance with the specified \a locale.
|
||||
*/
|
||||
Widen(const std::locale &locale = std::locale()) :
|
||||
m_loc(locale),
|
||||
m_pctype(&std::use_facet<std::ctype<E> >(locale))
|
||||
{}
|
||||
Widen(const std::locale &locale = std::locale())
|
||||
: m_loc(locale)
|
||||
, m_pctype(&std::use_facet<std::ctype<E> >(locale))
|
||||
{
|
||||
}
|
||||
|
||||
Widen(const Widen &) = delete;
|
||||
Widen &operator=(const Widen &) = delete;
|
||||
|
@ -47,7 +46,6 @@ private:
|
|||
std::locale m_loc;
|
||||
const std::ctype<E> *m_pctype;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // CONVERSION_UTILITIES_WIDEN_H
|
||||
|
|
|
@ -11,26 +11,11 @@
|
|||
*/
|
||||
namespace EscapeCodes {
|
||||
|
||||
enum class Color : char
|
||||
{
|
||||
Black = '0',
|
||||
Red,
|
||||
Green,
|
||||
Yellow,
|
||||
Blue,
|
||||
Purple,
|
||||
Cyan,
|
||||
White
|
||||
};
|
||||
enum class Color : char { Black = '0', Red, Green, Yellow, Blue, Purple, Cyan, White };
|
||||
|
||||
enum class ColorContext : char
|
||||
{
|
||||
Foreground = '3',
|
||||
Background = '4'
|
||||
};
|
||||
enum class ColorContext : char { Foreground = '3', Background = '4' };
|
||||
|
||||
enum class TextAttribute : char
|
||||
{
|
||||
enum class TextAttribute : char {
|
||||
Reset = '0',
|
||||
Bold = '1',
|
||||
Dim = '2',
|
||||
|
@ -41,33 +26,23 @@ enum class TextAttribute : char
|
|||
Concealed = '8'
|
||||
};
|
||||
|
||||
enum class Direction : char
|
||||
{
|
||||
Up = 'A',
|
||||
Down = 'B',
|
||||
Forward = 'C',
|
||||
Backward = 'D'
|
||||
};
|
||||
enum class Direction : char { Up = 'A', Down = 'B', Forward = 'C', Backward = 'D' };
|
||||
|
||||
inline void setStyle(std::ostream &stream, TextAttribute displayAttribute = TextAttribute::Reset)
|
||||
{
|
||||
stream << '\e' << '[' << static_cast<char>(displayAttribute) << 'm';
|
||||
}
|
||||
|
||||
inline void setStyle(std::ostream &stream, Color color,
|
||||
ColorContext context = ColorContext::Foreground,
|
||||
TextAttribute displayAttribute = TextAttribute::Reset)
|
||||
inline void setStyle(
|
||||
std::ostream &stream, Color color, ColorContext context = ColorContext::Foreground, TextAttribute displayAttribute = TextAttribute::Reset)
|
||||
{
|
||||
stream << '\e' << '[' << static_cast<char>(displayAttribute) << ';'
|
||||
<< static_cast<char>(context) << static_cast<char>(color) << 'm';
|
||||
stream << '\e' << '[' << static_cast<char>(displayAttribute) << ';' << static_cast<char>(context) << static_cast<char>(color) << 'm';
|
||||
}
|
||||
|
||||
inline void setStyle(std::ostream &stream, Color foregroundColor, Color backgroundColor,
|
||||
TextAttribute displayAttribute = TextAttribute::Reset)
|
||||
inline void setStyle(std::ostream &stream, Color foregroundColor, Color backgroundColor, TextAttribute displayAttribute = TextAttribute::Reset)
|
||||
{
|
||||
stream << '\e' << '[' << static_cast<char>(displayAttribute) << ';'
|
||||
<< static_cast<char>(ColorContext::Foreground) << static_cast<char>(foregroundColor) << ';'
|
||||
<< static_cast<char>(ColorContext::Foreground) << static_cast<char>(backgroundColor) << 'm';
|
||||
stream << '\e' << '[' << static_cast<char>(displayAttribute) << ';' << static_cast<char>(ColorContext::Foreground)
|
||||
<< static_cast<char>(foregroundColor) << ';' << static_cast<char>(ColorContext::Foreground) << static_cast<char>(backgroundColor) << 'm';
|
||||
}
|
||||
|
||||
inline void resetStyle(std::ostream &stream)
|
||||
|
@ -104,8 +79,6 @@ inline void eraseLine(std::ostream &stream)
|
|||
{
|
||||
stream << "\33[2K";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // IOUTILITIES_ANSIESCAPECODES
|
||||
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
|
||||
#include "../conversion/conversionexception.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#include <cstring>
|
||||
|
||||
using namespace std;
|
||||
using namespace IoUtilities;
|
||||
|
@ -25,19 +25,21 @@ using namespace ConversionUtilities;
|
|||
* \brief Constructs a new BinaryReader.
|
||||
* \param stream Specifies the stream to read from.
|
||||
*/
|
||||
BinaryReader::BinaryReader(istream *stream) :
|
||||
m_stream(stream),
|
||||
m_ownership(false)
|
||||
{}
|
||||
BinaryReader::BinaryReader(istream *stream)
|
||||
: m_stream(stream)
|
||||
, m_ownership(false)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Copies the specified BinaryReader.
|
||||
* \remarks The copy will not take ownership over the stream.
|
||||
*/
|
||||
BinaryReader::BinaryReader(const BinaryReader &other) :
|
||||
m_stream(other.m_stream),
|
||||
m_ownership(false)
|
||||
{}
|
||||
BinaryReader::BinaryReader(const BinaryReader &other)
|
||||
: m_stream(other.m_stream)
|
||||
, m_ownership(false)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Destroys the BinaryReader.
|
||||
|
@ -291,49 +293,25 @@ uint32 BinaryReader::computeCrc32(const char *buffer, size_t length)
|
|||
* \remarks Internally used by readCrc32() method.
|
||||
* \sa readCrc32()
|
||||
*/
|
||||
const uint32 BinaryReader::crc32Table[] = {
|
||||
0x00000000, 0x04c11db7, 0x09823b6e, 0x0d4326d9, 0x130476dc, 0x17c56b6b,
|
||||
0x1a864db2, 0x1e475005, 0x2608edb8, 0x22c9f00f, 0x2f8ad6d6, 0x2b4bcb61,
|
||||
0x350c9b64, 0x31cd86d3, 0x3c8ea00a, 0x384fbdbd, 0x4c11db70, 0x48d0c6c7,
|
||||
0x4593e01e, 0x4152fda9, 0x5f15adac, 0x5bd4b01b, 0x569796c2, 0x52568b75,
|
||||
0x6a1936c8, 0x6ed82b7f, 0x639b0da6, 0x675a1011, 0x791d4014, 0x7ddc5da3,
|
||||
0x709f7b7a, 0x745e66cd, 0x9823b6e0, 0x9ce2ab57, 0x91a18d8e, 0x95609039,
|
||||
0x8b27c03c, 0x8fe6dd8b, 0x82a5fb52, 0x8664e6e5, 0xbe2b5b58, 0xbaea46ef,
|
||||
0xb7a96036, 0xb3687d81, 0xad2f2d84, 0xa9ee3033, 0xa4ad16ea, 0xa06c0b5d,
|
||||
0xd4326d90, 0xd0f37027, 0xddb056fe, 0xd9714b49, 0xc7361b4c, 0xc3f706fb,
|
||||
0xceb42022, 0xca753d95, 0xf23a8028, 0xf6fb9d9f, 0xfbb8bb46, 0xff79a6f1,
|
||||
0xe13ef6f4, 0xe5ffeb43, 0xe8bccd9a, 0xec7dd02d, 0x34867077, 0x30476dc0,
|
||||
0x3d044b19, 0x39c556ae, 0x278206ab, 0x23431b1c, 0x2e003dc5, 0x2ac12072,
|
||||
0x128e9dcf, 0x164f8078, 0x1b0ca6a1, 0x1fcdbb16, 0x018aeb13, 0x054bf6a4,
|
||||
0x0808d07d, 0x0cc9cdca, 0x7897ab07, 0x7c56b6b0, 0x71159069, 0x75d48dde,
|
||||
0x6b93dddb, 0x6f52c06c, 0x6211e6b5, 0x66d0fb02, 0x5e9f46bf, 0x5a5e5b08,
|
||||
0x571d7dd1, 0x53dc6066, 0x4d9b3063, 0x495a2dd4, 0x44190b0d, 0x40d816ba,
|
||||
0xaca5c697, 0xa864db20, 0xa527fdf9, 0xa1e6e04e, 0xbfa1b04b, 0xbb60adfc,
|
||||
0xb6238b25, 0xb2e29692, 0x8aad2b2f, 0x8e6c3698, 0x832f1041, 0x87ee0df6,
|
||||
0x99a95df3, 0x9d684044, 0x902b669d, 0x94ea7b2a, 0xe0b41de7, 0xe4750050,
|
||||
0xe9362689, 0xedf73b3e, 0xf3b06b3b, 0xf771768c, 0xfa325055, 0xfef34de2,
|
||||
0xc6bcf05f, 0xc27dede8, 0xcf3ecb31, 0xcbffd686, 0xd5b88683, 0xd1799b34,
|
||||
0xdc3abded, 0xd8fba05a, 0x690ce0ee, 0x6dcdfd59, 0x608edb80, 0x644fc637,
|
||||
0x7a089632, 0x7ec98b85, 0x738aad5c, 0x774bb0eb, 0x4f040d56, 0x4bc510e1,
|
||||
0x46863638, 0x42472b8f, 0x5c007b8a, 0x58c1663d, 0x558240e4, 0x51435d53,
|
||||
0x251d3b9e, 0x21dc2629, 0x2c9f00f0, 0x285e1d47, 0x36194d42, 0x32d850f5,
|
||||
0x3f9b762c, 0x3b5a6b9b, 0x0315d626, 0x07d4cb91, 0x0a97ed48, 0x0e56f0ff,
|
||||
0x1011a0fa, 0x14d0bd4d, 0x19939b94, 0x1d528623, 0xf12f560e, 0xf5ee4bb9,
|
||||
0xf8ad6d60, 0xfc6c70d7, 0xe22b20d2, 0xe6ea3d65, 0xeba91bbc, 0xef68060b,
|
||||
0xd727bbb6, 0xd3e6a601, 0xdea580d8, 0xda649d6f, 0xc423cd6a, 0xc0e2d0dd,
|
||||
0xcda1f604, 0xc960ebb3, 0xbd3e8d7e, 0xb9ff90c9, 0xb4bcb610, 0xb07daba7,
|
||||
0xae3afba2, 0xaafbe615, 0xa7b8c0cc, 0xa379dd7b, 0x9b3660c6, 0x9ff77d71,
|
||||
0x92b45ba8, 0x9675461f, 0x8832161a, 0x8cf30bad, 0x81b02d74, 0x857130c3,
|
||||
0x5d8a9099, 0x594b8d2e, 0x5408abf7, 0x50c9b640, 0x4e8ee645, 0x4a4ffbf2,
|
||||
0x470cdd2b, 0x43cdc09c, 0x7b827d21, 0x7f436096, 0x7200464f, 0x76c15bf8,
|
||||
0x68860bfd, 0x6c47164a, 0x61043093, 0x65c52d24, 0x119b4be9, 0x155a565e,
|
||||
0x18197087, 0x1cd86d30, 0x029f3d35, 0x065e2082, 0x0b1d065b, 0x0fdc1bec,
|
||||
0x3793a651, 0x3352bbe6, 0x3e119d3f, 0x3ad08088, 0x2497d08d, 0x2056cd3a,
|
||||
0x2d15ebe3, 0x29d4f654, 0xc5a92679, 0xc1683bce, 0xcc2b1d17, 0xc8ea00a0,
|
||||
0xd6ad50a5, 0xd26c4d12, 0xdf2f6bcb, 0xdbee767c, 0xe3a1cbc1, 0xe760d676,
|
||||
0xea23f0af, 0xeee2ed18, 0xf0a5bd1d, 0xf464a0aa, 0xf9278673, 0xfde69bc4,
|
||||
0x89b8fd09, 0x8d79e0be, 0x803ac667, 0x84fbdbd0, 0x9abc8bd5, 0x9e7d9662,
|
||||
0x933eb0bb, 0x97ffad0c, 0xafb010b1, 0xab710d06, 0xa6322bdf, 0xa2f33668,
|
||||
0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4
|
||||
};
|
||||
|
||||
const uint32 BinaryReader::crc32Table[] = { 0x00000000, 0x04c11db7, 0x09823b6e, 0x0d4326d9, 0x130476dc, 0x17c56b6b, 0x1a864db2, 0x1e475005,
|
||||
0x2608edb8, 0x22c9f00f, 0x2f8ad6d6, 0x2b4bcb61, 0x350c9b64, 0x31cd86d3, 0x3c8ea00a, 0x384fbdbd, 0x4c11db70, 0x48d0c6c7, 0x4593e01e, 0x4152fda9,
|
||||
0x5f15adac, 0x5bd4b01b, 0x569796c2, 0x52568b75, 0x6a1936c8, 0x6ed82b7f, 0x639b0da6, 0x675a1011, 0x791d4014, 0x7ddc5da3, 0x709f7b7a, 0x745e66cd,
|
||||
0x9823b6e0, 0x9ce2ab57, 0x91a18d8e, 0x95609039, 0x8b27c03c, 0x8fe6dd8b, 0x82a5fb52, 0x8664e6e5, 0xbe2b5b58, 0xbaea46ef, 0xb7a96036, 0xb3687d81,
|
||||
0xad2f2d84, 0xa9ee3033, 0xa4ad16ea, 0xa06c0b5d, 0xd4326d90, 0xd0f37027, 0xddb056fe, 0xd9714b49, 0xc7361b4c, 0xc3f706fb, 0xceb42022, 0xca753d95,
|
||||
0xf23a8028, 0xf6fb9d9f, 0xfbb8bb46, 0xff79a6f1, 0xe13ef6f4, 0xe5ffeb43, 0xe8bccd9a, 0xec7dd02d, 0x34867077, 0x30476dc0, 0x3d044b19, 0x39c556ae,
|
||||
0x278206ab, 0x23431b1c, 0x2e003dc5, 0x2ac12072, 0x128e9dcf, 0x164f8078, 0x1b0ca6a1, 0x1fcdbb16, 0x018aeb13, 0x054bf6a4, 0x0808d07d, 0x0cc9cdca,
|
||||
0x7897ab07, 0x7c56b6b0, 0x71159069, 0x75d48dde, 0x6b93dddb, 0x6f52c06c, 0x6211e6b5, 0x66d0fb02, 0x5e9f46bf, 0x5a5e5b08, 0x571d7dd1, 0x53dc6066,
|
||||
0x4d9b3063, 0x495a2dd4, 0x44190b0d, 0x40d816ba, 0xaca5c697, 0xa864db20, 0xa527fdf9, 0xa1e6e04e, 0xbfa1b04b, 0xbb60adfc, 0xb6238b25, 0xb2e29692,
|
||||
0x8aad2b2f, 0x8e6c3698, 0x832f1041, 0x87ee0df6, 0x99a95df3, 0x9d684044, 0x902b669d, 0x94ea7b2a, 0xe0b41de7, 0xe4750050, 0xe9362689, 0xedf73b3e,
|
||||
0xf3b06b3b, 0xf771768c, 0xfa325055, 0xfef34de2, 0xc6bcf05f, 0xc27dede8, 0xcf3ecb31, 0xcbffd686, 0xd5b88683, 0xd1799b34, 0xdc3abded, 0xd8fba05a,
|
||||
0x690ce0ee, 0x6dcdfd59, 0x608edb80, 0x644fc637, 0x7a089632, 0x7ec98b85, 0x738aad5c, 0x774bb0eb, 0x4f040d56, 0x4bc510e1, 0x46863638, 0x42472b8f,
|
||||
0x5c007b8a, 0x58c1663d, 0x558240e4, 0x51435d53, 0x251d3b9e, 0x21dc2629, 0x2c9f00f0, 0x285e1d47, 0x36194d42, 0x32d850f5, 0x3f9b762c, 0x3b5a6b9b,
|
||||
0x0315d626, 0x07d4cb91, 0x0a97ed48, 0x0e56f0ff, 0x1011a0fa, 0x14d0bd4d, 0x19939b94, 0x1d528623, 0xf12f560e, 0xf5ee4bb9, 0xf8ad6d60, 0xfc6c70d7,
|
||||
0xe22b20d2, 0xe6ea3d65, 0xeba91bbc, 0xef68060b, 0xd727bbb6, 0xd3e6a601, 0xdea580d8, 0xda649d6f, 0xc423cd6a, 0xc0e2d0dd, 0xcda1f604, 0xc960ebb3,
|
||||
0xbd3e8d7e, 0xb9ff90c9, 0xb4bcb610, 0xb07daba7, 0xae3afba2, 0xaafbe615, 0xa7b8c0cc, 0xa379dd7b, 0x9b3660c6, 0x9ff77d71, 0x92b45ba8, 0x9675461f,
|
||||
0x8832161a, 0x8cf30bad, 0x81b02d74, 0x857130c3, 0x5d8a9099, 0x594b8d2e, 0x5408abf7, 0x50c9b640, 0x4e8ee645, 0x4a4ffbf2, 0x470cdd2b, 0x43cdc09c,
|
||||
0x7b827d21, 0x7f436096, 0x7200464f, 0x76c15bf8, 0x68860bfd, 0x6c47164a, 0x61043093, 0x65c52d24, 0x119b4be9, 0x155a565e, 0x18197087, 0x1cd86d30,
|
||||
0x029f3d35, 0x065e2082, 0x0b1d065b, 0x0fdc1bec, 0x3793a651, 0x3352bbe6, 0x3e119d3f, 0x3ad08088, 0x2497d08d, 0x2056cd3a, 0x2d15ebe3, 0x29d4f654,
|
||||
0xc5a92679, 0xc1683bce, 0xcc2b1d17, 0xc8ea00a0, 0xd6ad50a5, 0xd26c4d12, 0xdf2f6bcb, 0xdbee767c, 0xe3a1cbc1, 0xe760d676, 0xea23f0af, 0xeee2ed18,
|
||||
0xf0a5bd1d, 0xf464a0aa, 0xf9278673, 0xfde69bc4, 0x89b8fd09, 0x8d79e0be, 0x803ac667, 0x84fbdbd0, 0x9abc8bd5, 0x9e7d9662, 0x933eb0bb, 0x97ffad0c,
|
||||
0xafb010b1, 0xab710d06, 0xa6322bdf, 0xa2f33668, 0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4 };
|
||||
|
|
|
@ -3,14 +3,12 @@
|
|||
|
||||
#include "../conversion/binaryconversion.h"
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <istream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace IoUtilities
|
||||
{
|
||||
class CPP_UTILITIES_EXPORT BinaryReader
|
||||
{
|
||||
namespace IoUtilities {
|
||||
class CPP_UTILITIES_EXPORT BinaryReader {
|
||||
|
||||
public:
|
||||
BinaryReader(std::istream *stream);
|
||||
|
@ -559,7 +557,6 @@ inline float32 BinaryReader::readFixed16LE()
|
|||
{
|
||||
return ConversionUtilities::toFloat32(readUInt32LE());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // IOUTILITIES_BINERYREADER_H
|
||||
|
|
|
@ -19,19 +19,21 @@ using namespace ConversionUtilities;
|
|||
* \brief Constructs a new BinaryWriter.
|
||||
* \param stream Specifies the stream to write to.
|
||||
*/
|
||||
BinaryWriter::BinaryWriter(ostream *stream) :
|
||||
m_stream(stream),
|
||||
m_ownership(false)
|
||||
{}
|
||||
BinaryWriter::BinaryWriter(ostream *stream)
|
||||
: m_stream(stream)
|
||||
, m_ownership(false)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Copies the specified BinaryWriter.
|
||||
* \remarks The copy will not take ownership over the stream.
|
||||
*/
|
||||
BinaryWriter::BinaryWriter(const BinaryWriter &other) :
|
||||
m_stream(other.m_stream),
|
||||
m_ownership(false)
|
||||
{}
|
||||
BinaryWriter::BinaryWriter(const BinaryWriter &other)
|
||||
: m_stream(other.m_stream)
|
||||
, m_ownership(false)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Destroys the BinaryWriter.
|
||||
|
|
|
@ -1,18 +1,16 @@
|
|||
#ifndef IOUTILITIES_BINARYWRITER_H
|
||||
#define IOUTILITIES_BINARYWRITER_H
|
||||
|
||||
#include "../conversion/types.h"
|
||||
#include "../conversion/binaryconversion.h"
|
||||
#include "../conversion/types.h"
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace IoUtilities
|
||||
{
|
||||
namespace IoUtilities {
|
||||
|
||||
class CPP_UTILITIES_EXPORT BinaryWriter
|
||||
{
|
||||
class CPP_UTILITIES_EXPORT BinaryWriter {
|
||||
public:
|
||||
BinaryWriter(std::ostream *stream);
|
||||
BinaryWriter(const BinaryWriter &other);
|
||||
|
@ -527,7 +525,6 @@ inline void BinaryWriter::writeFixed16LE(float32 valueToConvertAndWrite)
|
|||
{
|
||||
writeUInt32LE(ConversionUtilities::toFixed16(valueToConvertAndWrite));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // IO_UTILITIES_BINARYWRITER_H
|
||||
|
|
|
@ -29,4 +29,3 @@ void BitReader::skipBits(std::size_t bitCount)
|
|||
}
|
||||
|
||||
} // namespace IoUtilities
|
||||
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
#define IOUTILITIES_BITREADER_H
|
||||
|
||||
#include "../conversion/types.h"
|
||||
#include "../io/catchiofailure.h"
|
||||
#include "../global.h"
|
||||
#include "../io/catchiofailure.h"
|
||||
|
||||
#include <ios>
|
||||
#include <iostream>
|
||||
|
@ -11,8 +11,7 @@
|
|||
|
||||
namespace IoUtilities {
|
||||
|
||||
class CPP_UTILITIES_EXPORT BitReader
|
||||
{
|
||||
class CPP_UTILITIES_EXPORT BitReader {
|
||||
public:
|
||||
BitReader(const char *buffer, std::size_t bufferSize);
|
||||
BitReader(const char *buffer, const char *end);
|
||||
|
@ -40,9 +39,10 @@ private:
|
|||
* - Does not take ownership over the specified \a buffer.
|
||||
* - bufferSize must be equal or greather than 1.
|
||||
*/
|
||||
inline BitReader::BitReader(const char *buffer, std::size_t bufferSize) :
|
||||
BitReader(buffer, buffer + bufferSize)
|
||||
{}
|
||||
inline BitReader::BitReader(const char *buffer, std::size_t bufferSize)
|
||||
: BitReader(buffer, buffer + bufferSize)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a new BitReader.
|
||||
|
@ -50,11 +50,12 @@ inline BitReader::BitReader(const char *buffer, std::size_t bufferSize) :
|
|||
* - Does not take ownership over the specified \a buffer.
|
||||
* - \a end must be greather than \a buffer.
|
||||
*/
|
||||
inline BitReader::BitReader(const char *buffer, const char *end) :
|
||||
m_buffer(reinterpret_cast<const byte *>(buffer)),
|
||||
m_end(reinterpret_cast<const byte *>(end)),
|
||||
m_bitsAvail(8)
|
||||
{}
|
||||
inline BitReader::BitReader(const char *buffer, const char *end)
|
||||
: m_buffer(reinterpret_cast<const byte *>(buffer))
|
||||
, m_end(reinterpret_cast<const byte *>(end))
|
||||
, m_bitsAvail(8)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Reads the specified number of bits from the buffer advancing the current position by \a bitCount bits.
|
||||
|
@ -64,8 +65,7 @@ inline BitReader::BitReader(const char *buffer, const char *end) :
|
|||
* \throws Throws ios_base::failure if the end of the buffer is exceeded.
|
||||
* The reader becomes invalid in that case.
|
||||
*/
|
||||
template<typename intType>
|
||||
intType BitReader::readBits(byte bitCount)
|
||||
template <typename intType> intType BitReader::readBits(byte bitCount)
|
||||
{
|
||||
intType val = 0;
|
||||
for (byte readAtOnce; bitCount; bitCount -= readAtOnce) {
|
||||
|
@ -99,8 +99,7 @@ inline byte BitReader::readBit()
|
|||
* The reader becomes invalid in that case.
|
||||
* \sa https://en.wikipedia.org/wiki/Exponential-Golomb_coding
|
||||
*/
|
||||
template<typename intType>
|
||||
intType BitReader::readUnsignedExpGolombCodedBits()
|
||||
template <typename intType> intType BitReader::readUnsignedExpGolombCodedBits()
|
||||
{
|
||||
byte count = 0;
|
||||
while (!readBit()) {
|
||||
|
@ -117,8 +116,7 @@ intType BitReader::readUnsignedExpGolombCodedBits()
|
|||
* The reader becomes invalid in that case.
|
||||
* \sa https://en.wikipedia.org/wiki/Exponential-Golomb_coding
|
||||
*/
|
||||
template<typename intType>
|
||||
intType BitReader::readSignedExpGolombCodedBits()
|
||||
template <typename intType> intType BitReader::readSignedExpGolombCodedBits()
|
||||
{
|
||||
auto value = readUnsignedExpGolombCodedBits<typename std::make_unsigned<intType>::type>();
|
||||
return (value % 2) ? static_cast<intType>((value + 1) / 2) : (-static_cast<intType>(value / 2));
|
||||
|
@ -127,8 +125,7 @@ intType BitReader::readSignedExpGolombCodedBits()
|
|||
/*!
|
||||
* \brief Reads the specified number of bits from the buffer without advancing the current position.
|
||||
*/
|
||||
template<typename intType>
|
||||
intType BitReader::showBits(byte bitCount)
|
||||
template <typename intType> intType BitReader::showBits(byte bitCount)
|
||||
{
|
||||
auto tmp = *this;
|
||||
return tmp.readBits<intType>(bitCount);
|
||||
|
|
|
@ -31,6 +31,4 @@ void throwIoFailure(const char *what)
|
|||
{
|
||||
throw ios_base::failure(what);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,6 @@ namespace IoUtilities {
|
|||
|
||||
CPP_UTILITIES_EXPORT const char *catchIoFailure();
|
||||
CPP_UTILITIES_EXPORT void throwIoFailure(const char *what);
|
||||
|
||||
}
|
||||
|
||||
#endif // IOUTILITIES_CATCHIOFAILURE_H
|
||||
|
|
27
io/copy.h
27
io/copy.h
|
@ -3,8 +3,8 @@
|
|||
|
||||
#include "../global.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
|
||||
namespace IoUtilities {
|
||||
|
||||
|
@ -13,14 +13,14 @@ namespace IoUtilities {
|
|||
* \brief The CopyHelper class helps to copy bytes from one stream to another.
|
||||
* \tparam Specifies the buffer size.
|
||||
*/
|
||||
template<std::size_t bufferSize>
|
||||
class CPP_UTILITIES_EXPORT CopyHelper
|
||||
{
|
||||
template <std::size_t bufferSize> class CPP_UTILITIES_EXPORT CopyHelper {
|
||||
public:
|
||||
CopyHelper();
|
||||
void copy(std::istream &input, std::ostream &output, std::size_t count);
|
||||
void callbackCopy(std::istream &input, std::ostream &output, std::size_t count, const std::function<bool (void)> &isAborted, const std::function<void (double)> &callback);
|
||||
void callbackCopy(std::istream &input, std::ostream &output, std::size_t count, const std::function<bool(void)> &isAborted,
|
||||
const std::function<void(double)> &callback);
|
||||
char *buffer();
|
||||
|
||||
private:
|
||||
char m_buffer[bufferSize];
|
||||
};
|
||||
|
@ -28,17 +28,16 @@ private:
|
|||
/*!
|
||||
* \brief Constructs a new copy helper.
|
||||
*/
|
||||
template<std::size_t bufferSize>
|
||||
CopyHelper<bufferSize>::CopyHelper()
|
||||
{}
|
||||
template <std::size_t bufferSize> CopyHelper<bufferSize>::CopyHelper()
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Copies \a count bytes from \a input to \a output.
|
||||
* \remarks Set an exception mask using std::ios::exceptions() to get a std::ios_base::failure exception
|
||||
* when an IO error occurs.
|
||||
*/
|
||||
template<std::size_t bufferSize>
|
||||
void CopyHelper<bufferSize>::copy(std::istream &input, std::ostream &output, std::size_t count)
|
||||
template <std::size_t bufferSize> void CopyHelper<bufferSize>::copy(std::istream &input, std::ostream &output, std::size_t count)
|
||||
{
|
||||
while (count > bufferSize) {
|
||||
input.read(m_buffer, bufferSize);
|
||||
|
@ -49,7 +48,6 @@ void CopyHelper<bufferSize>::copy(std::istream &input, std::ostream &output, std
|
|||
output.write(m_buffer, count);
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
* \brief Copies \a count bytes from \a input to \a output. The procedure might be aborted and
|
||||
* progress updates will be reported.
|
||||
|
@ -61,7 +59,8 @@ void CopyHelper<bufferSize>::copy(std::istream &input, std::ostream &output, std
|
|||
* when an IO error occurs.
|
||||
*/
|
||||
template <std::size_t bufferSize>
|
||||
void CopyHelper<bufferSize>::callbackCopy(std::istream &input, std::ostream &output, std::size_t count, const std::function<bool (void)> &isAborted, const std::function<void (double)> &callback)
|
||||
void CopyHelper<bufferSize>::callbackCopy(std::istream &input, std::ostream &output, std::size_t count, const std::function<bool(void)> &isAborted,
|
||||
const std::function<void(double)> &callback)
|
||||
{
|
||||
const std::size_t totalBytes = count;
|
||||
while (count > bufferSize) {
|
||||
|
@ -81,12 +80,10 @@ void CopyHelper<bufferSize>::callbackCopy(std::istream &input, std::ostream &out
|
|||
/*!
|
||||
* \brief Returns the internal buffer.
|
||||
*/
|
||||
template<std::size_t bufferSize>
|
||||
char *CopyHelper<bufferSize>::buffer()
|
||||
template <std::size_t bufferSize> char *CopyHelper<bufferSize>::buffer()
|
||||
{
|
||||
return m_buffer;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // IOUTILITIES_COPY_H
|
||||
|
|
|
@ -107,8 +107,7 @@ void IniFile::parse(std::istream &inputStream)
|
|||
case '\n':
|
||||
state = Init;
|
||||
break;
|
||||
default:
|
||||
;
|
||||
default:;
|
||||
}
|
||||
break;
|
||||
case ScopeName:
|
||||
|
@ -165,4 +164,3 @@ void IniFile::make(ostream &outputStream)
|
|||
}
|
||||
|
||||
} // namespace IoUtilities
|
||||
|
||||
|
|
|
@ -3,14 +3,13 @@
|
|||
|
||||
#include "../global.h"
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace IoUtilities {
|
||||
|
||||
class CPP_UTILITIES_EXPORT IniFile
|
||||
{
|
||||
class CPP_UTILITIES_EXPORT IniFile {
|
||||
public:
|
||||
IniFile();
|
||||
|
||||
|
@ -27,7 +26,8 @@ private:
|
|||
* \brief Constructs an empty ini file.
|
||||
*/
|
||||
inline IniFile::IniFile()
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Returns the data of the file.
|
||||
|
|
|
@ -29,5 +29,4 @@ string readFile(const string &path, std::string::size_type maxSize)
|
|||
res.assign((istreambuf_iterator<char>(file)), istreambuf_iterator<char>());
|
||||
return res;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
namespace IoUtilities {
|
||||
|
||||
CPP_UTILITIES_EXPORT std::string readFile(const std::string &path, std::string::size_type maxSize = std::string::npos);
|
||||
|
||||
}
|
||||
|
||||
#endif // IOUTILITIES_MISC_H
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
|
||||
#ifdef PLATFORM_MINGW
|
||||
#include "catchiofailure.h"
|
||||
# include <windows.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
|
@ -17,14 +17,15 @@ namespace IoUtilities {
|
|||
|
||||
#else
|
||||
|
||||
NativeFileStream::NativeFileStream() :
|
||||
m_filebuf(new __gnu_cxx::stdio_filebuf<char>)
|
||||
NativeFileStream::NativeFileStream()
|
||||
: m_filebuf(new __gnu_cxx::stdio_filebuf<char>)
|
||||
{
|
||||
rdbuf(m_filebuf.get());
|
||||
}
|
||||
|
||||
NativeFileStream::~NativeFileStream()
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
void NativeFileStream::open(const string &path, ios_base::openmode flags)
|
||||
{
|
||||
|
@ -69,5 +70,4 @@ void NativeFileStream::close()
|
|||
}
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
|
|
@ -6,10 +6,10 @@
|
|||
#ifndef PLATFORM_MINGW
|
||||
#include <fstream>
|
||||
#else
|
||||
#include <ext/stdio_filebuf.h>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
# include <iostream>
|
||||
# include <ext/stdio_filebuf.h>
|
||||
#endif
|
||||
|
||||
namespace IoUtilities {
|
||||
|
@ -20,8 +20,7 @@ typedef std::fstream NativeFileStream;
|
|||
|
||||
#else
|
||||
|
||||
class CPP_UTILITIES_EXPORT NativeFileStream : public std::iostream
|
||||
{
|
||||
class CPP_UTILITIES_EXPORT NativeFileStream : public std::iostream {
|
||||
public:
|
||||
NativeFileStream();
|
||||
~NativeFileStream();
|
||||
|
@ -41,8 +40,6 @@ inline bool NativeFileStream::is_open() const
|
|||
}
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
#endif // IOUTILITIES_NATIVE_FILE_STREAM
|
||||
|
||||
|
|
15
io/path.cpp
15
io/path.cpp
|
@ -1,15 +1,15 @@
|
|||
#include "./path.h"
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <cstdlib>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#if defined(PLATFORM_UNIX)
|
||||
# include <unistd.h>
|
||||
# include <sys/types.h>
|
||||
# include <sys/stat.h>
|
||||
# include <pwd.h>
|
||||
#include <dirent.h>
|
||||
#include <pwd.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#elif defined(PLATFORM_WINDOWS)
|
||||
#ifdef UNICODE
|
||||
#undef UNICODE
|
||||
|
@ -209,5 +209,4 @@ std::list<std::string> directoryEntries(const char *path, DirectoryEntryType typ
|
|||
return list<string>(); // TODO
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
|
15
io/path.h
15
io/path.h
|
@ -3,8 +3,8 @@
|
|||
|
||||
#include "../global.h"
|
||||
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include <string>
|
||||
|
||||
#ifdef PLATFORM_WINDOWS
|
||||
#define PATH_SEP_CHAR '\\'
|
||||
|
@ -23,14 +23,7 @@ namespace IoUtilities {
|
|||
/*!
|
||||
* \brief The DirectoryEntryType enum specifies the type of a directory entry (file, directory or symlink).
|
||||
*/
|
||||
enum class DirectoryEntryType : unsigned char
|
||||
{
|
||||
None = 0,
|
||||
File = 1,
|
||||
Directory = 2,
|
||||
Symlink = 4,
|
||||
All = 0xFF
|
||||
};
|
||||
enum class DirectoryEntryType : unsigned char { None = 0, File = 1, Directory = 2, Symlink = 4, All = 0xFF };
|
||||
|
||||
constexpr DirectoryEntryType operator|(DirectoryEntryType lhs, DirectoryEntryType rhs)
|
||||
{
|
||||
|
@ -50,9 +43,9 @@ constexpr DirectoryEntryType operator&(DirectoryEntryType lhs, DirectoryEntryTyp
|
|||
CPP_UTILITIES_EXPORT std::string fileName(const std::string &path);
|
||||
CPP_UTILITIES_EXPORT std::string directory(const std::string &path);
|
||||
CPP_UTILITIES_EXPORT void removeInvalidChars(std::string &fileName);
|
||||
CPP_UTILITIES_EXPORT bool settingsDirectory(std::string &result, std::string applicationDirectoryName = std::string(), bool createApplicationDirectory = false);
|
||||
CPP_UTILITIES_EXPORT bool settingsDirectory(
|
||||
std::string &result, std::string applicationDirectoryName = std::string(), bool createApplicationDirectory = false);
|
||||
CPP_UTILITIES_EXPORT std::list<std::string> directoryEntries(const char *path, DirectoryEntryType types = DirectoryEntryType::All);
|
||||
|
||||
}
|
||||
|
||||
#endif // IOUTILITIES_PATHHELPER_H
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include "./math.h"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
#include <cstdlib>
|
||||
|
||||
/*!
|
||||
* \namespace MathUtilities
|
||||
|
@ -84,6 +84,7 @@ int64 inverseModulo(int64 number, int64 module)
|
|||
uint64 orderModulo(const uint64 number, const uint64 module)
|
||||
{
|
||||
uint64 order = 1;
|
||||
for(; powerModulo(number, order, module) != 1; ++order);
|
||||
for (; powerModulo(number, order, module) != 1; ++order)
|
||||
;
|
||||
return order;
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#ifndef MATHUTILITIES_H
|
||||
#define MATHUTILITIES_H
|
||||
|
||||
#include "../global.h"
|
||||
#include "../conversion/types.h"
|
||||
#include "../global.h"
|
||||
|
||||
namespace MathUtilities {
|
||||
|
||||
|
@ -12,7 +12,6 @@ CPP_UTILITIES_EXPORT int factorial(int number);
|
|||
CPP_UTILITIES_EXPORT uint64 powerModulo(uint64 base, uint64 expontent, uint64 module);
|
||||
CPP_UTILITIES_EXPORT int64 inverseModulo(int64 number, int64 module);
|
||||
CPP_UTILITIES_EXPORT uint64 orderModulo(uint64 number, uint64 module);
|
||||
|
||||
}
|
||||
|
||||
#endif // MATHUTILITIES_H
|
||||
|
|
|
@ -8,38 +8,36 @@
|
|||
#if __cplusplus <= 201103L
|
||||
#define __cpp_lib_make_unique 201304
|
||||
namespace std {
|
||||
template<typename _Tp>
|
||||
struct _MakeUniq
|
||||
{ typedef unique_ptr<_Tp> __single_object; };
|
||||
template <typename _Tp> struct _MakeUniq {
|
||||
typedef unique_ptr<_Tp> __single_object;
|
||||
};
|
||||
|
||||
template<typename _Tp>
|
||||
struct _MakeUniq<_Tp[]>
|
||||
{ typedef unique_ptr<_Tp[]> __array; };
|
||||
template <typename _Tp> struct _MakeUniq<_Tp[]> {
|
||||
typedef unique_ptr<_Tp[]> __array;
|
||||
};
|
||||
|
||||
template<typename _Tp, size_t _Bound>
|
||||
struct _MakeUniq<_Tp[_Bound]>
|
||||
{ struct __invalid_type { }; };
|
||||
template <typename _Tp, size_t _Bound> struct _MakeUniq<_Tp[_Bound]> {
|
||||
struct __invalid_type {
|
||||
};
|
||||
};
|
||||
|
||||
/// std::make_unique for single objects
|
||||
template<typename _Tp, typename... _Args>
|
||||
inline typename _MakeUniq<_Tp>::__single_object
|
||||
make_unique(_Args&&... __args)
|
||||
{ return unique_ptr<_Tp>(new _Tp(std::forward<_Args>(__args)...)); }
|
||||
template <typename _Tp, typename... _Args> inline typename _MakeUniq<_Tp>::__single_object make_unique(_Args &&... __args)
|
||||
{
|
||||
return unique_ptr<_Tp>(new _Tp(std::forward<_Args>(__args)...));
|
||||
}
|
||||
|
||||
/// std::make_unique for arrays of unknown bound
|
||||
template<typename _Tp>
|
||||
inline typename _MakeUniq<_Tp>::__array
|
||||
make_unique(size_t __num)
|
||||
{ return unique_ptr<_Tp>(new typename remove_extent<_Tp>::type[__num]()); }
|
||||
template <typename _Tp> inline typename _MakeUniq<_Tp>::__array make_unique(size_t __num)
|
||||
{
|
||||
return unique_ptr<_Tp>(new typename remove_extent<_Tp>::type[__num]());
|
||||
}
|
||||
|
||||
/// Disable std::make_unique for arrays of known bound
|
||||
template<typename _Tp, typename... _Args>
|
||||
inline typename _MakeUniq<_Tp>::__invalid_type
|
||||
make_unique(_Args&&...) = delete;
|
||||
template <typename _Tp, typename... _Args> inline typename _MakeUniq<_Tp>::__invalid_type make_unique(_Args &&...) = delete;
|
||||
}
|
||||
#endif
|
||||
|
||||
/// \endcond
|
||||
|
||||
#endif // MEMORY_H
|
||||
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
#include "./random.h"
|
||||
|
||||
#include <iomanip>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
@ -28,7 +28,8 @@ const char symbols[24] = "!\"$%&/()=?'#*+~-_><.:,;";
|
|||
* \brief Generates a random character sequence using the given \a randomizer.
|
||||
* \deprecated Might be removed in future release because API is bad and it is not used anymore anyways.
|
||||
*/
|
||||
void generateRandomCharacterSequence(char *result, unsigned int length, std::function<int ()> randomizer, int highestRandomNumber, bool useSmallLetters, bool useCapitalLetters, bool useNumbers, bool useSymbols, bool useAtLeastOneOfEachCategory)
|
||||
void generateRandomCharacterSequence(char *result, unsigned int length, std::function<int()> randomizer, int highestRandomNumber,
|
||||
bool useSmallLetters, bool useCapitalLetters, bool useNumbers, bool useSymbols, bool useAtLeastOneOfEachCategory)
|
||||
{
|
||||
if (length) {
|
||||
return;
|
||||
|
@ -117,10 +118,10 @@ void generateRandomCharacterSequence(char *result, unsigned int length, std::fun
|
|||
* \brief Generates a random character sequence using std::rand().
|
||||
* \deprecated Might be removed in future release because API is bad and it is not used anymore anyways.
|
||||
*/
|
||||
void generateRandomCharacterSequence(char *result, unsigned int length, bool useSmallLetters, bool useCapitalLetters, bool useNumbers, bool useSymbols, bool useAtLeastOneOfEachCategory)
|
||||
void generateRandomCharacterSequence(char *result, unsigned int length, bool useSmallLetters, bool useCapitalLetters, bool useNumbers,
|
||||
bool useSymbols, bool useAtLeastOneOfEachCategory)
|
||||
{
|
||||
generateRandomCharacterSequence(result, length, rand, RAND_MAX, useSmallLetters, useCapitalLetters, useNumbers, useSymbols, useAtLeastOneOfEachCategory);
|
||||
generateRandomCharacterSequence(
|
||||
result, length, rand, RAND_MAX, useSmallLetters, useCapitalLetters, useNumbers, useSymbols, useAtLeastOneOfEachCategory);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -7,9 +7,11 @@
|
|||
|
||||
namespace RandomUtilities {
|
||||
|
||||
CPP_UTILITIES_EXPORT void generateRandomCharacterSequence(char *result, unsigned int length, bool useSmallLetters = true, bool useCapitalLetters = true, bool useNumbers = true, bool useSymbols = true, bool useAtLeastOneOfEachCategory = true);
|
||||
CPP_UTILITIES_EXPORT void generateRandomCharacterSequence(char *result, unsigned int length, std::function<int ()> randomizer, int maximalRandomNumber, bool useSmallLetters = true, bool useCapitalLetters = true, bool useNumbers = true, bool useSymbols = true, bool useAtLeastOneOfEachCategory = true);
|
||||
|
||||
CPP_UTILITIES_EXPORT void generateRandomCharacterSequence(char *result, unsigned int length, bool useSmallLetters = true,
|
||||
bool useCapitalLetters = true, bool useNumbers = true, bool useSymbols = true, bool useAtLeastOneOfEachCategory = true);
|
||||
CPP_UTILITIES_EXPORT void generateRandomCharacterSequence(char *result, unsigned int length, std::function<int()> randomizer, int maximalRandomNumber,
|
||||
bool useSmallLetters = true, bool useCapitalLetters = true, bool useNumbers = true, bool useSymbols = true,
|
||||
bool useAtLeastOneOfEachCategory = true);
|
||||
}
|
||||
|
||||
#endif // RANDOMUTILS_H
|
||||
|
|
|
@ -12,41 +12,33 @@ namespace Detail {
|
|||
}
|
||||
/// \endcond
|
||||
|
||||
template <typename If, typename Then, typename Else>
|
||||
using Conditional = typename std::conditional<If::value, Then, Else>::type;
|
||||
template <typename If, typename Then, typename Else> using Conditional = typename std::conditional<If::value, Then, Else>::type;
|
||||
|
||||
template <bool B, typename...>
|
||||
struct Bool : std::integral_constant<bool, B> {};
|
||||
template <bool B, typename...> struct Bool : std::integral_constant<bool, B> {
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
using Not = Bool<!T::value>;
|
||||
template <typename T> using Not = Bool<!T::value>;
|
||||
|
||||
template <typename... T>
|
||||
struct Any : Bool<false> {};
|
||||
template <typename Head, typename... Tail>
|
||||
struct Any<Head, Tail...> : Conditional<Head, Bool<true>, Any<Tail...> > {};
|
||||
template <typename... T> struct Any : Bool<false> {
|
||||
};
|
||||
template <typename Head, typename... Tail> struct Any<Head, Tail...> : Conditional<Head, Bool<true>, Any<Tail...> > {
|
||||
};
|
||||
|
||||
template <typename... T>
|
||||
struct All : Bool<true> {};
|
||||
template <typename Head, typename... Tail>
|
||||
struct All<Head, Tail...> : Conditional<Head, All<Tail...>, Bool<false> > {};
|
||||
template <typename... T> struct All : Bool<true> {
|
||||
};
|
||||
template <typename Head, typename... Tail> struct All<Head, Tail...> : Conditional<Head, All<Tail...>, Bool<false> > {
|
||||
};
|
||||
|
||||
template <typename... Condition>
|
||||
using EnableIf = typename std::enable_if<All<Condition...>::value, Detail::Enabler>::type;
|
||||
template <typename... Condition>
|
||||
using DisableIf = typename std::enable_if<!All<Condition...>::value, Detail::Enabler>::type;
|
||||
template <typename... Condition> using EnableIf = typename std::enable_if<All<Condition...>::value, Detail::Enabler>::type;
|
||||
template <typename... Condition> using DisableIf = typename std::enable_if<!All<Condition...>::value, Detail::Enabler>::type;
|
||||
|
||||
template <typename... Condition>
|
||||
using EnableIfAny = typename std::enable_if<Any<Condition...>::value, Detail::Enabler>::type;
|
||||
template <typename... Condition>
|
||||
using DisableIfAny = typename std::enable_if<!Any<Condition...>::value, Detail::Enabler>::type;
|
||||
|
||||
template <typename T, template <typename...> class Template>
|
||||
struct IsSpecializationOf : Bool<false> {};
|
||||
template <template <typename...> class Template, typename... Args>
|
||||
struct IsSpecializationOf<Template<Args...>, Template> : Bool<true> {};
|
||||
template <typename... Condition> using EnableIfAny = typename std::enable_if<Any<Condition...>::value, Detail::Enabler>::type;
|
||||
template <typename... Condition> using DisableIfAny = typename std::enable_if<!Any<Condition...>::value, Detail::Enabler>::type;
|
||||
|
||||
template <typename T, template <typename...> class Template> struct IsSpecializationOf : Bool<false> {
|
||||
};
|
||||
template <template <typename...> class Template, typename... Args> struct IsSpecializationOf<Template<Args...>, Template> : Bool<true> {
|
||||
};
|
||||
}
|
||||
|
||||
#endif // CPP_UTILITIES_TRAITS_H
|
||||
|
||||
|
|
|
@ -3,9 +3,9 @@
|
|||
|
||||
#include "./testutils.h"
|
||||
|
||||
#include <cppunit/TestPath.h>
|
||||
#include <cppunit/extensions/TestFactoryRegistry.h>
|
||||
#include <cppunit/ui/text/TestRunner.h>
|
||||
#include <cppunit/TestPath.h>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
|
|
|
@ -6,15 +6,15 @@
|
|||
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <initializer_list>
|
||||
#include <iostream>
|
||||
|
||||
#ifdef PLATFORM_UNIX
|
||||
# include <unistd.h>
|
||||
#include <poll.h>
|
||||
# include <sys/wait.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
|
@ -39,12 +39,12 @@ TestApplication *TestApplication::m_instance = nullptr;
|
|||
* \brief Constructs a TestApplication instance.
|
||||
* \throws Throws std::runtime_error if an instance has already been created.
|
||||
*/
|
||||
TestApplication::TestApplication(int argc, char **argv) :
|
||||
m_helpArg(m_parser),
|
||||
m_testFilesPathArg("test-files-path", 'p', "specifies the path of the directory with test files"),
|
||||
m_applicationPathArg("app-path",'a', "specifies the path of the application to be tested"),
|
||||
m_workingDirArg("working-dir", 'w', "specifies the directory to store working copies of test files"),
|
||||
m_unitsArg("units", 'u', "specifies the units to test; omit to test all units")
|
||||
TestApplication::TestApplication(int argc, char **argv)
|
||||
: m_helpArg(m_parser)
|
||||
, m_testFilesPathArg("test-files-path", 'p', "specifies the path of the directory with test files")
|
||||
, m_applicationPathArg("app-path", 'a', "specifies the path of the application to be tested")
|
||||
, m_workingDirArg("working-dir", 'w', "specifies the directory to store working copies of test files")
|
||||
, m_unitsArg("units", 'u', "specifies the units to test; omit to test all units")
|
||||
{
|
||||
// check whether there is already an instance
|
||||
if (m_instance) {
|
||||
|
@ -327,5 +327,4 @@ int TestApplication::execApp(const char *const *args, string &stdout, string &st
|
|||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
|
|
@ -3,22 +3,20 @@
|
|||
|
||||
#include "../application/argumentparser.h"
|
||||
|
||||
#include <string>
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
|
||||
namespace TestUtilities {
|
||||
|
||||
/*!
|
||||
* \brief The WorkingCopyMode enum specifies additional options to influence behavior of TestApplication::workingCopyPathMode().
|
||||
*/
|
||||
enum class WorkingCopyMode
|
||||
{
|
||||
enum class WorkingCopyMode {
|
||||
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 */
|
||||
};
|
||||
|
||||
class CPP_UTILITIES_EXPORT TestApplication
|
||||
{
|
||||
class CPP_UTILITIES_EXPORT TestApplication {
|
||||
public:
|
||||
TestApplication(int argc, char **argv);
|
||||
~TestApplication();
|
||||
|
@ -130,11 +128,13 @@ inline CPP_UTILITIES_EXPORT int execApp(const char *const *args, std::string &ou
|
|||
* \brief The AsHexNumber class allows printing values asserted with cppunit (or similar test framework) using the
|
||||
* hex system in the error case.
|
||||
*/
|
||||
template <typename T> class AsHexNumber
|
||||
{
|
||||
template <typename T> class AsHexNumber {
|
||||
public:
|
||||
/// \brief Constructs a new instance; use asHexNumber() for convenience instead.
|
||||
AsHexNumber(const T &value) : value(value) {}
|
||||
AsHexNumber(const T &value)
|
||||
: value(value)
|
||||
{
|
||||
}
|
||||
const T &value;
|
||||
};
|
||||
|
||||
|
@ -168,10 +168,8 @@ template <typename T> AsHexNumber<T> asHexNumber(const T &value)
|
|||
* \brief Asserts successful execution of application via TestApplication::execApp(). Output is stored in stdout and stderr.
|
||||
* \remarks Requires cppunit.
|
||||
*/
|
||||
# define TESTUTILS_ASSERT_EXEC(args) \
|
||||
CPPUNIT_ASSERT_EQUAL(0, execApp(args, stdout, stderr))
|
||||
#define TESTUTILS_ASSERT_EXEC(args) CPPUNIT_ASSERT_EQUAL(0, execApp(args, stdout, stderr))
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
#endif // TESTUTILS_H
|
||||
|
|
Loading…
Reference in New Issue