Jive reference manual
List of all members | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes
jem::mt::ThreadSafeReader Class Reference

#include <jem/mt/ThreadSafeReader.h>

Inheritance diagram for jem::mt::ThreadSafeReader:
Inheritance graph

Public Types

typedef ThreadSafeReader Self
 
typedef Reader Super
 

Public Member Functions

 ThreadSafeReader (const Ref< Reader > &in)
 
 ThreadSafeReader (const Ref< Reader > &in, const Ref< IOMutex > &mutex)
 
 ThreadSafeReader (const Self &rhs)
 
virtual Ref< Readerdup ()
 
virtual void lock ()
 Locks this input stream. More...
 
virtual void unlock ()
 Unlocks this input stream. More...
 
virtual void close ()
 Closes this input stream. More...
 
virtual idx_t poll (const Time &timeout)
 
virtual int read ()
 Extracts the next character from this input stream. More...
 
virtual idx_t read (char *buf, idx_t n)
 
virtual idx_t readUntil (char *buf, idx_t n, int delim)
 
virtual void pushBack (int c)
 Pushes back a previously read character. More...
 
virtual void skipUntil (int delim)
 Skips characters until a specified character. More...
 
virtual void skipWhite ()
 Skips over white space. More...
 
virtual idx_t skip (idx_t n)
 
- Public Member Functions inherited from jem::io::Reader
virtual int poll ()
 Returns the number of characters that can read without blocking. More...
 
virtual int read (char *buf, int n)
 Extracts multiple characters from this input stream. More...
 
virtual int readUntil (char *buf, int n, int delim)
 Reads characters until a specified character. More...
 
virtual int skip (int n)
 Skips over a specified number of characters. More...
 
String readLine ()
 Reads the next line from this input stream. More...
 
virtual byte parseByte ()
 Reads a byte from this input stream. More...
 
virtual bool parseBool ()
 Reads a boolean from this input stream. More...
 
virtual long parseInt ()
 Reads a long integer from this input stream. More...
 
virtual double parseFloat ()
 Reads a double from this input stream. More...
 
- Public Member Functions inherited from jem::Object
virtual ClassgetClass () const
 Returns the Class instance representing the runtime class of this object. More...
 
virtual String toString () const
 Returns a short textual description of this object. More...
 
virtual long hashValue () const
 Returns a hash value for this object. More...
 
virtual bool equals (const Ref< Object > &obj) const
 Tests whether two objects are equal. More...
 
Ref< Objectclone () const
 Returns a copy of this object. More...
 

Protected Member Functions

 ThreadSafeReader ()
 
virtual ~ThreadSafeReader ()
 
- Protected Member Functions inherited from jem::Collectable
 Collectable ()
 Creates an empty Collectable. More...
 
 ~Collectable ()
 Frees resources. More...
 
- Protected Member Functions inherited from jem::Interface
virtual ~Interface ()
 Empty destructor. More...
 

Protected Attributes

Ref< Readerinput_
 
Ref< IOMutexmutex_
 

Additional Inherited Members

- Static Public Member Functions inherited from jem::Object
static ClassgetType ()
 Returns the Class instance representing the Object class. More...
 

Member Typedef Documentation

Constructor & Destructor Documentation

jem::mt::ThreadSafeReader::ThreadSafeReader ( const Ref< Reader > &  in)
explicit
jem::mt::ThreadSafeReader::ThreadSafeReader ( const Ref< Reader > &  in,
const Ref< IOMutex > &  mutex 
)
jem::mt::ThreadSafeReader::ThreadSafeReader ( const Self rhs)
jem::mt::ThreadSafeReader::ThreadSafeReader ( )
protected
virtual jem::mt::ThreadSafeReader::~ThreadSafeReader ( )
protectedvirtual

Member Function Documentation

virtual Ref<Reader> jem::mt::ThreadSafeReader::dup ( )
virtual
virtual void jem::mt::ThreadSafeReader::lock ( )
virtual

This function locks this Reader object so that only the current thread can read from the input stream. All other threads calling this function will be blocked until the current thread calls the unlock() member function.

The lock() and unlock() member functions are guaranteed to be recursive. This means that a thread may call lock() multiple times without creating a deadlock situation. Each call to lock() must be balanced by a call to unlock() to ensure that this Reader instance does not become permanently inaccessible to other threads.

The lock() function does not have to lock this object. In fact, the default implementation provided by the Reader class does nothing. It is up to you to instantiate a class derived from the Reader class that implements an appropriate locking scheme.

See also
Lock, IOMutex, ThreadSafeReader.

Reimplemented from jem::io::Reader.

virtual void jem::mt::ThreadSafeReader::unlock ( )
virtual

Unlocks this Reader object so that it can be accessed by other threads.

The default implementation provided by the Reader class does nothing.

Precondition
This object has been locked by a call to the lock() member function.

Reimplemented from jem::io::Reader.

virtual void jem::mt::ThreadSafeReader::close ( )
virtual

Closes this input stream. After calling this function, one should not attempt to read any more characters from this stream.

The default implementation provided by the Reader class does nothing.

Exceptions
IOException- if an I/O error occurs.

Reimplemented from jem::io::Reader.

virtual idx_t jem::mt::ThreadSafeReader::poll ( const Time timeout)
virtual
virtual int jem::mt::ThreadSafeReader::read ( )
virtual

Returns the next character, cast to an int, from this input stream. If the end of the stream has been reached, -1 is returned.

Returns
The next character in the input stream, or -1.
Exceptions
IOException- if an I/O error occurs.

Implements jem::io::TextInput.

virtual idx_t jem::mt::ThreadSafeReader::read ( char *  buf,
idx_t  n 
)
virtual
virtual idx_t jem::mt::ThreadSafeReader::readUntil ( char *  buf,
idx_t  n,
int  delim 
)
virtual
virtual void jem::mt::ThreadSafeReader::pushBack ( int  c)
virtual

Pushes back the character c, cast to an unsigned char, into this input stream. This character must have been previously extracted from the input stream by calling one of the read() member functions. The pushed back character will be the first character to be extracted from the input stream when one of the read() member functions is called.

Characters must be pushed back in the same order as they have been read; one is not allowed to alter the contents of the input stream.

If the character c has a negative value, this function does nothing.

Example:

void skipNumbers ( TextInput& in )
{
int c;
for ( c = in.read(); c >= 0 && isalpha(c); c = in.read() );
in.pushBack( c );
}
Parameters
c- the character to be pushed back.
Postcondition
If c is non-negative, then this->read() == c.
Exceptions
IOException- if an I/O error occurs.

Implements jem::io::TextInput.

virtual void jem::mt::ThreadSafeReader::skipUntil ( int  delim)
virtual

Reads characters from this input stream until the delimiting character delim is encountered, or until the end of the input stream has been reached. The delimiter is not extracted from the input stream.

The implementation of this function provided by the Reader class repeatedly calls the member function readUntil().

Parameters
delim- the delimiter.
Exceptions
IOException- if an I/O error occurs.

Reimplemented from jem::io::Reader.

virtual void jem::mt::ThreadSafeReader::skipWhite ( )
virtual

Extracts white space from this input stream. The implementation provided by the Reader class simply executes:

int c;
for ( c = read(); c >= 0 && isspace(c); c = read() );
pushBack( c );
Postcondition
The next character returned by the read() member function either returns -1 or a non-white space character.
Exceptions
IOException- if an I/O error occurs.

Reimplemented from jem::io::Reader.

virtual idx_t jem::mt::ThreadSafeReader::skip ( idx_t  n)
virtual

Member Data Documentation

Ref<Reader> jem::mt::ThreadSafeReader::input_
protected
Ref<IOMutex> jem::mt::ThreadSafeReader::mutex_
protected