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

UListIO.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 "UList.H"
00027 #include <OpenFOAM/Ostream.H>
00028 #include <OpenFOAM/token.H>
00029 #include <OpenFOAM/contiguous.H>
00030 
00031 // * * * * * * * * * * * * * * * Ostream Operator *  * * * * * * * * * * * * //
00032 
00033 template<class T>
00034 void Foam::UList<T>::writeEntry(Ostream& os) const
00035 {
00036     if
00037     (
00038         size()
00039      && token::compound::isCompound
00040         (
00041             "List<" + word(pTraits<T>::typeName) + '>'
00042         )
00043     )
00044     {
00045         os  << word("List<" + word(pTraits<T>::typeName) + '>') << " ";
00046     }
00047 
00048     os << *this;
00049 }
00050 
00051 
00052 template<class T>
00053 void Foam::UList<T>::writeEntry(const word& keyword, Ostream& os) const
00054 {
00055     os.writeKeyword(keyword);
00056     writeEntry(os);
00057     os << token::END_STATEMENT << endl;
00058 }
00059 
00060 
00061 template<class T>
00062 Foam::Ostream& Foam::operator<<(Foam::Ostream& os, const Foam::UList<T>& L)
00063 {
00064     // Write list contents depending on data format
00065     if (os.format() == IOstream::ASCII || !contiguous<T>())
00066     {
00067         bool uniform = false;
00068 
00069         if (L.size() > 1 && contiguous<T>())
00070         {
00071             uniform = true;
00072 
00073             forAll(L, i)
00074             {
00075                 if (L[i] != L[0])
00076                 {
00077                     uniform = false;
00078                     break;
00079                 }
00080             }
00081         }
00082 
00083         if (uniform)
00084         {
00085             // Write size and start delimiter
00086             os << L.size() << token::BEGIN_BLOCK;
00087 
00088             // Write contents
00089             os << L[0];
00090 
00091             // Write end delimiter
00092             os << token::END_BLOCK;
00093         }
00094         else if (L.size() < 11 && contiguous<T>())
00095         {
00096             // Write size and start delimiter
00097             os << L.size() << token::BEGIN_LIST;
00098 
00099             // Write contents
00100             forAll(L, i)
00101             {
00102                 if (i > 0) os << token::SPACE;
00103                 os << L[i];
00104             }
00105 
00106             // Write end delimiter
00107             os << token::END_LIST;
00108         }
00109         else
00110         {
00111             // Write size and start delimiter
00112             os << nl << L.size() << nl << token::BEGIN_LIST;
00113 
00114             // Write contents
00115             forAll(L, i)
00116             {
00117                 os << nl << L[i];
00118             }
00119 
00120             // Write end delimiter
00121             os << nl << token::END_LIST << nl;
00122         }
00123     }
00124     else
00125     {
00126         os << nl << L.size() << nl;
00127         if (L.size())
00128         {
00129             os.write(reinterpret_cast<const char*>(L.v_), L.byteSize());
00130         }
00131     }
00132 
00133     // Check state of IOstream
00134     os.check("Ostream& operator<<(Ostream&, const UList&)");
00135 
00136     return os;
00137 }
00138 
00139 
00140 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines