params.hh 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. * true if need sorted object
  31. **/
  32. virtual bool sortObjects() const =0;
  33. };
  34. class Params: public AParams
  35. {
  36. public:
  37. Params(char **av);
  38. virtual ~Params();
  39. /**
  40. * Interpret input
  41. **/
  42. virtual bool read();
  43. /**
  44. * retun input
  45. * can be file stream (-f), stringstream ( -- INPUT), or std::cin (none)
  46. **/
  47. IndexedDeque getInputs() const;
  48. /**
  49. * false if invalid argument is passed
  50. **/
  51. bool isValid() const;
  52. /**
  53. * print usage
  54. * @param program name
  55. **/
  56. virtual void usage() const noexcept;
  57. /**
  58. * print version number
  59. * @param program name
  60. **/
  61. virtual void version() const noexcept;
  62. /**
  63. * get argv[0]
  64. **/
  65. const std::string &getProgName() const;
  66. /**
  67. * flags
  68. **/
  69. bool isStrict() const;
  70. bool colorEnabled() const;
  71. bool isIgnoringUnicode() const;
  72. bool isDiff() const;
  73. bool sortObjects() const;
  74. private:
  75. /**
  76. * input stream
  77. * can be null for stdin
  78. **/
  79. IndexedDeque inputs;
  80. const std::string progName;
  81. std::list<std::string> params;
  82. bool ignoreUnicode;
  83. bool colorMode;
  84. bool strict;
  85. bool diffMode;
  86. bool sorted;
  87. };