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

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