File: overunder.yo

package info (click to toggle)
c%2B%2B-annotations 13.02.02-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,576 kB
  • sloc: cpp: 25,297; makefile: 1,523; ansic: 165; sh: 126; perl: 90; fortran: 27
file content (55 lines) | stat: -rw-r--r-- 2,773 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
The member tt(overflow) is called then the stream's write buffer is empty or
exhausted. The member tt(underflow) is called then the stream's read buffer is
empty or exhausted.

In both cases a new buffer (from tt(bufBeg) to tt(bufEnd)) is computed
containing tt(offset). But tt(offset) depends on the streambuf's state. When
called in the tt(SEEK) state tt(offset) is up-to-date; when called in the
tt(WRITE) state the offset is at the last-used write offset; when called in
the tt(READ) state the current offset is at the end of the current read
buffer. 

When called in the tt(SEEK) state the read and write buffers are already
empty. When called in the tt(READ) state the actual offset is determined and
the read buffer is reset to ensure that tt(underflow) is called at the next
read operation.

Likewise, when called in the tt(WRITE) state the write buffer is reset to
ensure that tt(overflow) is called at the next write request. 

Both tt(underflow) and tt(overflow) therefore start by determining the current
offset, computing the corresponding buffer boundaries. The member tt(getOffset)
is called by both tt(underflow) and tt(overflow). Here's its skeleton
implementation: 
    verbinclude(-a examples/getoffset.cc)

The member tt(bufLimits) simply ensures that tt(offset) is located inside a
buffer: 
    verbinclude(-a examples/buflimits.cc)

The member tt(overflow) returns tt(EOF) or initializes a new read
buffer. Since tt(overflow) is guaranteed to be called when writing is
requested from states tt(SEEK) and tt(READ) it calls tt(getOffset) to obtain
the current absolute offset and the corresponding tt(bufBeg) en tt(bufEnd)
values. Writing can only be used if tt(offset < maxEnd). If so, a new write
buffer is installed whose tt(pptr()) points at the tt(offset) position in the
physical device. After calling tt(setp) tt(overflow) em(must) return tt(ch) on
success. Here's tt(overflow's) skeleton:
    verbinclude(-a examples/overflow.cc)

The member tt(underflow) returns tt(EOF) or initializes a new read
buffer. Since tt(underflow) is guaranteed to be called when reading is
requested from states tt(SEEK) and tt(WRITE) it calls, like tt(overflow),
tt(getOffset) to obtain the current absolute offset as well as the
matching tt(bufBeg) en tt(bufEnd) values. Reading can only be used if
tt(offset < getEnd). If so, a new read buffer is installed whose tt(gptr())
points at the tt(offset) position in the physical device.

As with tt(overflow), after calling tt(setg) it's em(essential) that the first
available character (i.e., tt(*gptr())) is returned. If not and the buffer
contains just one character then that character might not be processed by
tt(underflow's) caller. Here's tt(underflow's) skeleton:
    verbinclude(-a examples/underflow.cc)