getopt_cpp.h 876 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Portions Copyright (c) 1987, 1993, 1994
  3. * The Regents of the University of California. All rights reserved.
  4. *
  5. * Portions Copyright (c) 2003-2010, PostgreSQL Global Development
  6. * Group
  7. *
  8. * Simple conversion to C++ by Andrew Tridgell for ArduPilot. Based on
  9. * getopt_long.h from ccache
  10. */
  11. #pragma once
  12. class GetOptLong {
  13. public:
  14. struct option {
  15. const char *name;
  16. bool has_arg;
  17. int *flag;
  18. int val;
  19. };
  20. GetOptLong(int argc, char *const argv[], const char *optstring, const option * longopts);
  21. int opterr;
  22. int optind;
  23. int optopt;
  24. int longindex;
  25. const char *optarg;
  26. enum error_return {
  27. BADCH='?',
  28. BADARG=':'
  29. };
  30. int getoption(void);
  31. private:
  32. int argc;
  33. char *const *argv;
  34. const char *optstring;
  35. const struct option *longopts;
  36. const char *place;
  37. };