params.hh 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /**
  2. * params.hh for jsonstroller
  3. *
  4. * Author: isundil <isundill@gmail.com>
  5. **/
  6. #pragma once
  7. #include <list>
  8. #include <string>
  9. #include <istream>
  10. class AParams
  11. {
  12. public:
  13. /**
  14. * true if --ascii
  15. **/
  16. virtual bool isIgnoringUnicode() const =0;
  17. /**
  18. * false if -W
  19. **/
  20. virtual bool isStrict() const =0;
  21. /**
  22. * true if --color match conditions
  23. **/
  24. virtual bool colorEnabled() const =0;
  25. };
  26. class Params: public AParams
  27. {
  28. public:
  29. Params(int ac, char **av);
  30. virtual ~Params();
  31. /**
  32. * retun input
  33. * can be file stream (-f), stringstream ( -- INPUT), or std::cin (none)
  34. **/
  35. std::basic_istream<char> &getInput() const;
  36. /**
  37. * false if invalid argument is passed
  38. **/
  39. bool isValid() const;
  40. /**
  41. * print usage
  42. * @param program name
  43. **/
  44. static void usage(const std::string &) noexcept;
  45. /**
  46. * get argv[0]
  47. **/
  48. const std::string &getProgName() const;
  49. /**
  50. * flags
  51. **/
  52. bool isStrict() const;
  53. bool colorEnabled() const;
  54. bool isIgnoringUnicode() const;
  55. private:
  56. /**
  57. * input stream
  58. * can be null for stdin
  59. **/
  60. std::basic_istream<char> *input;
  61. const std::string progName;
  62. std::list<std::string> params;
  63. bool ignoreUnicode;
  64. bool colorMode;
  65. bool strict;
  66. };