options.hpp 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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", "tolerance", "nodecorations", "nokeyboard", "help", "xdisplay", "version", "quiet" };
  29. static char validCharArguments[] = { 'b', 'p', 'c', 'r', 'l', 'f', 't', 'n', 'k', 'h', 'd', 'v', 'q' };
  30. static unsigned int isFlagArgument[] = { false, false, false, false, true, false, false, false, true, true, false, true, true };
  31. static unsigned int validArgumentCount = 13;
  32. static unsigned int maxFloatingValues = 0;
  33. class Options {
  34. private:
  35. std::vector<std::string> arguments;
  36. std::vector<std::string> values;
  37. std::vector<std::string> floatingValues;
  38. int parseCharOption( int argc, char** argv, int argumentIndex, int validIndex );
  39. int parseStringOption( int argc, char** argv, int argumentIndex, int validIndex );
  40. int validateStringOption( int argc, char** argv, int argumentIndex );
  41. int validateCharOption( int argc, char** argv, int argumentIndex );
  42. void validate( int argc, char** argv );
  43. public:
  44. Options( int argc, char** argv );
  45. bool getFloat( std::string name, char namec, float& found );
  46. bool getInt( std::string name, char namec, int& found );
  47. bool getString( std::string name, char namec, std::string& found );
  48. bool getColor( std::string name, char namec, glm::vec4& found );
  49. bool getBool( std::string name, char namec, bool& found );
  50. };
  51. #endif // N_OPTIONS_H_