FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

prefixOSstream.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software: you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
00023 
00024 \*---------------------------------------------------------------------------*/
00025 
00026 #include "prefixOSstream.H"
00027 #include <OpenFOAM/Pstream.H>
00028 #include <OpenFOAM/token.H>
00029 
00030 // * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * * //
00031 
00032 inline void Foam::prefixOSstream::checkWritePrefix()
00033 {
00034     if (printPrefix_ && prefix_.size())
00035     {
00036         OSstream::write(prefix_.c_str());
00037         printPrefix_ = false;
00038     }
00039 }
00040 
00041 
00042 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00043 
00044 Foam::prefixOSstream::prefixOSstream
00045 (
00046     ostream& os,
00047     const string& name,
00048     streamFormat format,
00049     versionNumber version,
00050     compressionType compression
00051 )
00052 :
00053     OSstream(os, name, format, version, compression),
00054     printPrefix_(true),
00055     prefix_("")
00056 {}
00057 
00058 
00059 // * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * * //
00060 
00061 void Foam::prefixOSstream::print(Ostream& os) const
00062 {
00063     os  << "prefixOSstream ";
00064     OSstream::print(os);
00065 }
00066 
00067 
00068 Foam::Ostream& Foam::prefixOSstream::write(const token&)
00069 {
00070     return *this;
00071 }
00072 
00073 
00074 Foam::Ostream& Foam::prefixOSstream::write(const char c)
00075 {
00076     checkWritePrefix();
00077     OSstream::write(c);
00078 
00079     if (c == token::NL)
00080     {
00081         printPrefix_ = true;
00082     }
00083 
00084     return *this;
00085 }
00086 
00087 
00088 Foam::Ostream& Foam::prefixOSstream::write(const char* str)
00089 {
00090     checkWritePrefix();
00091     OSstream::write(str);
00092 
00093     size_t len = strlen(str);
00094     if (len && str[len-1] == token::NL)
00095     {
00096         printPrefix_ = true;
00097     }
00098 
00099     return *this;
00100 }
00101 
00102 
00103 Foam::Ostream& Foam::prefixOSstream::write(const word& val)
00104 {
00105     checkWritePrefix();
00106     return OSstream::write(val);
00107 }
00108 
00109 
00110 Foam::Ostream& Foam::prefixOSstream::write(const string& val)
00111 {
00112     checkWritePrefix();
00113     return OSstream::write(val);
00114 }
00115 
00116 
00117 Foam::Ostream& Foam::prefixOSstream::writeQuoted
00118 (
00119     const std::string& val,
00120     const bool quoted
00121 )
00122 {
00123     checkWritePrefix();
00124     return OSstream::writeQuoted(val, quoted);
00125 }
00126 
00127 
00128 Foam::Ostream& Foam::prefixOSstream::write(const label val)
00129 {
00130     checkWritePrefix();
00131     return OSstream::write(val);
00132 }
00133 
00134 
00135 Foam::Ostream& Foam::prefixOSstream::write(const floatScalar val)
00136 {
00137     checkWritePrefix();
00138     return OSstream::write(val);
00139 }
00140 
00141 
00142 Foam::Ostream& Foam::prefixOSstream::write(const doubleScalar val)
00143 {
00144     checkWritePrefix();
00145     return OSstream::write(val);
00146 }
00147 
00148 
00149 Foam::Ostream& Foam::prefixOSstream::write
00150 (
00151     const char* buf,
00152     std::streamsize count
00153 )
00154 {
00155     checkWritePrefix();
00156     return OSstream::write(buf, count);
00157 }
00158 
00159 
00160 void Foam::prefixOSstream::indent()
00161 {
00162     checkWritePrefix();
00163     OSstream::indent();
00164 }
00165 
00166 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines