Argo  1.0
A C++ library for handling JSON.
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
argo::stream_reader Class Reference

A class to read JSON messages from C++ istreams. More...

#include <stream_reader.hpp>

Inheritance diagram for argo::stream_reader:
argo::reader

Public Member Functions

 stream_reader (std::istream *s, int max_message_length, bool block_read)
 
- Public Member Functions inherited from argo::reader
 reader (size_t max_message_length, bool block_read)
 
virtual int next ()
 Get the next character from the reader. More...
 
virtual void put_back (int c)
 Put back a character so that it is returned by the next call to next().
 
size_t get_byte_index () const
 Get the current byte index in the input.
 
void reset_byte_index ()
 Reset the byte index at the start of parsing a messege.
 

Protected Member Functions

virtual int read_next_char ()
 
virtual bool read_next_block ()
 
- Protected Member Functions inherited from argo::reader
int read_next_char_from_block ()
 When in block read mode, get the next available character.
 

Protected Attributes

std::istream * m_stream
 The C++ stream to read from.
 
- Protected Attributes inherited from argo::reader
int m_put_back
 Character last put back. If equal to no_put_back then none was.
 
size_t m_byte_index
 Total number of characters read.
 
size_t m_max_message_length
 Maximum length of a message.
 
bool m_block_read
 Whether to read in blocks or one byte at a time.
 
unsigned char m_block [block_size]
 If we're reading blocks, the block data.
 
int m_block_num_bytes
 If we're reading blocks, the number of bytes in the current block.
 
int m_block_index
 If we're reading blocks, the index into the current block.
 

Additional Inherited Members

- Static Public Attributes inherited from argo::reader
static const int block_size = 8192
 Amount of data to read at once when in block read mode.
 
- Static Protected Attributes inherited from argo::reader
static const int no_put_back = 1000
 Special character value indicating that no character has been put back.
 

Detailed Description

A class to read JSON messages from C++ istreams.

Definition at line 35 of file stream_reader.hpp.

Constructor & Destructor Documentation

stream_reader::stream_reader ( std::istream *  s,
int  max_message_length,
bool  block_read 
)

Constructor.

Parameters
sIOSTREAMS input stream. The instance does not take ownership of the stream and it is up to the calling code to close it when done.
max_message_lengthLongest message that can be read.
block_readWhether to read in blocks or one byte at a time.

Definition at line 33 of file stream_reader.cpp.

Member Function Documentation

bool stream_reader::read_next_block ( )
protectedvirtual

Read the next block of data up to block_size bytes.

Returns
true if some data was read, false if EOF.
Exceptions
json_io_errorif the read failed for some reason other than EOF.

Implements argo::reader.

Definition at line 44 of file stream_reader.cpp.

int stream_reader::read_next_char ( )
protectedvirtual

Read a character from the file using fread()

Exceptions
json_io_exceptionThrown if fread fails in some way.

Implements argo::reader.

Definition at line 39 of file stream_reader.cpp.


The documentation for this class was generated from the following files: