File: protectedoutput.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 (88 lines) | stat: -rw-r--r-- 4,336 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
The following  protected members are available for output
operations. Again, some members may be overridden by derived classes:
    itemization(
    ithtq(overflow)
        (virtual int overflow(int c))
       (This member function may be overridden by derived classes to flush the
        characters currently stored in the output buffer to the output device,
        and then to reset the output buffer pointers so as to represent an
        empty buffer. Its parameter tt(c) is initialized to the next character
        to be processed. If no output buffering is used tt(overflow) is called
        for every single character that is written to the tt(streambuf)
        object. No output buffering is accomplished by setting the buffer
        pointers (using, tt(setp), see below) to 0. The
        i(default implementation) returns endOfFile(), indicating that no
        characters can be written to the device.

        Classes derived from tt(streambuf) for writing normally at least
        override tt(overflow). The prototypical example of an overridden
        tt(overflow) function looks like this (see also section
        ref(IOSTREAMBUF)):
 verb(int OFdStreambuf::overflow(int c)
{
    sync();                             // flush the buffer
    if (c != EOF)                       // write a character?
    {
        *pptr() = static_cast<char>(c); // put it into the buffer
        pbump(1);                       // advance the buffer's pointer
    }
    unsigned char ch = c;
    return ch;
})

)
    ithtq(pbase)
        (char *pbase())
       (tt(Streambuf) maintains three pointers controlling its output buffer:
        tt(pbase) points to the beginning of the output buffer area. See also
        figure ref(SBBUFFERS).)
    ithtq(pptr)
        (char *epptr())
       (tt(Streambuf) maintains three pointers controlling its output buffer:
        tt(epptr) points just beyond the output buffer's last available
        location. See also figure ref(SBBUFFERS). If tt(pptr) (see below)
        equals tt(epptr) the buffer must be flushed. This is implemented by
        calling tt(overflow), see before.)
    ithtq(pbump)
        (void pbump(int n))
       (The location returned by tt(pptr) (see below) is advanced by tt(n)
        positions. The next character will be written at that location.)
    ithtq(pptr)
        (char *pptr())
       (tt(Streambuf) maintains three pointers controlling its output buffer:
        tt(pptr) points to the location in the output buffer where the next
        available character will be written (note that in order to write a
        character tt(pptr()) must point to a location in the range tt(pbase())
        to tt(epptr())). See also figure ref(SBBUFFERS).)
    ithtq(setp)
        (void setp(char *beg, char *beyond))
       (tt(Streambuf)'s output buffer is initialized to the locations passed
        to tt(setp). tt(Beg) points to the beginning of the output buffer and
        tt(beyond) points just beyond the last available location of the
        output buffer. Use tt(setp(0, 0)) to indicate that i(no buffering)
        should be used. In that case tt(overflow) is called for every single
        character to be written to the device.)
    ithtq(xsputn)
        (virtual streamsize xsputn(char const *buffer, streamsize n))
       (This member function may be overridden by derived classes to write a
        series of at most tt(n) characters to the output buffer. The actual
        number of inserted characters is returned. If endOfFile() is returned
        writing to the device stops. The default implementation calls
        tt(sputc) for each individual character. Redefine this member if,
        e.g., the tt(streambuf) should support the tt(ios::openmode ios::app).
        Assuming the class tt(MyBuf), derived from tt(streambuf), features a
        data member tt(ios::openmode d_mode) (representing the requested
        tt(ios::openmode)), and a member tt(write(char const *buf, streamsize
        len)) (writing tt(len) bytes at tt(pptr())), then the following code
        acknowledges the tt(ios::app) mode (see also section
        ref(IOSTREAMBUF)):
 verb(std::streamsize MyStreambuf::xsputn(char const *buf, std::streamsize len)
{
    if (d_openMode & ios::app)
        seekoff(0, ios::end);

    return write(buf, len);
})

)
    )