|
rlmm::basic_streambuf< Lock > Struct Template Reference#include <rlmm/streambuf.hh>
Inheritance diagram for rlmm::basic_streambuf< Lock >:
[legend]Collaboration diagram for rlmm::basic_streambuf< Lock >:
[legend]List of all members.
Detailed Description
template<typename Lock = single_thread>
struct rlmm::basic_streambuf< Lock >
Stream buffer reading from readline.
Using this stream buffer layer, you can use a standard std::istream to read lines from the via readline.
Internally, the buffer uses the global instance of rlmm::readline, as it really makes the code simpler.
- Note:
- This stream buffer always returns the newline from readline. If it didn't, you'd never know when one line start and one ends. This requries a bit more bookkeeping but is worth the effort.
- Example
- Below is shown an example of using this class template.
namespace examples
{
class streamer
{
private:
std::istream _in;
public:
streamer() : _in(new rlmm::streambuf("streamer> ")) {}
void do_char() {
char c; while((_in >> noskipws >> c)) cout << c;
cout << flush;
}
void do_string() {
string s; while((_in >> s)) cout << s << flush; }
void do_get() {
char g;
while((g = _in.get()) != EOF) cout << g;
Member Typedef Documentation
Constructor & Destructor Documentation
template<typename Lock> |
rlmm::basic_streambuf< Lock >::basic_streambuf |
( |
const std::string & |
prompt = std::string() , |
|
|
bool |
use_history = true , |
|
|
char * |
buf = 0 , |
|
|
std::streamsize |
n = 0 |
|
) |
[inline] |
|
|
Constructor.
Allocates a new stream buffer reading via readline. - Parameters:
-
| prompt | The prompt to display. |
| use_history | Whether to use history |
| buf | externally allocated buffer for buffered reads. If this is zero, the reading will not be buffered. |
| n | Size of the externally allocated buffer. |
|
Member Function Documentation
template<typename Lock> |
bool rlmm::basic_streambuf< Lock >::internal_read |
( |
|
) |
[inline, protected, virtual] |
|
|
Read a line via readline and store it.
This member uses the C library readline function to read a line from the input. - Returns:
- true if a non-empty line was read, false otherwise.
|
|
Put back a character in the buffer.
If we're at the begining of line read, expand the buffer at start and insert c there; otherwise, simply back up one character in the read line. - Parameters:
-
| c | the character to put back. |
- Returns:
- EOF in case of errors.
c otherwise.
|
template<typename Lock = single_thread> |
virtual const std::string& rlmm::basic_streambuf< Lock >::prompt |
( |
|
) |
const [inline, virtual] |
|
template<typename Lock = single_thread> |
virtual std::string& rlmm::basic_streambuf< Lock >::prompt |
( |
const std::string & |
p |
) |
[inline, virtual] |
|
|
Set the prompt.
- Parameters:
-
|
template<typename Lock = single_thread> |
virtual int_type rlmm::basic_streambuf< Lock >::showmanyc |
( |
|
) |
const [inline, protected, virtual] |
|
|
Return the number of characters avaliable in internal buffer.
- Returns:
- # of characters avaliable in input sequence.
|
|
Return next character from input sequence.
Returns next character from pending sequence and pushes it back to on read sequence. - Returns:
- pending character.
|
|
Return next pending character.
If the sequence is empty, read a new line from terminal. If this again results in an empty line, repeat. - Returns:
- pending character in sequence.
|
template<typename Lock> |
std::streamsize rlmm::basic_streambuf< Lock >::xsgetn |
( |
char_type * |
buf, |
|
|
std::streamsize |
n |
|
) |
[inline, protected, virtual] |
|
|
Get a number of characters from sequence.
Get a block of characters from the input sequence, and put them in the passed buffer buf which is of size n . The maximum of n or # of pending characters are read into the passed buffer. The iterators are updated accordingly. - Parameters:
-
| buf | the buffer to read into. |
| n | the size of the buffer buf . |
- Returns:
- # of copied characters.
|
Member Data Documentation
|
Current pending point in buffer Pointer into sequence, marking the start of avaliable characters.
|
|
The line read from readline (the sequence).
|
The documentation for this struct was generated from the following file:
Top of page
Last update Fri Aug 26 15:19:53 2005
Christian Holm
Created by DoxyGen 1.4.4
|