options.hpp 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* options.hpp: parses arguments from the commandline.
  2. *
  3. * Copyright (C) 2014: Dalton Nell, Slop Contributors (https://github.com/naelstrof/slop/graphs/contributors).
  4. *
  5. * This file is part of Slop.
  6. *
  7. * Slop is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * Slop is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with Slop. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #ifndef N_OPTIONS_H_
  21. #define N_OPTIONS_H_
  22. #include <iostream>
  23. #include <string>
  24. #include <exception>
  25. #include <stdexcept>
  26. #include <vector>
  27. #include <glm/glm.hpp>
  28. class Argument {
  29. public:
  30. std::string name;
  31. char cname;
  32. bool isFlagArgument;
  33. Argument( std::string name, char cname, bool isFlagArgument ) : name(name), cname(cname), isFlagArgument(isFlagArgument) {}
  34. };
  35. static std::vector<Argument> validArguments;
  36. static unsigned int maxFloatingValues = 0;
  37. class Options {
  38. private:
  39. std::vector<std::string> arguments;
  40. std::vector<std::string> values;
  41. std::vector<std::string> floatingValues;
  42. int parseCharOption( int argc, char** argv, int argumentIndex, int validIndex );
  43. int parseStringOption( int argc, char** argv, int argumentIndex, int validIndex );
  44. int validateStringOption( int argc, char** argv, int argumentIndex );
  45. int validateCharOption( int argc, char** argv, int argumentIndex );
  46. void validate( int argc, char** argv );
  47. public:
  48. Options( int argc, char** argv );
  49. bool getFloat( std::string name, char namec, float& found );
  50. bool getInt( std::string name, char namec, int& found );
  51. bool getString( std::string name, char namec, std::string& found );
  52. bool getColor( std::string name, char namec, glm::vec4& found );
  53. bool getBool( std::string name, char namec, bool& found );
  54. };
  55. #endif // N_OPTIONS_H_