ITstream.C 3.84 KB
Newer Older
1
2
3
4
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
5
    \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
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
79
80
{
    // 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())
        {
            FatalIOErrorIn
            (
Mark Olesen's avatar
Mark Olesen committed
81
                "ITstream::read(token&)",
82
83
84
85
86
87
88
89
90
91
92
                *this
            )   << "attempt to read beyond EOF"
                << exit(FatalIOError);

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

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

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

    return *this;
}


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

Mark Olesen's avatar
Mark Olesen committed
115
116

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


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


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


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


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


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


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

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

    setGood();

    return *this;
}


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