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

UIndirectListIO.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 "UIndirectList.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 Foam::Ostream& Foam::operator<<
00035 (
00036     Foam::Ostream& os,
00037     const Foam::UIndirectList<T>& L
00038 )
00039 {
00040     // Write list contents depending on data format
00041     if (os.format() == IOstream::ASCII || !contiguous<T>())
00042     {
00043         bool uniform = false;
00044 
00045         if (L.size() > 1 && contiguous<T>())
00046         {
00047             uniform = true;
00048 
00049             forAll(L, i)
00050             {
00051                 if (L[i] != L[0])
00052                 {
00053                     uniform = false;
00054                     break;
00055                 }
00056             }
00057         }
00058 
00059         if (uniform)
00060         {
00061             // Write size and start delimiter
00062             os << L.size() << token::BEGIN_BLOCK;
00063 
00064             // Write contents
00065             os << L[0];
00066 
00067             // Write end delimiter
00068             os << token::END_BLOCK;
00069         }
00070         else if (L.size() < 11 && contiguous<T>())
00071         {
00072             // Write size and start delimiter
00073             os << L.size() << token::BEGIN_LIST;
00074 
00075             // Write contents
00076             forAll(L, i)
00077             {
00078                 if (i) os << token::SPACE;
00079                 os << L[i];
00080             }
00081 
00082             // Write end delimiter
00083             os << token::END_LIST;
00084         }
00085         else
00086         {
00087             // Write size and start delimiter
00088             os << nl << L.size() << nl << token::BEGIN_LIST;
00089 
00090             // Write contents
00091             forAll(L, i)
00092             {
00093                 os << nl << L[i];
00094             }
00095 
00096             // Write end delimiter
00097             os << nl << token::END_LIST << nl;
00098         }
00099     }
00100     else
00101     {
00102         // this is annoying, and wasteful, but there's currently no alternative
00103 
00104         os << nl << L.size() << nl;
00105 
00106         if (L.size())
00107         {
00108             List<T> lst = L();
00109 
00110             os.write
00111             (
00112                 reinterpret_cast<const char*>(lst.cdata()),
00113                 lst.byteSize()
00114             );
00115         }
00116     }
00117 
00118     // Check state of IOstream
00119     os.check("Ostream& operator<<(Ostream&, const UIndirectList&)");
00120 
00121     return os;
00122 }
00123 
00124 
00125 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines