TableReader.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
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 \*---------------------------------------------------------------------------*/
25 
26 #include "TableReader.H"
27 #include "fileOperation.H"
28 
29 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
30 
31 template<class Type>
33 (
34  const word& readerType,
35  const dictionary& dict
36 )
37 {
38  typename dictionaryConstructorTable::iterator cstrIter =
39  dictionaryConstructorTablePtr_->find(readerType);
40 
41  if (cstrIter == dictionaryConstructorTablePtr_->end())
42  {
44  << "Unknown reader type " << readerType
45  << nl << nl
46  << "Valid reader types : " << nl
47  << dictionaryConstructorTablePtr_->sortedToc()
48  << exit(FatalError);
49  }
50 
51  return autoPtr<TableReader<Type>>(cstrIter()(dict));
52 }
53 
54 
55 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
56 
57 template<class Type>
59 {}
60 
61 
62 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
63 
64 template<class Type>
66 {}
67 
68 
69 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
70 
71 template<class Type>
73 {}
74 
75 
76 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
77 
78 template<class Type>
79 template<class TableType>
81 (
82  const fileName& fName,
83  TableType& data
84 ) const
85 {
86  // Expand the file
87  fileName fNameExpanded(fName);
88  fNameExpanded.expand();
89 
90  // Open a stream and check it
91  autoPtr<ISstream> isPtr(fileHandler().NewIFstream(fNameExpanded));
92  ISstream& is = isPtr();
93  if (!is.good())
94  {
96  << "Cannot open file" << fName << nl
97  << exit(FatalIOError);
98  }
99 
100  // Read data from the stream
101  read(is, data);
102 
103  // Check something was read
104  if (data.empty())
105  {
107  << "Table read from " << fName << " is empty" << nl
108  << exit(FatalIOError);
109  }
110 }
111 
112 
113 // ************************************************************************* //
Base class to read table data for tables.
Definition: TableReader.H:52
dictionary dict
A class for handling file names.
Definition: fileName.H:79
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
void read(Istream &, label &, const dictionary &)
In-place read with dictionary lookup.
bool good() const
Return true if next operation might succeed.
Definition: IOstream.H:333
A class for handling words, derived from string.
Definition: word.H:59
const fileOperation & fileHandler()
Get current file handler.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
static autoPtr< TableReader< Type > > New(const word &readerType, const dictionary &dict)
Definition: TableReader.C:33
static const char nl
Definition: Ostream.H:260
Database for solution and other reduced data.
Definition: data.H:51
virtual void write(Ostream &os) const
Write additional information.
Definition: TableReader.C:72
TableReader(const dictionary &dict)
Construct from dictionary.
Definition: TableReader.C:58
Generic input stream.
Definition: ISstream.H:51
string & expand(const bool allowEmpty=false)
Expand initial tildes and all occurrences of environment variables.
Definition: string.C:103
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:331
virtual ~TableReader()
Destructor.
Definition: TableReader.C:65
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
IOerror FatalIOError