Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Class template basic_reader

trial::protocol::json::basic_reader — Incremental JSON reader.

Synopsis

// In header: <boost/libs/trial.protocol/include/trial/protocol/json/reader.hpp>

template<typename CharT> 
class basic_reader {
public:
  // types
  typedef unspecified value_type;
  typedef unspecified size_type; 
  typedef unspecified view_type; 

  // construct/copy/destruct
  basic_reader(const view_type &);
  basic_reader(const basic_reader &);

  // public member functions
  bool next();
  bool next(token::code::value);
  size_type level() const noexcept;
  token::code::value code() const noexcept;
  token::symbol::value symbol() const noexcept;
  token::category::value category() const noexcept;
  std::error_code error() const noexcept;
  template<typename ReturnType> ReturnType value() const;
  const view_type & literal() const noexcept;
  const view_type & tail() const noexcept;
};

Description

Parse a JSON formatted input buffer incrementally. Incrementally means that the reader only parses enough of the input to identify the next token. The entire input has to be parsed by repeating parsing the next token until the end of the input.

basic_reader public construct/copy/destruct

  1. basic_reader(const view_type & view);
    Construct an incremental JSON reader.

    The first token is automatically parsed.

    The reader does not assume ownership of the view.

    Parameters:

    view

    A string view of a JSON formatted buffer.

  2. basic_reader(const basic_reader & other);
    Copy-construct an incremental JSON reader.

    Copies the internal parsing state from the input reader, and continues parsing independently from where the input reader had reached.

    Parameters:

    other

    The reader that is copied.

basic_reader public member functions

  1. bool next();
    Parse the next token.

    Returns:

    false if an error occurred or end-of-input was reached, true otherwise.

  2. bool next(token::code::value expect);
    Parse the next token if current token has a given value.

    Parameters:

    expect

    Expected value of current token.

    Returns:

    false if current token does not have the expected value.

  3. size_type level() const noexcept;
    Get the current nesting level.

    Keep track of the nesting level of containers. The outermost root level is 0.

    Returns:

    The current nesting level.

  4. token::code::value code() const noexcept;
    Get the current token as a detailed code.

    Returns:

    The code of the current token.

  5. token::symbol::value symbol() const noexcept;
    Get the current token as a symbol.

    Returns:

    The symbol of the current token.

  6. token::category::value category() const noexcept;
    Get the current token as a category.

    Returns:

    The category of the current token.

  7. std::error_code error() const noexcept;
    Get the current error.

    The error code contains an error enumerator. If parsing did not result in an error, the json::no_error enumerator is used.

    Returns:

    The current error code.

  8. template<typename ReturnType> ReturnType value() const;
    Converts the current value into ReturnType.

    The following conversions are valid:

    1. Convert a symbol::boolean token into bool.

    2. Convert a symbol::integer token into an integral C++ type (expect bool.)

    3. Convert a symbol::real token into a floating-point C++ type.

    4. Convert a symbol::string token into std::string.

    Returns:

    The converted value.

    Throws:

    json::error If requested type is incompatible with the current token.
  9. const view_type & literal() const noexcept;

    Returns:

    A view of the current value before it is converted into its type.

  10. const view_type & tail() const noexcept;

    Returns:

    A view of the remaining buffer.


PrevUpHomeNext