File: seekoff.cc

package info (click to toggle)
bobcat 6.11.00-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 15,292 kB
  • sloc: cpp: 21,370; fortran: 6,507; makefile: 2,787; sh: 724; perl: 401; ansic: 26
file content (55 lines) | stat: -rw-r--r-- 1,633 bytes parent folder | download
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
#define XERR "memorybuf"
#include "memorybuf.ih"

// overrides
ios::pos_type MemoryBuf::seekoff(
                ios::off_type step, ios::seekdir way, ios::openmode mode)
{
    off_type offset;

    switch (way)
    {
        default:                        // ios::beg: buffOffset is step
            offset = step;
        break;

        case ios::cur:
            switch (d_last)
            {
                                        // default: case SEEK
                default:                // no read/write used so far
                    offset = d_bridge.offset();
                break;                  // add step to bufOffset (below)

                case READ:              // setg was used, set bufOffset to
                                        // the abs offset of gptr()
                    offset = d_bridge.blockBegin() + gptr() - eback();
                break;

                case WRITE:             // setp was used, set bufOffset to
                                        // the abs offset of pptr()
                    offset =  d_bridge.blockBegin() + pptr() - pbase();
                    d_bridge.writtenUntil(offset);
                break;
            }

            offset += step;          // add the step
        break;

        case ios::end:                  // shift from the last write position
            offset = d_bridge.writtenUntil() + step;  
        break;
    }

    if (offset < 0)
        offset = 0;                     // offset always >= 0

    d_last = SEEK;

    noBuffers();

    d_bridge.offset(offset);
    return offset;                      // the updated offset
}