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

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