cpp-utilities/application/commandlineutils.h

66 lines
2.1 KiB
C
Raw Normal View History

2015-06-24 00:44:16 +02:00
#ifndef APPLICATIONUTILITIES_COMMANDLINEUTILS_H
#define APPLICATIONUTILITIES_COMMANDLINEUTILS_H
#include "../global.h"
2015-06-24 00:44:16 +02:00
#include <ostream>
2016-12-18 17:19:57 +01:00
#ifdef PLATFORM_WINDOWS
2017-05-01 03:13:11 +02:00
#include <memory>
#include <vector>
2016-12-18 17:19:57 +01:00
#endif
2015-06-24 00:44:16 +02:00
namespace ApplicationUtilities {
2016-07-02 02:02:47 +02:00
/*!
* \brief The Response enum is used to specify the default response for the confirmPrompt() method.
*/
2017-05-01 03:13:11 +02:00
enum class Response { None, Yes, No };
2015-06-24 00:44:16 +02:00
bool CPP_UTILITIES_EXPORT confirmPrompt(const char *message, Response defaultResponse = Response::None);
2015-06-24 00:44:16 +02:00
#ifdef PLATFORM_WINDOWS
void CPP_UTILITIES_EXPORT startConsole();
2017-05-04 22:44:00 +02:00
std::pair<std::vector<std::unique_ptr<char[]>>, std::vector<char *>> CPP_UTILITIES_EXPORT convertArgsToUtf8();
2017-05-01 03:13:11 +02:00
#define CMD_UTILS_START_CONSOLE ::ApplicationUtilities::startConsole();
#define CMD_UTILS_CONVERT_ARGS_TO_UTF8 \
auto utf8Args = ::ApplicationUtilities::convertArgsToUtf8(); \
argv = utf8Args.second.data(); \
2016-12-18 17:19:57 +01:00
argc = static_cast<int>(utf8Args.second.size());
#else
2017-05-01 03:13:11 +02:00
#define CMD_UTILS_START_CONSOLE
#define CMD_UTILS_CONVERT_ARGS_TO_UTF8
#endif
/*!
2016-12-18 17:19:57 +01:00
* \brief The Indentation class allows printing indentation conveniently, eg. cout << Indentation(4) << ...
*/
2017-05-01 03:13:11 +02:00
class CPP_UTILITIES_EXPORT Indentation {
public:
2017-05-01 03:13:11 +02:00
Indentation(unsigned char level = 4, char character = ' ')
: level(level)
, character(character)
{
}
2017-05-01 03:13:11 +02:00
Indentation operator+(unsigned char level)
{
return Indentation(this->level + level, character);
}
unsigned char level;
char character;
};
2017-05-01 03:13:11 +02:00
inline CPP_UTILITIES_EXPORT std::ostream &operator<<(std::ostream &out, Indentation indentation)
{
2017-05-01 03:13:11 +02:00
for (unsigned char i = 0; i < indentation.level; ++i) {
out << indentation.character;
}
return out;
}
2015-06-24 00:44:16 +02:00
} // namespace ApplicationUtilities
#endif // APPLICATIONUTILITIES_COMMANDLINEUTILS_H