options.hpp 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. static std::string validStringArguments[] = { "bordersize", "padding", "color", "shader", "highlight", "format" };
  29. static char validCharArguments[] = { 'b', 'p', 'c', 's', 'h', 'f' };
  30. // 0 for flag, 1 for how many arguments to eat up
  31. static unsigned int isFlagArgument[] = { false, false, false, false, true, false };
  32. static unsigned int validArgumentCount = 6;
  33. static unsigned int maxFloatingValues = 0;
  34. class Options {
  35. private:
  36. std::vector<std::string> arguments;
  37. std::vector<std::string> values;
  38. std::vector<std::string> floatingValues;
  39. int parseCharOption( int argc, char** argv, int argumentIndex, int validIndex );
  40. int parseStringOption( int argc, char** argv, int argumentIndex, int validIndex );
  41. int validateStringOption( int argc, char** argv, int argumentIndex );
  42. int validateCharOption( int argc, char** argv, int argumentIndex );
  43. void validate( int argc, char** argv );
  44. public:
  45. Options( int argc, char** argv );
  46. bool getFloat( std::string name, char namec, float& found );
  47. bool getInt( std::string name, char namec, int& found );
  48. bool getString( std::string name, char namec, std::string& found );
  49. bool getColor( std::string name, char namec, glm::vec4& found );
  50. bool getBool( std::string name, char namec, bool& found );
  51. };
  52. #endif // N_OPTIONS_H_