Annotation of researchv10dc/man/mana/ios.3, revision 1.1.1.1

1.1       root        1: .  \"ident     "%W%"
                      2: .  \"Copyright (c) 1984 AT&T
                      3: .  \"All Rights Reserved
                      4: .  \"THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
                      5: .  \"The copyright notice above does not evidence any
                      6: .  \"actual or intended publication of such source code.
                      7: .TH IOSTREAM 3I+ "C++ Stream Library" " "
                      8: .SH NAME
                      9: ios \- input/output formatting
                     10: .SH SYNOPSIS
                     11: .nf
                     12: .ta1i 2i
                     13: .ft B
                     14: #include <iostream.h>
                     15: 
                     16: struct fmtinfo {
                     17:        ostream*        tie;
                     18:        short   convbase;
                     19:        short   width;
                     20:        short   precision;
                     21:        char    fill;
                     22:        char    ladjust;
                     23:        char    showbase;
                     24:        char    skip;
                     25:        char    floatfmt;
                     26: };
                     27: 
                     28: class ios {
                     29: public:
                     30:        enum    io_state { goodbit=0, eofbit, failbit, badbit };
                     31:        enum    open_mode { in, out, ate, app };
                     32:        enum    seek_dir { beg, cur, end };
                     33: public:
                     34:                ios(streambuf* b);
                     35: 
                     36:        int     bad();
                     37:        void    clear(state_value i = _good);
                     38:        int     convbase();
                     39:        void    convbase(int i);
                     40:        int     eof();
                     41:        int     fail();
                     42:        char    fill();
                     43:        void    fill(char c);
                     44:        char    floatfmt();
                     45:        void    floatfmt(char c);
                     46:        fmtinfo fmt();
                     47:        void    fmt(fmtinfo& info);
                     48:        int     ladjust();
                     49:        void    ladjust(int a);
                     50:        int     good();
                     51:        int     operator!();
                     52:                operator int();
                     53:        int     popfmt();
                     54:        int     precision();
                     55:        void    precision(int i);
                     56:        void    pushfmt();
                     57:        streambuf*      rdbuf();
                     58:        int     rdstate();
                     59:        int     showbase();
                     60:        void    showbase(int i);
                     61:        int     skip();
                     62:        int     skip(int i);
                     63:        void    sync_with_stdio();
                     64:        streampos       tellg();
                     65:        ostream*        tie();
                     66:        ostream*        tie(ostream* iosp);
                     67:        int     width();
                     68:        void    width(int i);
                     69: 
                     70:        ios&    operator<<(ios& (*)(ios&));
                     71:        ios&    operator>>(ios& (*)(ios&));
                     72: private:
                     73:                iostream(iostream&) ;
                     74:        iostream&       operator=(iostream&)    ;
                     75: };
                     76: 
                     77: class ios_withassign : ios {
                     78:                ios_withassign();
                     79:        ios&    operator=(ios&);
                     80:        ios&    operator=(streambuf*);
                     81: } ;
                     82: 
                     83: ios&   dec(ios& i) ; 
                     84: ios&   hex(ios& i) ;
                     85: ios&   oct(ios& i) ;
                     86: ios&   popfmt(ios& i) ;
                     87: ios&   pushfmt(ios& i) ;
                     88: .fi
                     89: .ft R
                     90: .SH DESCRIPTION
                     91: The stream classes derived from \f(CWios\fRs
                     92: provide a high level interface that
                     93: supports transferring
                     94: formatted and unformatted information into and out of
                     95: \f(CWstreambuf\fRs.
                     96: .PP
                     97: In the following assume:
                     98: .br
                     99: \(em \fBs\fR is an \f(CWios\fR.
                    100: .br
                    101: \(em \fBswa\fR is an \f(CWios_withassign\fR.
                    102: .br
                    103: \(em \fBsp\fR is a \f(CWios*\fR.
                    104: .br
                    105: \(em \fBi\fR and \fBn\fR are \f(CWint\fR.
                    106: .br
                    107: \(em \fBc\fR is a \f(CWchar\fR.
                    108: .br
                    109: \(em \fBosp\fR is an \f(CWostream*\fR.
                    110: .br
                    111: \(em \fBsb\fR is a \f(CWstreambuf*\fR.
                    112: .br
                    113: \(em \fBpos\fR is a \f(CWstreampos\fR.
                    114: .br
                    115: \(em \fBoff\fR is a \f(CWstreamoff\fR.
                    116: .br
                    117: \(em \fBinfo\fR is a \f(CWformatinfo\fR.
                    118: .br
                    119: \(em \fBdir\fR is a \f(CWseek_dir\fR.
                    120: .br
                    121: \(em \fBmode\fR is a \f(CWseek_dir\fR.
                    122: .br
                    123: \(em \fBfct\fR is a function with type \f(CWios& (*)(ios&)\fR.
                    124: .PP
                    125: Constructors and assignment:
                    126: .TP
                    127: \fBios(sb)\fR
                    128: \fBsb\fR becomes the \f(CWstreambuf\fR associated with the
                    129: constructed \fBios\fR.  This association is fixed for
                    130: the life of the \f(CWios\fR. If \fBsb\fR is null the effect is
                    131: undefined.
                    132: .TP
                    133: \fBios_withassign()\fR
                    134: Uninitialized variable.
                    135: .sp
                    136: .nf
                    137: .in -.5i
                    138: \fBios(ios&)\fR
                    139: \fBios=ios\fR
                    140: .in
                    141: .fi
                    142: Copying of \f(CWios\fR's is not in general
                    143: well defined and the constructor and assignment operators
                    144: are made private so that the compiler will complain about attempts to
                    145: do so.  Usually what is desired
                    146: is copying of pointers to \f(CWiostream\fRs.
                    147: .TP
                    148: swa=sb
                    149: Associates \fBsb\fR with \fBswa\fR and initializes the entire
                    150: state of
                    151: \fBswa\fR. 
                    152: .TP
                    153: swa=s
                    154: Associates \fBs->rdbuf()\fR with \fBswa\fR and
                    155: initializes the entire state of
                    156: \fBswa\fR. 
                    157: .PP
                    158: An \fBios\fR has an internal error state (which is a collection
                    159: of the bits declared as \f(CWio_state\fRs).  Members related
                    160: to the error state:
                    161: .RS
                    162: .TP
                    163: \fBi=s.rdstate()\fR
                    164: Returns the current error state.
                    165: .TP
                    166: \fBs.clear(i)\fR
                    167: Stores \fBi\fR as the error state.  If \fBi\fR is zero
                    168: this clears all bits.  To set a bit without clearing previously
                    169: set bits requires something like \fBs.clear(badbit|s.rdstate())\fR.
                    170: .TP
                    171: \fBi=s\fR
                    172: The \f(CWint\fR conversion operator is non-zero if \f(CWbadbit\fR or
                    173: \f(CWfailbit\fR is set in the error state.
                    174: .TP
                    175: \fBi=s.good()\fR
                    176: Non-zero if the error state has no bits set.
                    177: .TP
                    178: \fBi=s.eof()\fR
                    179: Non-zero if \f(CWeofbit\fR is set in the error state.  Normally this
                    180: bit is set when an end of file has been encountered doing extraction.
                    181: .TP
                    182: \fBi=s.fail()\fR
                    183: Non-zero if either \f(CWbadbit\fR or \f(CWfailbit\fR are set in the
                    184: error state.  Normally this indicates that some operation has failed.
                    185: .TP
                    186: \fBi=s.bad()\fR
                    187: Non-zero if \fBbadbit\fR is set in the error state.
                    188: Normally this indicates
                    189: that some operation on \fBs.rdbuf()\fR has failed.
                    190: .RE
                    191: .PP
                    192: An \f(CWios\fR has a collection of format state variables
                    193: that are used by input and output operations to control the
                    194: details of formatting operations.  Otherwise their values
                    195: have no particular effect and they may be set and examined arbitrarily
                    196: by user code.
                    197: .RS
                    198: .TP
                    199: \fBs.convbase(i)\fR
                    200: Sets the "conversion base" format state variable to \fBi\fR.
                    201: .TP
                    202: \fBi=s.convbase()\fR
                    203: Returns the "conversion base" format state variable.
                    204: .TP
                    205: \fBs.fill(c)\fR
                    206: Sets the "fill character" format state variable to \fBc\fR.
                    207: .TP
                    208: \fBc=s.fill()\fR
                    209: Returns the "fill character" format state variable.
                    210: .TP
                    211: \fBs.fill(c)\fR
                    212: Sets the "fill character" format state variable to \fBc\fR.
                    213: .TP
                    214: \fBc=s.fill()\fR
                    215: Returns the "fill character" format state variable.
                    216: .TP
                    217: \fBs.floatfmt(c)\fR
                    218: Sets the "floating format" format state variable to \fBc\fR.
                    219: .TP
                    220: \fBc=s.floatfmt()\fR
                    221: Returns the "floating format" format state variable.
                    222: .TP
                    223: \fBs.ladjust(i)\fR
                    224: Sets the "left adjustment" format state variable to \fBi\fR.
                    225: .TP
                    226: \fBi=s.ladjust()\fR
                    227: Returns the "left adjustment" format state variable.
                    228: .TP
                    229: \fBs.precision(i)\fR
                    230: Sets the "precision" format state variable to \fBi\fR.
                    231: .TP
                    232: \fBi=s.precision()\fR
                    233: Returns the "precision" format state variable.
                    234: .TP
                    235: \fBs.showbase(i)\fR
                    236: Sets the "show explicit base" format state variable to \fBi\fR.
                    237: .TP
                    238: \fBi=s.showbase()\fR
                    239: Returns the "show explicit base" format state variable.
                    240: .TP
                    241: \fBsp=s.skip(sp)\fR
                    242: Sets the "skip whitespace" format state variable to \fBsp\fP.
                    243: .TP
                    244: \fBsp=s.skip()\fR
                    245: Returns the "skip whitespace" format state variable.
                    246: .TP
                    247: \fBosp=s.tie(osp)\fR
                    248: Sets the "tie" format state variable \fBsp\fP.
                    249: .TP
                    250: \fBosp=s.tie()\fR
                    251: Returns the "tie" format state variable.
                    252: .TP
                    253: \fBs.width(i)\fR
                    254: Sets the "field width" format state variable to \fBi\fP.
                    255: .TP
                    256: \fBi=s.width()\fR
                    257: Returns the "field width" format state variable.
                    258: .TP
                    259: \fBs.fmt(info)\fR
                    260: Sets the collection of all format state variables to \fBinfo\fP in
                    261: a single operation.
                    262: .TP
                    263: \fBinfo=s.fmt()\fR
                    264: Returns the collection of all format state variables in
                    265: a single operation.
                    266: .TP
                    267: \fBs.pushfmt()\fR
                    268: Pushes a \f(CWformatinfo\fR structure onto a (dynamically allocated)
                    269: stack associated with \fBs\fR.  This copies the current
                    270: values of format state variables without changing them.
                    271: .TP
                    272: \fBi=s.popfmt()\fR
                    273: Pops the topmost \f(CWformatinfo\fR from the stack associated with
                    274: \fBs\fR and sets the format state variables accordingly.  Normally
                    275: \fBi\fR is non-zero, but it will be zero if the stack is empty
                    276: (i.e., more \fBpopfmt\fR than \fBpushfmt\fR operations have been
                    277: performed.
                    278: .RE
                    279: .PP
                    280: Other members:
                    281: .TP
                    282: \fBsb=s.rdbuf()\fR
                    283: Returns a pointer to the \f(CWstreambuf\fR associated with
                    284: \fBs\fR when \fBs\fR was constructed.
                    285: .TP
                    286: \fB((ios*)0)->sync_with_stdio()\fR
                    287: Solves problems that arise when mixing stdio and
                    288: iostreams.   The first time it is called it will reset the
                    289: standard iostreams (\f(CWinstream\fR, \f(CWoutstream\fR, \f(CWerrstream\fR,
                    290: \f(CWlogstream\fR) to be streams
                    291: using  \f(CWstdiobuf\fRs.
                    292: After that input and output using these streams may
                    293: be mixed with input and output using the corresponding \f(CWFILE\fRs and
                    294: will be properly synchronized.
                    295: .RE
                    296: .PP
                    297: Convenient manipulators (functions that take an \f(CWios&\fR
                    298: and return their argument).
                    299: .TP
                    300: \fBios<<dec
                    301: .in -.5i
                    302: .br
                    303: .nf
                    304: \fBios<<dec
                    305: \fBios>>dec\fR
                    306: .fi
                    307: .in
                    308: Sets the convbase to 10.
                    309: .sp
                    310: .nf
                    311: .in -.5i
                    312: \fBios<<hex
                    313: \fBios>>hex\fR
                    314: .in
                    315: Sets the convbase to 16.
                    316: .sp
                    317: .nf
                    318: .in -.5i
                    319: \fBios<<oct
                    320: \fBios>>oct\fR
                    321: .fi
                    322: .in
                    323: Sets the convbase to 8.
                    324: .sp
                    325: .nf
                    326: .in -.5i
                    327: \fBios<<popfmt
                    328: \fBios>>popfmt\fR
                    329: .fi
                    330: .in
                    331: Does \fBs.popfmt()\fR
                    332: .in -.5i
                    333: .sp
                    334: .nf
                    335: \fBios<<pushfmt
                    336: \fBios>>pushfmt\fR
                    337: .fi
                    338: .in
                    339: Does \fBs.pushfmt()\fR
                    340: .PP
                    341: The \f(CWstreambuf\fR associated with an \f(CWios\fR may be manipulated
                    342: by other methods than through \f(CWios\fR.  For example, characters may
                    343: be stored in a queuelike \f(CWstreambuf\fR through an \f(CWostream\fR
                    344: while they are being fetched through an \f(CWistream\fR.
                    345: Or for efficiency some
                    346: part of a program may choose to do \f(CWstreambuf\fR gets
                    347: directly rather than through the \f(CWios\fR.
                    348: In most cases
                    349: the program does not have to worry about this possibility, because
                    350: an \f(CWios\fR never saves information about the internal state
                    351: of a \f(CWstreambuf\fR.  For example if the \f(CWstreambuf\fR is
                    352: repostitioned between extraction operations the extraction (input) 
                    353: will proceed normally.
                    354: .SH CAVEATS
                    355: .PP
                    356: The effect of \fBios.sync_with_stdio()\fR
                    357: does not depend on \fBios\fR.
                    358: \fBsync_with_stdio\fR ought
                    359: to be a global function but it is a member of \fBiostream\fR to
                    360: avoid name space pollution.
                    361: The need for \fBsync_with_stdio\fR is a wart.  The old stream
                    362: package did this as a default, but in the iostream package
                    363: unbuffered \f(CWstdiobuf\fRs are too inefficient to be the default.
                    364: .PP
                    365: The stream package had a constructor that took a \fBFILE*\fR argument.
                    366: This is now replaced by \f(CWstdiostream\fR.
                    367: It is not declared even as an obsolete form to avoid
                    368: having \f(CWiostream.h\fR
                    369: depend on \f(CWstdio.h\fR.
                    370: .PP
                    371: The old stream package allowed copying of streams.  This is disallowed
                    372: by the iostream package.  Old code using copying can usually be
                    373: rewritten to use pointers and copy pointers.
                    374: .PP
                    375: For compatibility with the old stream package, the versions of 
                    376: .I tie
                    377: and
                    378: .I skip
                    379: that set the state variables also return the old value.
                    380: .SH SEE ALSO
                    381: IOS.INTRO(3C++)
                    382: streambuf(3C++)
                    383: istream(3C++)
                    384: ostream(3C++)

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.