Home
Downloads
Documentation
Installation
User Guide
man-pages
API Documentation
README
Release Notes
Changes
License
Support
SourceForge Project
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
src
OpenFOAM
primitives
ints
int
intIO.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
Reads an int from an input stream, for a given version
26
number and File format. If an ascii File is being read,
27
then the line numbers are counted and an erroneous read
28
ised.
29
30
\*---------------------------------------------------------------------------*/
31
32
#include <
OpenFOAM/error.H
>
33
34
#include "
int.H
"
35
#include <
OpenFOAM/IOstreams.H
>
36
37
#include <sstream>
38
39
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40
41
Foam::word
Foam::name
(
const
int
val)
42
{
43
std::ostringstream buf;
44
buf << val;
45
return
buf.str();
46
}
47
48
49
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
50
51
Foam::Istream
&
Foam::operator>>
(
Istream
& is,
int
& i)
52
{
53
token
t(is);
54
55
if
(!t.
good
())
56
{
57
is.
setBad
();
58
return
is;
59
}
60
61
if
(t.
isLabel
())
62
{
63
i = int(t.
labelToken
());
64
}
65
else
66
{
67
is.
setBad
();
68
FatalIOErrorIn
(
"operator>>(Istream&, int&)"
, is)
69
<<
"wrong token type - expected int found "
<< t.
info
()
70
<<
exit
(
FatalIOError
);
71
72
return
is;
73
}
74
75
// Check state of Istream
76
is.
check
(
"Istream& operator>>(Istream&, int&)"
);
77
78
return
is;
79
}
80
81
82
int
Foam::readInt
(
Istream
& is)
83
{
84
int
val;
85
is >> val;
86
87
return
val;
88
}
89
90
91
Foam::Ostream
&
Foam::operator<<
(
Ostream
& os,
const
int
i)
92
{
93
os.
write
(label(i));
94
os.
check
(
"Ostream& operator<<(Ostream&, const int)"
);
95
return
os;
96
}
97
98
99
// ************************ vim: set sw=4 sts=4 et: ************************ //