tobicore  7.0.0
 All Classes Functions Variables Typedefs Enumerator Friends Groups Pages
TPStreamer Class Reference

Utility class to handle data streams. More...

#include <tobiplatform/TPStreamer.hpp>

+ Collaboration diagram for TPStreamer:

Public Member Functions

 TPStreamer (void)
 Constructor.
virtual ~TPStreamer (void)
 Destructor.
virtual void Append (std::string buffer)
 Appends a string to the streamer.
virtual void Append (const char *buffer, size_t bsize)
 Appends a char array to the streamer.
virtual bool Extract (std::string *buffer, std::string hdr, std::string trl, TPStreamerDirection direction=TPStreamer::Forward)
 Extracts a message from the streamer.
virtual bool Has (std::string hdr, std::string trl, TPStreamerDirection direction=TPStreamer::Forward)
 Searches the streamer for a message.
virtual int Count (std::string hdr)
 Count the number of messages given one header.
virtual void Dump (void)
 Prints contents.
virtual int Size (void)
 Returns size in bytes.
virtual void Clear (void)
 Clears the streamer.

Static Public Attributes

static const TPStreamerDirection Forward = 0
 Search forward (FIFO)
static const TPStreamerDirection Reverse = 1
 Search reverse (LIFO)

Detailed Description

Utility class to handle data streams.

This class is designed to allow an easy handling of the data streams received from a TCP connection (but not only). It allows to verify whether a certain message is present and to extract it automatically.

Definition at line 38 of file TPStreamer.hpp.

Member Function Documentation

void TPStreamer::Append ( std::string  buffer)
virtual

Appends a string to the streamer.

  • buffer The string to append

Definition at line 33 of file TPStreamer.cpp.

+ Here is the caller graph for this function:

void TPStreamer::Append ( const char *  buffer,
size_t  bsize 
)
virtual

Appends a char array to the streamer.

  • buffer The char array to append

Definition at line 39 of file TPStreamer.cpp.

int TPStreamer::Count ( std::string  hdr)
virtual

Count the number of messages given one header.

  • hdr The header that identifies the messages
    Returns
    Number of messages

Definition at line 102 of file TPStreamer.cpp.

bool TPStreamer::Extract ( std::string *  buffer,
std::string  hdr,
std::string  trl,
TPStreamerDirection  direction = TPStreamer::Forward 
)
virtual

Extracts a message from the streamer.

Searches for a message (given a direction, i.e. FIFO or LIFO) contained between an header and a trailer and extracts it.

  • buffer Extracted message
  • hdr Header (i.e. "<msg>")
  • trl Trailer (i.e. "</msg>")
  • direction FIFO or LIFO
    Returns
    True if message was first found and then extracted, false otherwise

Definition at line 45 of file TPStreamer.cpp.

+ Here is the caller graph for this function:

bool TPStreamer::Has ( std::string  hdr,
std::string  trl,
TPStreamerDirection  direction = TPStreamer::Forward 
)
virtual

Searches the streamer for a message.

Searches for a message (given a direction, i.e. FIFO or LIFO) contained between an header and a trailer and extracts it.

  • hdr Header (i.e. "<msg>")
  • trl Trailer (i.e. "</msg>")
  • direction FIFO or LIFO
    Returns
    True if message was found, false otherwise

Definition at line 93 of file TPStreamer.cpp.

int TPStreamer::Size ( void  )
virtual

Returns size in bytes.

Returns
Bytes

Definition at line 128 of file TPStreamer.cpp.


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