OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

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-2009 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 the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     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, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "prefixOSstream.H"
00028 #include "Pstream.H"
00029 #include "token.H"
00030 
00031 // * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * * //
00032 
00033 inline void Foam::prefixOSstream::checkWritePrefix()
00034 {
00035     if (printPrefix_ && prefix_.size())
00036     {
00037         OSstream::write(prefix_.c_str());
00038         printPrefix_ = false;
00039     }
00040 }
00041 
00042 
00043 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00044 
00045 Foam::prefixOSstream::prefixOSstream
00046 (
00047     ostream& os,
00048     const string& name,
00049     streamFormat format,
00050     versionNumber version,
00051     compressionType compression
00052 )
00053 :
00054     OSstream(os, name, format, version, compression),
00055     printPrefix_(true),
00056     prefix_("")
00057 {}
00058 
00059 
00060 // * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * * //
00061 
00062 void Foam::prefixOSstream::print(Ostream& os) const
00063 {
00064     os  << "prefixOSstream ";
00065     OSstream::print(os);
00066 }
00067 
00068 
00069 Foam::Ostream& Foam::prefixOSstream::write(const token&)
00070 {
00071     return *this;
00072 }
00073 
00074 
00075 Foam::Ostream& Foam::prefixOSstream::write(const char c)
00076 {
00077     checkWritePrefix();
00078     OSstream::write(c);
00079 
00080     if (c == token::NL)
00081     {
00082         printPrefix_ = true;
00083     }
00084 
00085     return *this;
00086 }
00087 
00088 
00089 Foam::Ostream& Foam::prefixOSstream::write(const char* str)
00090 {
00091     checkWritePrefix();
00092     OSstream::write(str);
00093 
00094     size_t len = strlen(str);
00095     if (len && str[len-1] == token::NL)
00096     {
00097         printPrefix_ = true;
00098     }
00099 
00100     return *this;
00101 }
00102 
00103 
00104 Foam::Ostream& Foam::prefixOSstream::write(const word& val)
00105 {
00106     checkWritePrefix();
00107     return OSstream::write(val);
00108 }
00109 
00110 
00111 Foam::Ostream& Foam::prefixOSstream::write(const string& val)
00112 {
00113     checkWritePrefix();
00114     return OSstream::write(val);
00115 }
00116 
00117 
00118 Foam::Ostream& Foam::prefixOSstream::writeQuoted
00119 (
00120     const std::string& val,
00121     const bool quoted
00122 )
00123 {
00124     checkWritePrefix();
00125     return OSstream::writeQuoted(val, quoted);
00126 }
00127 
00128 
00129 Foam::Ostream& Foam::prefixOSstream::write(const label val)
00130 {
00131     checkWritePrefix();
00132     return OSstream::write(val);
00133 }
00134 
00135 
00136 Foam::Ostream& Foam::prefixOSstream::write(const floatScalar val)
00137 {
00138     checkWritePrefix();
00139     return OSstream::write(val);
00140 }
00141 
00142 
00143 Foam::Ostream& Foam::prefixOSstream::write(const doubleScalar val)
00144 {
00145     checkWritePrefix();
00146     return OSstream::write(val);
00147 }
00148 
00149 
00150 Foam::Ostream& Foam::prefixOSstream::write
00151 (
00152     const char* buf,
00153     std::streamsize count
00154 )
00155 {
00156     checkWritePrefix();
00157     return OSstream::write(buf, count);
00158 }
00159 
00160 
00161 void Foam::prefixOSstream::indent()
00162 {
00163     checkWritePrefix();
00164     OSstream::indent();
00165 }
00166 
00167 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd