1 #ifndef __COMMAND_COMMAND_H
2 #define __COMMAND_COMMAND_H
11 * Main class for handling user passed parameters from command line.
15 std::vector<Parameter *> parameters;
18 * Default constructor.
20 * @param argc passed to the main function
21 * @param argv passed to the main function
22 * @param params initializer_list containing Parameter handlers
23 * responsible for correctly handle user data.
25 Command(unsigned int argc, char *argv[], std::initializer_list<Parameter *> params)
26 : parameters(params) {
29 matchArguments(argc, argv);
31 catch(std::invalid_argument exception) {
38 * Destructor. Releases allocated memory.
45 * Matches user passed arguments with available parameter handlers.
47 void matchArguments(unsigned int argc, char *argv[]) {
48 for (unsigned int i = 1; i < argc; i++) {
49 for(Parameter *param : parameters) {
50 if (param->understand(argv[i])) {
59 * Releases acquired memory
61 void releaseMemory() {
62 for (Parameter * parameter : parameters) {
63 if (parameter != NULL) {
68 parameters.shrink_to_fit();
73 #endif /* __COMMAND_COMMAND_H */