YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
yarp::os::StringInputStream Class Reference

An InputStream that reads from a string. More...

#include <yarp/os/StringInputStream.h>

+ Inheritance diagram for yarp::os::StringInputStream:

Public Member Functions

 StringInputStream ()
 
void reset ()
 
void reset (const std::string &str)
 
void add (const std::string &txt)
 
void add (const Bytes &b)
 
yarp::conf::ssize_t read (Bytes &b) override
 Read a block of data from the stream.
 
void close () override
 Terminate the stream.
 
virtual std::string toString () const
 
bool isOk () const override
 Check if the stream is ok or in an error state.
 
virtual int read ()
 Read and return a single byte.
 
virtual yarp::conf::ssize_t read (Bytes &b, size_t offset, yarp::conf::ssize_t len)
 Read a block of data from the stream.
 
virtual yarp::conf::ssize_t read (yarp::os::Bytes &b)=0
 Read a block of data from the stream.
 
- Public Member Functions inherited from yarp::os::InputStream
 InputStream ()
 Constructor.
 
virtual ~InputStream ()
 Destructor.
 
virtual void check ()
 Perform maintenance actions, if needed.
 
virtual yarp::conf::ssize_t partialRead (yarp::os::Bytes &b)
 Like read, but solicit partial responses.
 
virtual void interrupt ()
 Interrupt the stream.
 
virtual bool setReadTimeout (double timeout)
 Set activity timeout.
 
std::string readLine (const char terminal='\n', bool *success=nullptr)
 Read a block of text terminated with a specific marker (or EOF).
 
yarp::conf::ssize_t readFull (Bytes &b)
 Keep reading until buffer is full.
 
yarp::conf::ssize_t readDiscard (size_t len)
 Read and discard a fixed number of bytes.
 
virtual bool setReadEnvelopeCallback (readEnvelopeCallbackType callback, void *data)
 Install a callback that the InputStream will have to call when the envelope is read from a message in carriers that cannot be escaped.
 

Additional Inherited Members

- Public Types inherited from yarp::os::InputStream
typedef void(* readEnvelopeCallbackType) (void *, const yarp::os::Bytes &envelope)
 Callback type for setting the envelope from a message in carriers that cannot be escaped.
 

Detailed Description

An InputStream that reads from a string.

Handy For testing purposes.

Definition at line 20 of file StringInputStream.h.

Constructor & Destructor Documentation

◆ StringInputStream()

yarp::os::StringInputStream::StringInputStream ( )
inline

Definition at line 25 of file StringInputStream.h.

Member Function Documentation

◆ add() [1/2]

void yarp::os::StringInputStream::add ( const Bytes b)
inline

Definition at line 48 of file StringInputStream.h.

◆ add() [2/2]

void yarp::os::StringInputStream::add ( const std::string &  txt)
inline

Definition at line 43 of file StringInputStream.h.

◆ close()

void yarp::os::StringInputStream::close ( )
inlineoverridevirtual

Terminate the stream.

Implements yarp::os::InputStream.

Definition at line 70 of file StringInputStream.h.

◆ isOk()

bool yarp::os::StringInputStream::isOk ( ) const
inlineoverridevirtual

Check if the stream is ok or in an error state.

Returns
true iff the stream is ok

Implements yarp::os::InputStream.

Definition at line 79 of file StringInputStream.h.

◆ read() [1/4]

int InputStream::read ( )
virtual

Read and return a single byte.

Should block and wait for data. By default, this calls read(Bytes& b) to do its work.

Returns
a byte from the stream (0-255), or -1 on failure.

Reimplemented from yarp::os::InputStream.

Definition at line 50 of file InputStream.cpp.

◆ read() [2/4]

yarp::conf::ssize_t yarp::os::StringInputStream::read ( Bytes b)
inlineoverridevirtual

Read a block of data from the stream.

Should block and wait for data.

Parameters
b[out]the block of data to read to
Returns
the number of bytes read, or -1 upon error

Implements yarp::os::InputStream.

Definition at line 55 of file StringInputStream.h.

◆ read() [3/4]

yarp::conf::ssize_t InputStream::read ( Bytes b,
size_t  offset,
yarp::conf::ssize_t  len 
)
virtual

Read a block of data from the stream.

Should block and wait for data. By default, this calls read(Bytes& b) to do its work.

Parameters
[out]bthe block of data to read to
offsetan offset within the block to start at
lenthe number of bytes to read
Returns
the number of bytes read, or -1 upon error

Reimplemented from yarp::os::InputStream.

Definition at line 63 of file InputStream.cpp.

◆ read() [4/4]

virtual yarp::conf::ssize_t yarp::os::InputStream::read ( yarp::os::Bytes b)
virtual

Read a block of data from the stream.

Should block and wait for data.

Parameters
b[out]the block of data to read to
Returns
the number of bytes read, or -1 upon error

Implements yarp::os::InputStream.

◆ reset() [1/2]

void yarp::os::StringInputStream::reset ( )
inline

Definition at line 31 of file StringInputStream.h.

◆ reset() [2/2]

void yarp::os::StringInputStream::reset ( const std::string &  str)
inline

Definition at line 37 of file StringInputStream.h.

◆ toString()

virtual std::string yarp::os::StringInputStream::toString ( ) const
inlinevirtual

Definition at line 74 of file StringInputStream.h.


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