Torc  0.1
torccommandline.h
Go to the documentation of this file.
1 #ifndef TORCCOMMANDLINE_H
2 #define TORCCOMMANDLINE_H
3 
4 // Qt
5 #include <QObject>
6 #include <QVariant>
7 #include <QHash>
8 
9 // Torc
10 #include "torclogging.h"
11 
12 class TorcArgument;
13 
15 {
16  Q_GADGET
17  Q_FLAGS(Options)
18 
19  public:
20  enum Option
21  {
22  None = (0 << 0),
23  Help = (1 << 0),
24  Version = (1 << 1),
25  LogLevel = (1 << 2),
26  LogType = (1 << 3),
27  Database = (1 << 4),
28  LogFile = (1 << 5),
29  XSDTest = (1 << 6),
30  ConfDir = (1 << 7),
31  ShareDir = (1 << 8),
32  TransDir = (1 << 9)
33  };
34 
35  Q_DECLARE_FLAGS(Options, Option)
36 
37  public:
38  explicit TorcCommandLine(TorcCommandLine::Options Flags);
39  ~TorcCommandLine() = default;
40 
41  static bool RegisterEnvironmentVariable (const QString &Var, const QString &Description);
42 
43  int Evaluate (int argc, const char * const * argv, bool &Exit);
44  void Add (const QString &Keys, const QVariant &Default, const QString &HelpText, bool ExitImmediately/*=false*/);
45  QVariant GetValue (const QString &Key);
46 
47  private:
48  void AddPriv (const QString &Keys, const QVariant &Default, const QString &HelpText, TorcCommandLine::Options Flags = TorcCommandLine::None, bool ExitImmediately = false);
49 
50  private:
51  QHash<QString,TorcArgument> m_options;
52  QHash<QString,QString> m_aliases;
53  QHash<QString,QString> m_help;
54  uint m_maxLength;
55 };
56 
58 {
59  public:
60  TorcArgument();
61  TorcArgument(const QVariant &Default, const QString &HelpText, TorcCommandLine::Options Flags, bool Exit);
62 
63  QVariant m_value;
64  QString m_helpText;
66  TorcCommandLine::Options m_flags;
67 };
68 
69 Q_DECLARE_OPERATORS_FOR_FLAGS(TorcCommandLine::Options)
70 
71 #endif // TORCCOMMANDLINE_H
QString m_helpText
Torc command line handler.
bool m_exitImmediately
QVariant m_value
void Add(const QString &Keys, const QVariant &Default, const QString &HelpText, bool ExitImmediately)
Implement custom command line options.
static bool RegisterEnvironmentVariable(const QString &Var, const QString &Description)
Register an environment variable for display via the help option.
TorcCommandLine::Options m_flags
Simple wrapper around a command line argument.
int Evaluate(int argc, const char *const *argv, bool &Exit)
Evaluate the command line options.
QVariant GetValue(const QString &Key)
Return the value associated with Key or an invalid QVariant if the option is not present.