params.hh 1.9 KB

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