params.hh 1.8 KB

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