initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / containers / LinkedLists / accessTypes / ILList / ILListIO.C
blobe9c489169c99df4c490e0f74af6b3423b74a633c
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software; you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Description
27 \*---------------------------------------------------------------------------*/
29 #include "ILList.H"
30 #include "Istream.H"
31 #include "INew.H"
33 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
35 template<class LListBase, class T>
36 template<class INew>
37 void Foam::ILList<LListBase, T>::read(Istream& is, const INew& iNew)
39     is.fatalCheck("operator>>(Istream&, ILList<LListBase, T>&)");
41     token firstToken(is);
43     is.fatalCheck
44     (
45         "operator>>(Istream&, ILList<LListBase, T>&) : reading first token"
46     );
48     if (firstToken.isLabel())
49     {
50         label s = firstToken.labelToken();
52         // Read beginning of contents
53         char delimiter = is.readBeginList("ILList<LListBase, T>");
55         if (s)
56         {
57             if (delimiter == token::BEGIN_LIST)
58             {
59                 for (label i=0; i<s; i++)
60                 {
61                     append(iNew(is).ptr());
63                     is.fatalCheck
64                     (
65                         "operator>>(Istream&, ILList<LListBase, T>&) : "
66                         "reading entry"
67                     );
68                 }
69             }
70             else
71             {
72                 T* tPtr = iNew(is).ptr();
73                 append(tPtr);
75                 is.fatalCheck
76                 (
77                     "operator>>(Istream&, ILList<LListBase, T>&) : "
78                     "reading entry"
79                 );
81                 for (label i=1; i<s; i++)
82                 {
83                     append(new T(*tPtr));
84                 }
85             }
86         }
88         // Read end of contents
89         is.readEndList("ILList<LListBase, T>");
90     }
91     else if (firstToken.isPunctuation())
92     {
93         if (firstToken.pToken() != token::BEGIN_LIST)
94         {
95             FatalIOErrorIn
96             (
97                 "operator>>(Istream&, ILList<LListBase, T>&)",
98                 is
99             )   << "incorrect first token, '(', found " << firstToken.info()
100                 << exit(FatalIOError);
101         }
103         token lastToken(is);
104         is.fatalCheck("operator>>(Istream&, ILList<LListBase, T>&)");
106         while
107         (
108            !(
109                 lastToken.isPunctuation()
110              && lastToken.pToken() == token::END_LIST
111             )
112         )
113         {
114             is.putBack(lastToken);
115             append(iNew(is).ptr());
117             is >> lastToken;
118             is.fatalCheck("operator>>(Istream&, ILList<LListBase, T>&)");
119         }
120     }
121     else
122     {
123         FatalIOErrorIn("operator>>(Istream&, ILList<LListBase, T>&)", is)
124             << "incorrect first token, expected <int> or '(', found "
125             << firstToken.info()
126             << exit(FatalIOError);
127     }
129     is.fatalCheck("operator>>(Istream&, ILList<LListBase, T>&)");
133 template<class LListBase, class T>
134 template<class INew>
135 Foam::ILList<LListBase, T>::ILList(Istream& is, const INew& iNew)
137     read(is, iNew);
141 template<class LListBase, class T>
142 Foam::ILList<LListBase, T>::ILList(Istream& is)
144     read(is, INew<T>());
148 // * * * * * * * * * * * * * * * Istream Operator  * * * * * * * * * * * * * //
150 template<class LListBase, class T>
151 Foam::Istream& Foam::operator>>(Istream& is, ILList<LListBase, T>& L)
153     L.clear();
154     L.read(is, INew<T>());
156     return is;
160 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
162 // ************************************************************************* //