primitiveEntry.C 3.77 KB
Newer Older
1
2
3
4
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
Mark Olesen's avatar
Mark Olesen committed
5
    \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
     \\/     M anipulation  |
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

    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 2 of the License, or (at your
    option) any later version.

    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
    along with OpenFOAM; if not, write to the Free Software Foundation,
    Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

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

#include "primitiveEntry.H"
#include "dictionary.H"

// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //

mattijs's avatar
mattijs committed
32
Foam::primitiveEntry::primitiveEntry(const keyType& key, const ITstream& tokens)
33
34
35
36
37
38
39
40
:
    entry(key),
    ITstream(tokens)
{
    name() += "::" + keyword();
}


mattijs's avatar
mattijs committed
41
Foam::primitiveEntry::primitiveEntry(const keyType& keyword, const token& t)
42
43
44
45
46
47
48
49
:
    entry(keyword),
    ITstream(keyword, tokenList(1, t))
{}


Foam::primitiveEntry::primitiveEntry
(
mattijs's avatar
mattijs committed
50
    const keyType& keyword,
51
52
53
54
55
56
57
58
59
60
61
62
    const tokenList& tokens
)
:
    entry(keyword),
    ITstream(keyword, tokens)
{}


// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //

Foam::label Foam::primitiveEntry::startLineNumber() const
{
63
64
65
    const tokenList& tokens = *this;

    if (tokens.empty())
66
    {
67
        return -1;
68
69
70
    }
    else
    {
71
        return tokens.first().lineNumber();
72
73
74
    }
}

75

76
77
Foam::label Foam::primitiveEntry::endLineNumber() const
{
78
79
80
    const tokenList& tokens = *this;

    if (tokens.empty())
81
    {
82
        return -1;
83
84
85
    }
    else
    {
86
        return tokens.last().lineNumber();
87
88
89
90
91
92
    }
}


Foam::ITstream& Foam::primitiveEntry::stream() const
{
93
94
95
    ITstream& is = const_cast<primitiveEntry&>(*this);
    is.rewind();
    return is;
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
}


const Foam::dictionary& Foam::primitiveEntry::dict() const
{
    FatalErrorIn("const dictionary& primitiveEntry::dict() const")
        << "Attempt to return primitive entry " << info()
        << " as a sub-dictionary"
        << abort(FatalError);

    return dictionary::null;
}


Foam::dictionary& Foam::primitiveEntry::dict()
{
    FatalErrorIn("const dictionary& primitiveEntry::dict()")
        << "Attempt to return primitive entry " << info()
        << " as a sub-dictionary"
        << abort(FatalError);

    return const_cast<dictionary&>(dictionary::null);
}


121
122
123
124
125
void Foam::primitiveEntry::insert
(
    const tokenList& varTokens,
    const label posI
)
126
127
128
{
    tokenList& tokens = *this;

129
    if (varTokens.empty())
130
131
132
    {
        label end = tokens.size() - 1;

133
        for (label j = posI; j < end; j++)
134
135
136
137
138
139
140
141
142
143
144
145
146
        {
            tokens[j] = tokens[j+1];
        }

        tokens.setSize(tokens.size() - 1);
    }
    else if (varTokens.size() > 1)
    {
        tokens.setSize(tokens.size() + varTokens.size() - 1);

        label end = tokens.size() - 1;
        label offset = varTokens.size() - 1;

147
        for (label j = end; j > posI; j--)
148
149
150
151
152
153
154
        {
            tokens[j] = tokens[j-offset];
        }
    }

    forAll(varTokens, j)
    {
155
        tokens[posI + j] = varTokens[j];
156
157
158
159
160
    }
}


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