Class CursorStreamWrapper

Synopsis

#include <include/rapidjson/cursorstreamwrapper.h>

template <typename InputStream, typename Encoding = UTF8<> >
class CursorStreamWrapper : public GenericStreamWrapper<InputStream, Encoding>

Description

Cursor stream wrapper for counting line and column number if error exists.

Template Parameters

InputStream - Any stream that implements Stream Concept

Inheritance

Ancestors: GenericStreamWrapper

Methods

CursorStreamWrapper
GetColumnGet the error column number, if error exists.
GetLineGet the error line number, if error exists.
Take

Source

Lines 38-66 in include/rapidjson/cursorstreamwrapper.h.

template <typename InputStream, typename Encoding = UTF8<> >
class CursorStreamWrapper : public GenericStreamWrapper<InputStream, Encoding> {
public:
    typedef typename Encoding::Ch Ch;

    CursorStreamWrapper(InputStream& is):
        GenericStreamWrapper<InputStream, Encoding>(is), line_(1), col_(0) {}

    // counting line and column number
    Ch Take() {
        Ch ch = this->is_.Take();
        if(ch == '\n') {
            line_ ++;
            col_ = 0;
        } else {
            col_ ++;
        }
        return ch;
    }

    //! Get the error line number, if error exists.
    size_t GetLine() const { return line_; }
    //! Get the error column number, if error exists.
    size_t GetColumn() const { return col_; }

private:
    size_t line_;   //!< Current Line
    size_t col_;    //!< Current Column
};





Add Discussion as Guest

Log in