Drake
drakeAppUtil.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <string>
4 #include <algorithm>
5 
6 /*** getCommandLineOption
7  * @brief Provides a platform-independent way to parse command line options
8  *(getopt is not available on msvc)
9  *
10  * Example usage:
11  * char * filename = getCommandLineOption(argv, argv + argc, "-f");
12  * if (filename) { ... }
13  *
14  * See also commandLineOptionExists
15  */
16 char* getCommandLineOption(char** begin, char** end,
17  const std::string& option) {
18  char** itr = std::find(begin, end, option);
19  if (itr != end && ++itr != end) {
20  return *itr;
21  }
22  return 0;
23 }
24 
25 /*** commandLineOptionExists
26  * @brief Provides a platform-independent way to parse command line options
27  *(getopt is not available on msvc)
28  *
29  * Example usage:
30  * if (commandLineOptionExists(argv, argv+argc, "-h")) { ... }
31  *
32  * See also getCommandLineOption
33  */
34 
35 bool commandLineOptionExists(char** begin, char** end,
36  const std::string& option) {
37  return std::find(begin, end, option) != end;
38 }
char * getCommandLineOption(char **begin, char **end, const std::string &option)
Definition: drakeAppUtil.h:16
bool commandLineOptionExists(char **begin, char **end, const std::string &option)
Definition: drakeAppUtil.h:35