stringIO.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 "string.H"
27 #include "IOstreams.H"
28 
29 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30 
32 {
33  is >> *this;
34 }
35 
36 
37 // * * * * * * * * * * * * * * * IOstream Functions * * * * * * * * * * * * //
38 
39 void Foam::writeEntry(Ostream& os, const char* value)
40 {
41  os << value;
42 }
43 
44 
45 void Foam::writeEntry(Ostream& os, const string& value)
46 {
47  os << value;
48 }
49 
50 
51 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
52 
54 {
55  token t(is);
56 
57  if (!t.good())
58  {
59  is.setBad();
60  return is;
61  }
62 
63  if (t.isString())
64  {
65  s = t.stringToken();
66  }
67  else
68  {
69  is.setBad();
71  << "wrong token type - expected string, found " << t.info()
72  << exit(FatalIOError);
73 
74  return is;
75  }
76 
77  // Check state of Istream
78  is.check("Istream& operator>>(Istream&, string&)");
79 
80  return is;
81 }
82 
83 
85 {
86  os.write(s);
87  os.check("Ostream& operator<<(Ostream&, const string&)");
88  return os;
89 }
90 
91 
92 Foam::Ostream& Foam::operator<<(Ostream& os, const std::string& s)
93 {
94  os.write(string(s));
95  os.check("Ostream& operator<<(Ostream&, const std::string&)");
96  return os;
97 }
98 
99 
100 // ************************************************************************* //
virtual Ostream & write(const char)=0
Write character.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
InfoProxy< token > info() const
Return info proxy.
Definition: token.H:391
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
A token holds items read from Istream.
Definition: token.H:72
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
void setBad()
Set stream to be bad.
Definition: IOstream.H:484
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Istream & operator>>(Istream &, directionInfo &)
bool good() const
Definition: tokenI.H:228
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
string()
Construct null.
Definition: stringI.H:30
const string & stringToken() const
Definition: tokenI.H:320
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
bool isString() const
Definition: tokenI.H:315
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:318
Ostream & operator<<(Ostream &, const ensightPart &)
IOerror FatalIOError