C++ Utilities  4.6.1
Common C++ classes and routines used by my applications such as argument parser, IO and conversion utilities
commandlineutils.h
Go to the documentation of this file.
1 #ifndef APPLICATIONUTILITIES_COMMANDLINEUTILS_H
2 #define APPLICATIONUTILITIES_COMMANDLINEUTILS_H
3 
4 #include "../global.h"
5 
6 #include <ostream>
7 
8 #ifdef PLATFORM_WINDOWS
9 # include <memory>
10 # include <vector>
11 #endif
12 
13 namespace ApplicationUtilities {
14 
18 enum class Response
19 {
20  None,
21  Yes,
22  No
23 };
24 
25 bool CPP_UTILITIES_EXPORT confirmPrompt(const char *message, Response defaultResponse = Response::None);
26 
27 #ifdef PLATFORM_WINDOWS
28 void CPP_UTILITIES_EXPORT startConsole();
29 std::pair<std::vector<std::unique_ptr<char[]> >, std::vector<char *> > CPP_UTILITIES_EXPORT convertArgsToUtf8();
30 # define CMD_UTILS_START_CONSOLE \
31  ::ApplicationUtilities::startConsole();
32 # define CMD_UTILS_CONVERT_ARGS_TO_UTF8 \
33  auto utf8Args = ::ApplicationUtilities::convertArgsToUtf8(); \
34  argv = utf8Args.second.data(); \
35  argc = static_cast<int>(utf8Args.second.size());
36 #else
37 # define CMD_UTILS_START_CONSOLE
38 # define CMD_UTILS_CONVERT_ARGS_TO_UTF8
39 #endif
40 
45 {
46 public:
47  Indentation(unsigned char level = 4, char character = ' ') :
48  level(level),
49  character(character)
50  {}
51 
52  Indentation operator +(unsigned char level)
53  {
54  return Indentation(this->level + level, character);
55  }
56 
57  unsigned char level;
58  char character;
59 };
60 
61 inline CPP_UTILITIES_EXPORT std::ostream &operator<< (std::ostream &out, Indentation indentation)
62 {
63  for(unsigned char i = 0; i < indentation.level; ++i) {
64  out << indentation.character;
65  }
66  return out;
67 }
68 
69 } // namespace ApplicationUtilities
70 
71 #endif // APPLICATIONUTILITIES_COMMANDLINEUTILS_H
Contains currently only ArgumentParser and related classes.
The Indentation class allows printing indentation conveniently, eg.
bool CPP_UTILITIES_EXPORT confirmPrompt(const char *message, Response defaultResponse=Response::None)
Prompts for confirmation displaying the specified message.
Response
The Response enum is used to specify the default response for the confirmPrompt() method...
std::string operator+(const Tuple &lhs, const std::string &rhs)
Allows construction of final string from previously constructed string-tuple and trailing string via ...
#define CPP_UTILITIES_EXPORT
Marks the symbol to be exported by the c++utilities library.
Indentation(unsigned char level=4, char character=' ')
CPP_UTILITIES_EXPORT std::ostream & operator<<(std::ostream &out, Indentation indentation)