Loading...
Searching...
No Matches
fileNameIO.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 | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011-2017 OpenFOAM Foundation
9 Copyright (C) 2018-2021 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27\*---------------------------------------------------------------------------*/
28
29#include "fileName.H"
30#include "IOstreams.H"
31
32// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
33
36 is >> *this;
37}
38
39
40// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
41
42bool Foam::fileName::assign(const token& tok)
43{
44 if (tok.isWord())
45 {
46 // Also accept a plain word as a fileName
47 assign(tok.wordToken());
48 return true;
49 }
50 else if (tok.isQuotedString())
51 {
52 assign(tok.stringToken());
53 stripInvalid(); // More stringent for fileName than string
54 return true;
55 }
57 return false;
58}
59
60
61// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
62
63Foam::Istream& Foam::operator>>(Istream& is, fileName& val)
64{
65 token tok(is);
66
67 if (!val.assign(tok))
68 {
70 if (tok.good())
71 {
73 << "Wrong token type - expected string, found "
74 << tok.info();
75 }
76 else
77 {
79 << "Bad token - could not get fileName";
80 }
82 is.setBad();
83 return is;
84 }
85
86 is.check(FUNCTION_NAME);
87 return is;
88}
89
90
91Foam::Ostream& Foam::operator<<(Ostream& os, const fileName& val)
92{
93 os.write(val);
95 return os;
96}
97
98
99// ************************************************************************* //
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
void setBad() noexcept
Set stream state to be 'bad'.
Definition IOstream.H:488
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition IOstream.C:45
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
virtual Ostream & write(const char c) override
Write character.
Definition OBJstream.C:69
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
A class for handling file names.
Definition fileName.H:75
bool assign(const token &tok)
Assign from word or string token.
Definition fileNameIO.C:35
fileName()=default
Default construct.
void stripInvalid()
Strip invalid characters.
Definition fileNameI.H:106
A token holds an item read from Istream.
Definition token.H:70
const string & stringToken() const
Return const reference to the string contents.
Definition tokenI.H:1076
bool good() const noexcept
True if token is not UNDEFINED or ERROR.
Definition tokenI.H:584
bool isQuotedString() const noexcept
Token is (quoted) STRING (string variant).
Definition tokenI.H:1034
const word & wordToken() const
Return const reference to the word contents.
Definition tokenI.H:1022
bool isWord() const noexcept
Token is word-variant (WORD, DIRECTIVE).
Definition tokenI.H:1004
InfoProxy< token > info() const noexcept
Return info proxy, for printing token information to a stream.
Definition token.H:1253
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition error.H:629
OBJstream os(runTime.globalPath()/outputName)
#define FUNCTION_NAME
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces).
Istream & operator>>(Istream &, directionInfo &)
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125