Forward compatibility: flex
[foam-extend-3.2.git] / src / foam / db / dictionary / primitiveEntry / primitiveEntry.C
blob3845b326218524699fede04684fd7bdc245604cb
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     | Version:     3.2
5     \\  /    A nd           | Web:         http://www.foam-extend.org
6      \\/     M anipulation  | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9     This file is part of foam-extend.
11     foam-extend is free software: you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation, either version 3 of the License, or (at your
14     option) any later version.
16     foam-extend is distributed in the hope that it will be useful, but
17     WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19     General Public License for more details.
21     You should have received a copy of the GNU General Public License
22     along with foam-extend.  If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "primitiveEntry.H"
27 #include "dictionary.H"
29 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
31 Foam::primitiveEntry::primitiveEntry(const keyType& key, const ITstream& tokens)
33     entry(key),
34     ITstream(tokens)
36     name() += "::" + keyword();
40 Foam::primitiveEntry::primitiveEntry(const keyType& keyword, const token& t)
42     entry(keyword),
43     ITstream(keyword, tokenList(1, t))
47 Foam::primitiveEntry::primitiveEntry
49     const keyType& keyword,
50     const tokenList& tokens
53     entry(keyword),
54     ITstream(keyword, tokens)
58 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
60 Foam::label Foam::primitiveEntry::startLineNumber() const
62     if (size())
63     {
64         return operator[](0).lineNumber();
65     }
66     else
67     {
68         return -1;
69     }
72 Foam::label Foam::primitiveEntry::endLineNumber() const
74     if (size())
75     {
76         return operator[](size()-1).lineNumber();
77     }
78     else
79     {
80         return -1;
81     }
85 Foam::ITstream& Foam::primitiveEntry::stream() const
87     ITstream& dataStream = const_cast<primitiveEntry&>(*this);
88     dataStream.rewind();
89     return dataStream;
93 const Foam::dictionary& Foam::primitiveEntry::dict() const
95     FatalErrorIn("const dictionary& primitiveEntry::dict() const")
96         << "Attempt to return primitive entry " << info()
97         << " as a sub-dictionary"
98         << abort(FatalError);
100     return dictionary::null;
104 Foam::dictionary& Foam::primitiveEntry::dict()
106     FatalErrorIn("const dictionary& primitiveEntry::dict()")
107         << "Attempt to return primitive entry " << info()
108         << " as a sub-dictionary"
109         << abort(FatalError);
111     return const_cast<dictionary&>(dictionary::null);
115 void Foam::primitiveEntry::insert
117     const tokenList& varTokens,
118     const label posI
121     tokenList& tokens = *this;
123     if (varTokens.empty())
124     {
125         label end = tokens.size() - 1;
127         for (label j=posI; j<end; j++)
128         {
129             tokens[j] = tokens[j+1];
130         }
132         tokens.setSize(tokens.size() - 1);
133     }
134     else if (varTokens.size() > 1)
135     {
136         tokens.setSize(tokens.size() + varTokens.size() - 1);
138         label end = tokens.size() - 1;
139         label offset = varTokens.size() - 1;
141         for (label j=end; j>posI; j--)
142         {
143             tokens[j] = tokens[j-offset];
144         }
145     }
147     forAll(varTokens, j)
148     {
149         tokens[posI + j] = varTokens[j];
150     }
154 // ************************************************************************* //