1
1

params.hh 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. * Interpret input
  33. **/
  34. virtual bool read();
  35. /**
  36. * retun input
  37. * can be file stream (-f), stringstream ( -- INPUT), or std::cin (none)
  38. **/
  39. std::basic_istream<char> &getInput() const;
  40. /**
  41. * false if invalid argument is passed
  42. **/
  43. bool isValid() const;
  44. /**
  45. * print usage
  46. * @param program name
  47. **/
  48. virtual void usage() const noexcept;
  49. /**
  50. * print version number
  51. * @param program name
  52. **/
  53. virtual void version() const noexcept;
  54. /**
  55. * get argv[0]
  56. **/
  57. const std::string &getProgName() const;
  58. /**
  59. * flags
  60. **/
  61. bool isStrict() const;
  62. bool colorEnabled() const;
  63. bool isIgnoringUnicode() const;
  64. private:
  65. /**
  66. * input stream
  67. * can be null for stdin
  68. **/
  69. std::basic_istream<char> *input;
  70. const std::string progName;
  71. std::list<std::string> params;
  72. bool ignoreUnicode;
  73. bool colorMode;
  74. bool strict;
  75. };