My Project
 All Classes Functions Variables Pages
Console.h
1 /*
2  * Console.h
3  *
4  * Created on: Jun 15, 2018
5  * Author: kolban
6  */
7 
8 #ifndef COMPONENTS_CPP_UTILS_CONSOLE_H_
9 #define COMPONENTS_CPP_UTILS_CONSOLE_H_
10 
11 #include <string>
12 #include <stdio.h>
13 #include <list>
14 #include <argtable3/argtable3.h>
15 
16 class Console {
17 public:
18  Console();
19  virtual ~Console();
20 };
21 
22 
23 enum class ArgType_t { LIT, INT, DBL, STR, REX, FILE, DATE };
24 
25 
27 protected:
28  ArgType_t m_type;
29 public:
30  virtual int getCount();
31  bool hasValue() {
32  return getCount() > 0;
33  }
34  virtual void* getEntry() = 0;
35 };
36 
37 
39 private:
40  struct arg_lit* m_argLit;
41 public:
42  int getCount();
43  ArgTableEntry_Lit(std::string shortopts, std::string longopts, std::string glossary);
44  void* getEntry() {
45  return m_argLit;
46  }
47 };
48 
50 private:
51  struct arg_int* m_argInt;
52 public:
53  ArgTableEntry_Int(std::string shortopts, std::string longopts, std::string glossary);
54  int getCount();
55  int getValue(int index = 0);
56  void* getEntry() {
57  return m_argInt;
58  }
59 };
60 
61 
63 private:
64  struct arg_dbl* m_argDbl;
65 public:
66  ArgTableEntry_Double(std::string shortopts, std::string longopts, std::string glossary);
67  int getCount();
68  double getValue(int index = 0);
69  void* getEntry() {
70  return m_argDbl;
71  }
72 };
73 
74 
76 private:
77  struct arg_str* m_argStr;
78 public:
79  ArgTableEntry_String(std::string shortopts, std::string longopts, std::string glossary, int min, int max);
80  int getCount();
81  std::string getValue(int index = 0);
82  void* getEntry() {
83  return m_argStr;
84  }
85 };
86 
87 
89 private:
90  struct arg_rex* m_argRex;
91 public:
92  int getCount();
93  std::string getValue(int index = 0);
94  void* getEntry() {
95  return m_argRex;
96  }
97 };
98 
99 
101 private:
102  struct arg_file* m_argFile;
103 public:
104  ArgTableEntry_File(std::string shortopts, std::string longopts, std::string glossary);
105  int getCount();
106  std::string getFilename(int index = 0);
107  std::string getBasename(int index = 0);
108  std::string getExtension(int index = 0);
109  void* getEntry() {
110  return m_argFile;
111  }
112 };
113 
114 
116 private:
117  struct arg_date* m_argDate;
118 public:
119  ArgTableEntry_Date(std::string shortopts, std::string longopts, std::string glossary);
120  int getCount();
121  struct tm* getValue(int index = 0);
122  void* getEntry() {
123  return m_argDate;
124  }
125 };
126 
127 
128 class ArgTable {
129 private:
130  void** m_argtable;
131  struct arg_end* m_argEnd;
132  std::list<std::pair<std::string, ArgTableEntry_Generic*>> m_argTableEntries;
133  void build();
134  void freeArgtable();
135 
136 public:
137  ArgTable();
138  ~ArgTable();
139  ArgTableEntry_Date addDate(std::string name, std::string shortopts, std::string longopts, std::string glossary);
140  ArgTableEntry_Double addDouble(std::string name, std::string shortopts, std::string longopts, std::string glossary);
141  ArgTableEntry_File addFile(std::string name, std::string shortopts, std::string longopts, std::string glossary);
142  ArgTableEntry_Int addInt(std::string name, std::string shortopts, std::string longopts, std::string glossary);
143  ArgTableEntry_Lit addLit(std::string name, std::string shortopts, std::string longopts, std::string glossary);
144  ArgTableEntry_String addString(std::string name, std::string shortopts, std::string longopts, std::string glossary, int min, int max);
145  int parse(int argc, char* argv[]);
146  void printErrors(FILE* fp, std::string progName="");
147 };
148 
149 #endif /* COMPONENTS_CPP_UTILS_CONSOLE_H_ */
Definition: Console.h:75
Definition: Console.h:128
Definition: Console.h:16
Definition: Console.h:26
~ArgTable()
Definition: Console.cpp:30
Definition: Console.h:88
void printErrors(FILE *fp, std::string progName="")
Definition: Console.cpp:115
Definition: Console.h:115
Definition: Console.h:38
ArgTable()
Definition: Console.cpp:21
Definition: Console.h:100
Definition: Console.h:62
int parse(int argc, char *argv[])
Definition: Console.cpp:103
Definition: Console.h:49