params.hh 2.3 KB

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