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

ILListIO.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 Description
00025 
00026 \*---------------------------------------------------------------------------*/
00027 
00028 #include "ILList.H"
00029 #include <OpenFOAM/Istream.H>
00030 #include <OpenFOAM/INew.H>
00031 
00032 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00033 
00034 template<class LListBase, class T>
00035 template<class INew>
00036 void Foam::ILList<LListBase, T>::read(Istream& is, const INew& iNew)
00037 {
00038     is.fatalCheck("operator>>(Istream&, ILList<LListBase, T>&)");
00039 
00040     token firstToken(is);
00041 
00042     is.fatalCheck
00043     (
00044         "operator>>(Istream&, ILList<LListBase, T>&) : reading first token"
00045     );
00046 
00047     if (firstToken.isLabel())
00048     {
00049         label s = firstToken.labelToken();
00050 
00051         // Read beginning of contents
00052         char delimiter = is.readBeginList("ILList<LListBase, T>");
00053 
00054         if (s)
00055         {
00056             if (delimiter == token::BEGIN_LIST)
00057             {
00058                 for (label i=0; i<s; i++)
00059                 {
00060                     this->append(iNew(is).ptr());
00061 
00062                     is.fatalCheck
00063                     (
00064                         "operator>>(Istream&, ILList<LListBase, T>&) : "
00065                         "reading entry"
00066                     );
00067                 }
00068             }
00069             else
00070             {
00071                 T* tPtr = iNew(is).ptr();
00072                 this->append(tPtr);
00073 
00074                 is.fatalCheck
00075                 (
00076                     "operator>>(Istream&, ILList<LListBase, T>&) : "
00077                     "reading entry"
00078                 );
00079 
00080                 for (label i=1; i<s; i++)
00081                 {
00082                     this->append(new T(*tPtr));
00083                 }
00084             }
00085         }
00086 
00087         // Read end of contents
00088         is.readEndList("ILList<LListBase, T>");
00089     }
00090     else if (firstToken.isPunctuation())
00091     {
00092         if (firstToken.pToken() != token::BEGIN_LIST)
00093         {
00094             FatalIOErrorIn
00095             (
00096                 "operator>>(Istream&, ILList<LListBase, T>&)",
00097                 is
00098             )   << "incorrect first token, '(', found " << firstToken.info()
00099                 << exit(FatalIOError);
00100         }
00101 
00102         token lastToken(is);
00103         is.fatalCheck("operator>>(Istream&, ILList<LListBase, T>&)");
00104 
00105         while
00106         (
00107            !(
00108                 lastToken.isPunctuation()
00109              && lastToken.pToken() == token::END_LIST
00110             )
00111         )
00112         {
00113             is.putBack(lastToken);
00114             this->append(iNew(is).ptr());
00115 
00116             is >> lastToken;
00117             is.fatalCheck("operator>>(Istream&, ILList<LListBase, T>&)");
00118         }
00119     }
00120     else
00121     {
00122         FatalIOErrorIn("operator>>(Istream&, ILList<LListBase, T>&)", is)
00123             << "incorrect first token, expected <int> or '(', found "
00124             << firstToken.info()
00125             << exit(FatalIOError);
00126     }
00127 
00128     is.fatalCheck("operator>>(Istream&, ILList<LListBase, T>&)");
00129 }
00130 
00131 
00132 template<class LListBase, class T>
00133 template<class INew>
00134 Foam::ILList<LListBase, T>::ILList(Istream& is, const INew& iNew)
00135 {
00136     read(is, iNew);
00137 }
00138 
00139 
00140 template<class LListBase, class T>
00141 Foam::ILList<LListBase, T>::ILList(Istream& is)
00142 {
00143     read(is, INew<T>());
00144 }
00145 
00146 
00147 // * * * * * * * * * * * * * * * Istream Operator  * * * * * * * * * * * * * //
00148 
00149 template<class LListBase, class T>
00150 Foam::Istream& Foam::operator>>(Istream& is, ILList<LListBase, T>& L)
00151 {
00152     L.clear();
00153     L.read(is, INew<T>());
00154 
00155     return is;
00156 }
00157 
00158 
00159 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00160 
00161 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines