parse_options.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /**
  2. \file parse_options.h
  3. \author michael.zohner@ec-spride.de
  4. \copyright ABY - A Framework for Efficient Mixed-protocol Secure Two-party Computation
  5. Copyright (C) 2019 ENCRYPTO Group, TU Darmstadt
  6. This program is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU Lesser General Public License as published
  8. by the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. ABY is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU Lesser General Public License for more details.
  14. You should have received a copy of the GNU Lesser General Public License
  15. along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. \brief Parse Options Implementation
  17. */
  18. #ifndef UTIL_PARSE_OPTIONS_H_
  19. #define UTIL_PARSE_OPTIONS_H_
  20. #include <cstdint>
  21. #include <string>
  22. #include <vector>
  23. /**
  24. \enum etype
  25. \brief Data types for command line parameters
  26. */
  27. enum etype {
  28. T_NUM, //uint32_t number
  29. T_STR, //string
  30. T_FLAG, //boolean flag
  31. T_DOUBLE //double number
  32. };
  33. /**
  34. \struct parsing_ctx
  35. \brief holds information about parameters that should be parsed in the command line input
  36. */
  37. struct parsing_ctx {
  38. void* val; //value of the option, is written into by parse_options
  39. etype type; //type of value
  40. std::string opt_name; //name to set the parameter via command line
  41. std::string help_str; //definition of the parameter that is printed in print_usage
  42. bool required; //is the parameter required to run the program? If required and not set by the invocation, program will exit
  43. bool set; //has the value for the parameter been set previously? In case the parameter is read, this will be set to true
  44. };
  45. /**
  46. This method parses the command line arguments from a C program, given in argcp and argcv, using the flags and parameters specified
  47. in options where nops gives the number of parameters that are parsed. The values for the parameters are written into options.
  48. \param argcp - Pointer to argc
  49. \param argvp - Pointer to argv
  50. \param options - A list of parameters that the command line input should be parsed for
  51. \param nops - Number of parameters in options
  52. \return 0 if the command line string was faulty and 1 otherwise.
  53. */
  54. int32_t parse_options(int32_t* argcp, char*** argvp, parsing_ctx* options, uint32_t nops);
  55. /**
  56. This method prints the command line parameters together with a short help description in help_str
  57. \param progname - Name of the program
  58. \param options - Parameters that should be printed
  59. \param nops - Number of parameters in options
  60. */
  61. void print_usage(std::string progname, parsing_ctx* options, uint32_t nops);
  62. void tokenize(const std::string& str, std::vector<uint32_t>& tokens, const std::string& delimiters = "| \t");
  63. void tokenize_verilog(const std::string& str, std::vector<uint32_t>& tokens, const std::string& delimiters = " \t");
  64. #endif /* PARSE_OPTIONS_H_ */