|
More on ylmm::basic_bufferThe class ylmm::basic_buffer is an "Abstract base class" (ABC) for various kinds of input buffers.It's interface is quite simple. The thing to notice about ylmm::basic_buffer is the member function ylmm::basic_buffer::input and the pure virtual member functions ylmm::basic_buffer::input_buffered and ylmm::basic_buffer::input_interactive - at a minimum, these later two must overloaded in a derived class. ylmm::basic_buffer::input is the member function responsible for reading characters into the Flex generated C function. Depending on wether the scanner was defined as interactive or buffered, the member function will deligate the call to one of the virtual member functions ylmm::basic_buffer::input_buffered or ylmm::basic_buffer::input_interactive. Hence, the derived class should overload ylmm::basic_buffer::input_buffered to read as much as possible into an internal buffer, while ylmm::basic_buffer::input_interactive should read up to a newline and no more, immediately returning the result.
The basic class reads input from an my_scanner scanner(new ylmm::istream_buffer(std::cin));
Another common applicatin is to read from a file via std::ifstream input_file("input_file.txt"); my_scanner scanner(new ylmm::istream_buffer(input_file));
But one can easily make more exotic variations. Suppose you have a class std::istream input(new read_line::streambuf("prompt> "); ylmm::istream_buffer buffer(input); buffer.interactive(true); my_scanner scanner(&buffer);
At first, as well as reading the ISO/IEC C++ standard, you may be left with the impression that the Christian Holm (home page) Last update Fri Jul 8 12:58:03 2005 Created by DoxyGen 1.4.3-20050530 |