Annotation of GNUtools/libg++/libio/strstream.cc, revision 1.1

1.1     ! root        1: /* This is part of libio/iostream, providing -*- C++ -*- input/output.
        !             2: Copyright (C) 1993 Free Software Foundation
        !             3: 
        !             4: This file is part of the GNU IO Library.  This library is free
        !             5: software; you can redistribute it and/or modify it under the
        !             6: terms of the GNU General Public License as published by the
        !             7: Free Software Foundation; either version 2, or (at your option)
        !             8: any later version.
        !             9: 
        !            10: This library is distributed in the hope that it will be useful,
        !            11: but WITHOUT ANY WARRANTY; without even the implied warranty of
        !            12: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        !            13: GNU General Public License for more details.
        !            14: 
        !            15: You should have received a copy of the GNU General Public License
        !            16: along with GNU CC; see the file COPYING.  If not, write to
        !            17: the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
        !            18: 
        !            19: As a special exception, if you link this library with files
        !            20: compiled with a GNU compiler to produce an executable, this does not cause
        !            21: the resulting executable to be covered by the GNU General Public License.
        !            22: This exception does not however invalidate any other reasons why
        !            23: the executable file might be covered by the GNU General Public License. */
        !            24: 
        !            25: /* Written by Per Bothner ([email protected]). */
        !            26: 
        !            27: #ifdef __GNUG__
        !            28: #pragma implementation
        !            29: #endif
        !            30: #include "iostreamP.h"
        !            31: #include "strstream.h"
        !            32: #include <string.h>
        !            33: 
        !            34: static void* default_alloc(_IO_size_t size)
        !            35: {
        !            36:     return (void*)new char[size];
        !            37: }
        !            38: 
        !            39: static void default_free(void* ptr)
        !            40: {
        !            41:     delete [] (char*)ptr;
        !            42: }
        !            43: 
        !            44: /* Set to use the _IO_str_jump jumptable, for efficiency */
        !            45: 
        !            46: #define SET_STR_JUMPS(STRBUF) \
        !            47:   (STRBUF)->_jumps = &_IO_str_jumps,\
        !            48:   (STRBUF)->_vtable() = NULL;
        !            49: 
        !            50: istrstream::istrstream(const char *cp, int n)
        !            51: {
        !            52:   init(new strstreambuf(cp, n));
        !            53:   SET_STR_JUMPS(_strbuf);
        !            54: }
        !            55: 
        !            56: ostrstream::ostrstream()
        !            57: {
        !            58:   init(new strstreambuf());
        !            59:   SET_STR_JUMPS(_strbuf);
        !            60: }
        !            61: 
        !            62: strstreambase::strstreambase(char *cp, int n, int mode)
        !            63: {
        !            64:   char *pstart;
        !            65:   if (mode == ios::app || mode == ios::ate)
        !            66:     pstart = cp + strlen(cp);
        !            67:   else
        !            68:     pstart = cp;
        !            69:   init(new strstreambuf(cp, n, pstart));
        !            70:   SET_STR_JUMPS(_strbuf);
        !            71: }
        !            72: 
        !            73: char *strstreambuf::str()
        !            74: {
        !            75:     freeze(1);
        !            76:     return base();
        !            77: }
        !            78: 
        !            79: _IO_ssize_t strstreambuf::pcount() { return _IO_str_count (this); }
        !            80: 
        !            81: int strstreambuf::overflow(int c /* = EOF */)
        !            82: {
        !            83:   return _IO_str_overflow (this, c);
        !            84: }
        !            85: 
        !            86: int strstreambuf::underflow()
        !            87: {
        !            88:   return _IO_str_underflow(this);
        !            89: }
        !            90: 
        !            91: 
        !            92: void strstreambuf::init_dynamic(_IO_alloc_type alloc, _IO_free_type free,
        !            93:                                int initial_size)
        !            94:                                
        !            95: {
        !            96:     _s._len = 0;
        !            97:     if (initial_size < 16)
        !            98:        initial_size = 16;
        !            99:     _s._allocate_buffer = alloc ? alloc : default_alloc;
        !           100:     _s._free_buffer = free ? free : default_free;
        !           101:     char * buf = (char*)(*_s._allocate_buffer)(initial_size);
        !           102:     setb(buf, buf + initial_size, 1);
        !           103:     setp(buf, buf + initial_size);
        !           104:     setg(buf, buf, buf);
        !           105: }
        !           106: 
        !           107: void strstreambuf::init_static(char *ptr, int size, char *pstart)
        !           108: {
        !           109:   _IO_str_init_static (this, ptr, size, pstart);
        !           110: }
        !           111: 
        !           112: void strstreambuf::init_readonly (const char *ptr, int size)
        !           113: {
        !           114:   _IO_str_init_readonly (this, ptr, size);
        !           115: }
        !           116: 
        !           117: strstreambuf::~strstreambuf()
        !           118: {
        !           119:     if (_IO_buf_base && !(_flags & _IO_USER_BUF))
        !           120:         (_s._free_buffer)(_IO_buf_base);
        !           121:     _IO_buf_base = NULL;
        !           122: }
        !           123: 
        !           124: streampos strstreambuf::seekoff(streamoff off, _seek_dir dir,
        !           125:                                        int mode /*=ios::in|ios::out*/)
        !           126: {
        !           127:   return _IO_str_seekoff (this, off, convert_to_seekflags(dir, mode));
        !           128: }
        !           129: 
        !           130: int strstreambuf::pbackfail(int c)
        !           131: {
        !           132:   return _IO_str_pbackfail (this, c);
        !           133: }

unix.superglobalmegacorp.com

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