1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
20121120 rsz Created.
*/
#include <stdio.h>
#include "ezOptionParser.hpp"

using namespace ez;

int main(int argc, const char * argv[]) {
  ezOptionParser opt;

  opt.overview = "Demo of parse index for options.";
  opt.syntax = "parseindex [OPTIONS] in out";
  opt.example = "./parseindex skip -f foo -c bar,baz -c bam -f ooz -c yum ignore";
  
  opt.add(
    "", // Default.
    0, // Required?
    -1, // Number of args expected.
    ',', // Delimiter if expecting multiple args.
    "Some list of config parameters.", // Help description.
    "-c" // Flag token.
  );

  opt.add(
    "", // Default.
    0, // Required?
    1, // Number of args expected.
    0, // Delimiter if expecting multiple args.
    "Some string.", // Help description.
    "-f" // Flag token.
  );

  opt.parse(argc, argv);

  int i,j,n;
  const char * flags[] = {"-c", "-f"};
  
  for(i=0; i < 2; ++i) {
    if (opt.isSet(flags[i])) {
      std::vector<int> & indices = opt.get(flags[i])->parseIndex;
      n = indices.size();
      std::cout << flags[i] << " indices: ";
      
      for(j=0; j < n; ++j)
        std::cout << indices[j] << " "; 
      
      std::cout << std::endl;
    }
  }

  return 0;
}