ITstream.C 3.54 KB
Newer Older
1
2
3
4
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
5
    \\  /    A nd           | Copyright (C) 2011-2015 OpenFOAM Foundation
6
7
8
9
10
     \\/     M anipulation  |
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

11
12
13
14
    OpenFOAM is free software: you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
15
16
17
18
19
20
21

    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    for more details.

    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
27
28
29
30

\*---------------------------------------------------------------------------*/

#include "error.H"
#include "ITstream.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

Mark Olesen's avatar
Mark Olesen committed
31
void Foam::ITstream::print(Ostream& os) const
32
{
Mark Olesen's avatar
Mark Olesen committed
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
    os  << "ITstream : " << name_.c_str();

    if (size())
    {
        if (begin()->lineNumber() == rbegin()->lineNumber())
        {
            os  << ", line " << begin()->lineNumber() << ", ";
        }
        else
        {
            os  << ", lines " << begin()->lineNumber()
                << '-' << rbegin()->lineNumber() << ", ";
        }
    }
    else
    {
        os  << ", line " << lineNumber() << ", ";
    }

    IOstream::print(os);
}
54
55


Mark Olesen's avatar
Mark Olesen committed
56
Foam::Istream& Foam::ITstream::read(token& t)
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
{
    // Return the put back token if it exists
    if (Istream::getBack(t))
    {
        lineNumber_ = t.lineNumber();
        return *this;
    }

    if (tokenIndex_ < size())
    {
        t = operator[](tokenIndex_++);
        lineNumber_ = t.lineNumber();

        if (tokenIndex_ == size())
        {
            setEof();
        }
    }
    else
    {
        if (eof())
        {
79
            FatalIOErrorInFunction
80
81
82
83
84
85
86
87
88
89
90
91
            (
                *this
            )   << "attempt to read beyond EOF"
                << exit(FatalIOError);

            setBad();
        }
        else
        {
            setEof();
        }

Mark Olesen's avatar
Mark Olesen committed
92
93
        t = token::undefinedToken;

94
95
        if (size())
        {
Mark Olesen's avatar
Mark Olesen committed
96
            t.lineNumber() = tokenList::last().lineNumber();
97
98
99
        }
        else
        {
Mark Olesen's avatar
Mark Olesen committed
100
            t.lineNumber() = lineNumber();
101
102
103
104
105
106
107
        }
    }

    return *this;
}


Mark Olesen's avatar
Mark Olesen committed
108
Foam::Istream& Foam::ITstream::read(char&)
109
{
110
    NotImplemented;
111
112
113
    return *this;
}

Mark Olesen's avatar
Mark Olesen committed
114
115

Foam::Istream& Foam::ITstream::read(word&)
116
{
117
    NotImplemented;
118
119
120
121
    return *this;
}


Mark Olesen's avatar
Mark Olesen committed
122
Foam::Istream& Foam::ITstream::read(string&)
123
{
124
    NotImplemented;
125
126
127
128
    return *this;
}


Mark Olesen's avatar
Mark Olesen committed
129
Foam::Istream& Foam::ITstream::read(label&)
130
{
131
    NotImplemented;
132
133
134
135
    return *this;
}


Mark Olesen's avatar
Mark Olesen committed
136
Foam::Istream& Foam::ITstream::read(floatScalar&)
137
{
138
    NotImplemented;
139
140
141
142
    return *this;
}


Mark Olesen's avatar
Mark Olesen committed
143
Foam::Istream& Foam::ITstream::read(doubleScalar&)
144
{
145
    NotImplemented;
146
147
148
149
    return *this;
}


Mark Olesen's avatar
Mark Olesen committed
150
Foam::Istream& Foam::ITstream::read(char*, std::streamsize)
151
{
152
    NotImplemented;
153
154
155
156
    return *this;
}


Mark Olesen's avatar
Mark Olesen committed
157
Foam::Istream& Foam::ITstream::rewind()
158
159
160
161
162
{
    tokenIndex_ = 0;

    if (size())
    {
Mark Olesen's avatar
Mark Olesen committed
163
        lineNumber_ = tokenList::first().lineNumber();
164
165
166
167
168
169
170
171
172
    }

    setGood();

    return *this;
}


// ************************************************************************* //