TableFile.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) 2011-2017 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 "TableFile.H"
27 
28 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
29 
30 template<class Type>
32 (
33  const word& entryName,
34  const dictionary& dict
35 )
36 :
37  TableBase<Type>(entryName, dict),
38  fName_("none")
39 {
40  dict.lookup("file") >> fName_;
41 
42  fileName expandedFile(fName_);
43  //IFstream is(expandedFile.expand());
44  autoPtr<ISstream> isPtr(fileHandler().NewIFstream(expandedFile.expand()));
45  ISstream& is = isPtr();
46 
47  if (!is.good())
48  {
50  (
51  is
52  ) << "Cannot open file." << exit(FatalIOError);
53  }
54 
55  is >> this->table_;
56 
58 }
59 
60 
61 template<class Type>
63 :
64  TableBase<Type>(tbl),
65  fName_(tbl.fName_)
66 {}
67 
68 
69 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
70 
71 template<class Type>
73 {}
74 
75 
76 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
77 
78 template<class Type>
80 {
82 
83  os << token::END_STATEMENT << nl
84  << indent << word(this->name() + "Coeffs") << nl
86 
87  // Note: for TableBase write the dictionary entries it needs but not
88  // the values themselves
90 
91  os.writeKeyword("file")<< fName_ << token::END_STATEMENT << nl;
92  os << decrIndent << indent << token::END_BLOCK << endl;
93 }
94 
95 
96 // ************************************************************************* //
dictionary dict
virtual ~TableFile()
Destructor.
Definition: TableFile.C:72
A class for handling file names.
Definition: fileName.H:69
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:223
Templated table container function where data is read from file.
Definition: TableFile.H:73
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
const word & name() const
Return the name of the entry.
Definition: Function1.C:56
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
virtual void writeData(Ostream &os) const
Write in dictionary format.
Definition: TableFile.C:79
TableFile(const word &entryName, const dictionary &dict)
Construct from entry name and Istream.
Definition: TableFile.C:32
bool good() const
Return true if next operation might succeed.
Definition: IOstream.H:333
virtual void writeData(Ostream &os) const
Write in dictionary format.
Definition: Function1.C:121
Base class for table with bounds handling, interpolation and integration.
Definition: TableBase.H:55
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:53
static const char nl
Definition: Ostream.H:262
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition: Ostream.H:237
Ostream & writeKeyword(const keyType &)
Write the keyword followed by an appropriate indentation.
Definition: Ostream.C:54
Generic input stream.
Definition: ISstream.H:51
string & expand(const bool allowEmpty=false)
Expand initial tildes and all occurences of environment variables.
Definition: string.C:95
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:331
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:230
virtual void writeEntries(Ostream &os) const
Write keywords only in dictionary format. Used for non-inline.
Definition: TableBase.C:410
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:576
IOerror FatalIOError