initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / db / dictionary / primitiveEntry / primitiveEntry.C
blobbe5977ee062bcd39c29a750eb1d9f1df8014b7d0
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
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.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "primitiveEntry.H"
28 #include "dictionary.H"
30 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
32 Foam::primitiveEntry::primitiveEntry(const keyType& key, const ITstream& tokens)
34     entry(key),
35     ITstream(tokens)
37     name() += "::" + keyword();
41 Foam::primitiveEntry::primitiveEntry(const keyType& keyword, const token& t)
43     entry(keyword),
44     ITstream(keyword, tokenList(1, t))
48 Foam::primitiveEntry::primitiveEntry
50     const keyType& keyword,
51     const tokenList& tokens
54     entry(keyword),
55     ITstream(keyword, tokens)
59 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
61 Foam::label Foam::primitiveEntry::startLineNumber() const
63     if (size())
64     {
65         return operator[](0).lineNumber();
66     }
67     else
68     {
69         return -1;
70     }
73 Foam::label Foam::primitiveEntry::endLineNumber() const
75     if (size())
76     {
77         return operator[](size()-1).lineNumber();
78     }
79     else
80     {
81         return -1;
82     }
86 Foam::ITstream& Foam::primitiveEntry::stream() const
88     ITstream& dataStream = const_cast<primitiveEntry&>(*this);
89     dataStream.rewind();
90     return dataStream;
94 const Foam::dictionary& Foam::primitiveEntry::dict() const
96     FatalErrorIn("const dictionary& primitiveEntry::dict() const")
97         << "Attempt to return primitive entry " << info()
98         << " as a sub-dictionary"
99         << abort(FatalError);
101     return dictionary::null;
105 Foam::dictionary& Foam::primitiveEntry::dict()
107     FatalErrorIn("const dictionary& primitiveEntry::dict()")
108         << "Attempt to return primitive entry " << info()
109         << " as a sub-dictionary"
110         << abort(FatalError);
112     return const_cast<dictionary&>(dictionary::null);
116 void Foam::primitiveEntry::insert
118     const tokenList& varTokens,
119     const label posI
122     tokenList& tokens = *this;
124     if (varTokens.empty())
125     {
126         label end = tokens.size() - 1;
128         for (label j=posI; j<end; j++)
129         {
130             tokens[j] = tokens[j+1];
131         }
133         tokens.setSize(tokens.size() - 1);
134     }
135     else if (varTokens.size() > 1)
136     {
137         tokens.setSize(tokens.size() + varTokens.size() - 1);
139         label end = tokens.size() - 1;
140         label offset = varTokens.size() - 1;
142         for (label j=end; j>posI; j--)
143         {
144             tokens[j] = tokens[j-offset];
145         }
146     }
148     forAll(varTokens, j)
149     {
150         tokens[posI + j] = varTokens[j];
151     }
155 // ************************************************************************* //