| 7 | |
| 8 | |
| 9 | class TrackingStream : public std::enable_shared_from_this<TrackingStream> |
| 10 | { |
| 11 | private: |
| 12 | char m_chPrevChar {}; // Store previous character for handling column postion |
| 13 | size_t m_nLine {}; |
| 14 | size_t m_nColumn {}; |
| 15 | rapidjson::StringStream m_ss; |
| 16 | |
| 17 | public: |
| 18 | using Ch = char; // Define Ch to conform to RapidJSON's expectations |
| 19 | |
| 20 | TrackingStream(const std::string& jsonText) |
| 21 | : m_ss(jsonText.c_str()) |
| 22 | , m_nLine(0) |
| 23 | , m_nColumn(0) |
| 24 | , m_chPrevChar('\0') |
| 25 | { |
| 26 | } |
| 27 | |
| 28 | std::shared_ptr<TrackingStream> GetShared() |
| 29 | { |
| 30 | return shared_from_this(); |
| 31 | } |
| 32 | |
| 33 | inline size_t getLine() const |
| 34 | { |
| 35 | return m_nLine; |
| 36 | } |
| 37 | |
| 38 | inline size_t getColumn() const |
| 39 | { |
| 40 | return m_nColumn; |
| 41 | } |
| 42 | |
| 43 | // Read the next character and update line/column numbers |
| 44 | Ch Take() |
| 45 | { |
| 46 | Ch ch = m_ss.Take(); |
| 47 | if (ch == '\n') |
| 48 | { |
| 49 | ++m_nLine; |
| 50 | m_nColumn = 0; |
| 51 | } |
| 52 | else |
| 53 | { |
| 54 | ++m_nColumn; |
| 55 | } |
| 56 | m_chPrevChar = ch; |
| 57 | return ch; |
| 58 | } |
| 59 | |
| 60 | Ch Peek() const |
| 61 | { |
| 62 | return m_ss.Peek(); |
| 63 | } |
| 64 | |
| 65 | size_t Tell() const |
| 66 | { |
nothing calls this directly
no outgoing calls
no test coverage detected