1
1

streamConsumer.hh 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /**
  2. * streamConsumer.hh for jsonstroller
  3. *
  4. * Author: isundil <isundill@gmail.com>
  5. **/
  6. #pragma once
  7. #include <istream>
  8. #include "params.hh"
  9. #include "jsonObject.hh"
  10. #include "jsonArray.hh"
  11. #include "jsonPrimitive.hh"
  12. #include "linearHistory.hh"
  13. #include "warning.hh"
  14. class StreamConsumer
  15. {
  16. public:
  17. /**
  18. * constructor
  19. * does not read yet
  20. **/
  21. StreamConsumer(std::istream &stream);
  22. virtual ~StreamConsumer();
  23. /**
  24. * read from stream and set root data
  25. * @return current instance
  26. **/
  27. StreamConsumer *read();
  28. /**
  29. * get root node
  30. **/
  31. const JSonElement * getRoot() const;
  32. JSonElement * getRoot();
  33. /**
  34. * return non-blocking error messages
  35. **/
  36. const std::list<Warning> &getMessages() const;
  37. /**
  38. * set builder's params
  39. **/
  40. StreamConsumer *withConfig(const AParams *);
  41. private:
  42. /**
  43. * @return non-null on successfully read JSonElement, or null if token (',', '[', ...)
  44. **/
  45. JSonElement *consumeToken(JSonContainer *parent, std::string &buf);
  46. /**
  47. * read next item, fill object or array if found
  48. **/
  49. JSonElement *readNext(JSonContainer *parent);
  50. /**
  51. * fill object
  52. **/
  53. JSonObject *readObject(JSonContainer *parent);
  54. /**
  55. * fill array
  56. **/
  57. JSonArray *readArray(JSonContainer *parent);
  58. /**
  59. * out of token, should we ignore that char ?
  60. **/
  61. bool ignoreChar(char c) const noexcept;
  62. /**
  63. * compute unicode value and append it to buffer
  64. **/
  65. static void appendUnicode(const char [4], std::string &);
  66. /**
  67. * input stream
  68. **/
  69. std::istream &stream;
  70. /**
  71. * once read, contains root element
  72. **/
  73. JSonElement *root;
  74. /**
  75. * builder params (program's one in fact)
  76. **/
  77. const AParams *params;
  78. /**
  79. * non-blocking errors
  80. **/
  81. std::list<Warning> warnings;
  82. /**
  83. * last read input
  84. **/
  85. LinearHistory history;
  86. };