GestureRecognitionToolkit  Version: 1.0 Revision: 04-03-15
The Gesture Recognition Toolkit (GRT) is a cross-platform, open-source, c++ machine learning library for real-time gesture recognition.
CommandLineParser.h
1 /*
2 GRT MIT License
3 Copyright (c) <2012> <Nicholas Gillian, Media Lab, MIT>
4 
5 Permission is hereby granted, free of charge, to any person obtaining a copy of this software
6 and associated documentation files (the "Software"), to deal in the Software without restriction,
7 including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
9 subject to the following conditions:
10 
11 The above copyright notice and this permission notice shall be included in all copies or substantial
12 portions of the Software.
13 
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
15 LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
18 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19 */
20 
21 #ifndef GRT_COMMAND_LINE_PARSER_HEADER
22 #define GRT_COMMAND_LINE_PARSER_HEADER
23 
24 #include <iostream>
25 #include <vector>
26 #include <algorithm>
27 #include <fstream>
28 #include <sstream>
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <limits>
32 #include <math.h>
33 #include <fstream>
34 #include <typeinfo>
35 #include "InfoLog.h"
36 #include "ErrorLog.h"
37 #include "Util.h"
38 
39 namespace GRT{
40 
42 public:
46  CommandLineParser():infoLog("[CommandLineParser]"),errorLog("[ERROR CommandLineParser]"),warningLog("[WARNING CommandLineParser]"){}
47 
52 
53  bool addOption(const std::string option,const std::string destination){
54  options[option] = destination;
55  return true;
56  }
57 
58  bool parse(const int argc,const char * argv[] ){
59 
60  results.clear();
61 
62  std::map<std::string,std::string>::iterator it;
63  for(int i=1; i<argc; i++){
64 
65  //Search for a match in the options map
66  it = options.find( std::string(argv[i]) );
67  if( it != options.end() ){
68  results[ it->second ] = std::string(argv[i+1]);
69  }
70  }
71 
72  return true;
73  }
74 
75  template<class T> bool get(const std::string destination,T &option,T defaultValue = T()){
76 
77  //Find the option in the results buffer
78  std::map<std::string,std::string>::iterator it;
79  it = results.find( destination );
80 
81  if( it == results.end() ){
82  option = defaultValue;
83  warningLog << "get(const std::string destination,T &option) - Failed to find destination: " << destination << endl;
84  return false;
85  }
86 
87  try{
88  std::stringstream s( it->second );
89  s >> option;
90  return true;
91  }catch( ... ){
92  warningLog << "get(const std::string destination,T &option) - Can not parse type: " << typeid( option ).name() << endl;
93  }
94 
95  return false;
96  }
97 
98 
99  InfoLog infoLog;
100  WarningLog warningLog;
101  ErrorLog errorLog;
102  std::map< std::string, std::string > options;
103  std::map< std::string, std::string > results;
104 
105 };
106 
107 } //End of namespace GRT
108 
109 #endif //GRT_COMMAND_LINE_PARSER_HEADER
This file contains the Util class, a wrapper for a number of generic functions that are used througho...
Definition: AdaBoost.cpp:25