ostream_wrapper.cc

Go to the documentation of this file.
00001 /*
00002    The lestes compiler suite
00003    Copyright (C) 2002, 2003, 2004, 2005 Miroslav Tichy
00004    Copyright (C) 2002, 2003, 2004, 2005 Petr Zika
00005    Copyright (C) 2002, 2003, 2004, 2005 Vojtech Hala
00006    Copyright (C) 2002, 2003, 2004, 2005 Jiri Kosina
00007    Copyright (C) 2002, 2003, 2004, 2005 Pavel Sanda
00008    Copyright (C) 2002, 2003, 2004, 2005 Jan Zouhar
00009    Copyright (C) 2002, 2003, 2004, 2005 Rudolf Thomas
00010 
00011    This program is free software; you can redistribute it and/or modify
00012    it under the terms of the GNU General Public License as published by
00013    the Free Software Foundation; version 2 of the License.
00014 
00015    This program is distributed in the hope that it will be useful,
00016    but WITHOUT ANY WARRANTY; without even the implied warranty of
00017    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018    GNU General Public License for more details.
00019 
00020    See the full text of the GNU General Public License version 2, and
00021    the limitations in the file doc/LICENSE.
00022 
00023    By accepting the license the licensee waives any and all claims
00024    against the copyright holder(s) related in whole or in part to the
00025    work, its use, and/or the inability to use it.
00026  
00027  */
00028 /*! \file
00029   \brief Wrapper for ostream.
00030   
00031   Definition of ostream_wrapper class wrapping ostream object.
00032   \author pt
00033 */
00034 #include <lestes/common.hh>
00035 #include <lestes/std/ostream_wrapper.hh>
00036 #include <ostream>
00037 
00038 package(lestes);
00039 package(std);
00040 
00041 using namespace ::std;
00042 
00043 /*!
00044   Creates the wrapper.
00045   \pre a_stream != NULL
00046   \param a_stream  The stream to wrap.
00047   \param a_owned  The ownership flag.
00048 */
00049 ostream_wrapper::ostream_wrapper(stream_type a_stream, bool a_owned):
00050         stream(checked(a_stream)),
00051         owned(a_owned)
00052 {
00053 }
00054 
00055 /*!
00056   Finalizes the object.
00057   Releases the stream if owned.
00058 */
00059 ostream_wrapper::~ostream_wrapper(void)
00060 {
00061         release();
00062 }
00063 
00064 /*!
00065   Releases the stream if it was owned.
00066   \post stream_get() == NULL
00067 */
00068 void ostream_wrapper::release(void)
00069 {
00070         if (owned) delete stream;
00071         // set to NULL anyway
00072         stream = NULL;
00073 }
00074 
00075 /*!
00076   Returns the ownership.
00077   \return true  If the stream is owned by the wrapper.
00078 */
00079 bool ostream_wrapper::owned_get(void) const
00080 {
00081         return owned;
00082 }
00083 
00084 /*!
00085   Returns the wrapped stream.
00086   \pre release() was not called (stream_get() != NULL)
00087   \return The stream.
00088 */
00089 ostream_wrapper::stream_type ostream_wrapper::stream_get(void) const
00090 {
00091         lassert2(stream,"The stream is invalid because release() was already called.");
00092         return stream;
00093 }
00094 
00095 /*!
00096   Creates the wrapper.
00097   \pre a_stream != NULL
00098   \pre a_stream is allocated via new when a_owned is true
00099   \param a_stream  The stream to wrap.
00100   \param a_owned  The ownership flag.
00101   \return The new wrapper of a_stream.
00102 */
00103 ptr<ostream_wrapper> ostream_wrapper::create(stream_type a_stream, bool a_owned)
00104 {
00105         return new ostream_wrapper(a_stream,a_owned);
00106 }
00107 
00108 end_package(std);
00109 end_package(lestes);
00110 
00111 /* vim: set ft=lestes : */

Generated on Mon Feb 12 18:22:45 2007 for lestes by doxygen 1.5.1-20070107