FreeFOAM The Cross-Platform CFD Toolkit
ILListIO.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Description
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "ILList.H"
29 #include <OpenFOAM/Istream.H>
30 #include <OpenFOAM/INew.H>
31 
32 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
33 
34 template<class LListBase, class T>
35 template<class INew>
36 void Foam::ILList<LListBase, T>::read(Istream& is, const INew& iNew)
37 {
38  is.fatalCheck("operator>>(Istream&, ILList<LListBase, T>&)");
39 
40  token firstToken(is);
41 
42  is.fatalCheck
43  (
44  "operator>>(Istream&, ILList<LListBase, T>&) : reading first token"
45  );
46 
47  if (firstToken.isLabel())
48  {
49  label s = firstToken.labelToken();
50 
51  // Read beginning of contents
52  char delimiter = is.readBeginList("ILList<LListBase, T>");
53 
54  if (s)
55  {
56  if (delimiter == token::BEGIN_LIST)
57  {
58  for (label i=0; i<s; i++)
59  {
60  append(iNew(is).ptr());
61 
62  is.fatalCheck
63  (
64  "operator>>(Istream&, ILList<LListBase, T>&) : "
65  "reading entry"
66  );
67  }
68  }
69  else
70  {
71  T* tPtr = iNew(is).ptr();
72  append(tPtr);
73 
74  is.fatalCheck
75  (
76  "operator>>(Istream&, ILList<LListBase, T>&) : "
77  "reading entry"
78  );
79 
80  for (label i=1; i<s; i++)
81  {
82  append(new T(*tPtr));
83  }
84  }
85  }
86 
87  // Read end of contents
88  is.readEndList("ILList<LListBase, T>");
89  }
90  else if (firstToken.isPunctuation())
91  {
92  if (firstToken.pToken() != token::BEGIN_LIST)
93  {
95  (
96  "operator>>(Istream&, ILList<LListBase, T>&)",
97  is
98  ) << "incorrect first token, '(', found " << firstToken.info()
99  << exit(FatalIOError);
100  }
101 
102  token lastToken(is);
103  is.fatalCheck("operator>>(Istream&, ILList<LListBase, T>&)");
104 
105  while
106  (
107  !(
108  lastToken.isPunctuation()
109  && lastToken.pToken() == token::END_LIST
110  )
111  )
112  {
113  is.putBack(lastToken);
114  append(iNew(is).ptr());
115 
116  is >> lastToken;
117  is.fatalCheck("operator>>(Istream&, ILList<LListBase, T>&)");
118  }
119  }
120  else
121  {
122  FatalIOErrorIn("operator>>(Istream&, ILList<LListBase, T>&)", is)
123  << "incorrect first token, expected <int> or '(', found "
124  << firstToken.info()
125  << exit(FatalIOError);
126  }
127 
128  is.fatalCheck("operator>>(Istream&, ILList<LListBase, T>&)");
129 }
130 
131 
132 template<class LListBase, class T>
133 template<class INew>
135 {
136  read(is, iNew);
137 }
138 
139 
140 template<class LListBase, class T>
142 {
143  read(is, INew<T>());
144 }
145 
146 
147 // * * * * * * * * * * * * * * * Istream Operator * * * * * * * * * * * * * //
148 
149 template<class LListBase, class T>
151 {
152  L.clear();
153  L.read(is, INew<T>());
154 
155  return is;
156 }
157 
158 
159 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
160 
161 // ************************ vim: set sw=4 sts=4 et: ************************ //