libcwd: The C++ Debugging Support Library - Reference Manual
Author: Carlo Wood
Description: C++ debugging support library with ostream debug output
Keywords: libcwd, debug output, debug facility, debug channel, object orientation, OO, C++, nested debug output, ostream, memory allocation, debugging, source file and line number

Main Page Reference Manual Namespace List Compound List Namespace Members Compound Members File Members

# libcwd/private_bufferstream.h

Go to the documentation of this file.

    00001 // $Header$
    00002 //
    00003 // Copyright (C) 2003 - 2004, by
    00004 //
    00005 // Carlo Wood, Run on IRC <carlo@alinoe.com>
    00006 // RSA-1024 0x624ACAD5 1997-01-26                    Sign & Encrypt
    00007 // Fingerprint16 = 32 EC A7 B6 AC DB 65 A6  F6 F6 55 DD 1C DC FF 61
    00008 //
    00009 // This file may be distributed under the terms of the Q Public License
    00010 // version 1.0 as appearing in the file LICENSE.QPL included in the
    00011 // packaging of this file.
    00012 //
    00013
    00018 #ifndef LIBCWD_PRIVATE_BUFFERSTREAM_H
    00019 #define LIBCWD_PRIVATE_BUFFERSTREAM_H
    00020
    00021 #ifndef LIBCWD_CONFIG_H
    00022 #include <libcwd/config.h>
    00023 #endif
    00024
    00025 namespace libcwd {
    00026   namespace _private_ {
    00027
    00028     // This is a pseudo stringstream with auto_internal_allocator
    00029     // that allows to change the stringbuf on the fly.
    00030     class bufferstream_ct : public std::ostream
    00031     {
    00032     public:
    00033       typedef char char_type;
    00034       typedef std::char_traits<char> traits_type;
    00035 #if CWDEBUG_ALLOC
    00036       typedef auto_internal_allocator allocator_type;
    00037 #else
    00038       typedef ::std::allocator<char_type> allocator_type;
    00039 #endif
    00040       typedef traits_type::int_type int_type;
    00041       typedef traits_type::pos_type pos_type;
    00042       typedef traits_type::off_type off_type;
    00043       typedef std::basic_string<char_type, traits_type, allocator_type> string_type;
    00044       typedef std::basic_stringbuf<char_type, traits_type, allocator_type> stringbuf_type;
    00045
    00046     public:
    00047       stringbuf_type* M_stringbuf;
    00048
    00049     public:
    00050       explicit
    00051       bufferstream_ct(stringbuf_type* sb) : std::basic_ostream<char, std::char_traits<char> >(sb), M_stringbuf(sb) { }
    00052       ~bufferstream_ct() { }
    00053
    00054       stringbuf_type* rdbuf(void) const { return M_stringbuf; }
    00055       string_type str(void) const { return M_stringbuf->str(); }
    00056       void str(string_type const& s) { M_stringbuf->str(s); }
    00057     };
    00058
    00059   } // namespace _private_
    00060 } // namespace libcwd
    00061
    00062 #endif // LIBCWD_PRIVATE_BUFFERSTREAM_H