1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
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
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)
37 name() += "::" + keyword();
41 Foam::primitiveEntry::primitiveEntry(const keyType& keyword, const token& t)
44 ITstream(keyword, tokenList(1, t))
48 Foam::primitiveEntry::primitiveEntry
50 const keyType& keyword,
51 const tokenList& tokens
55 ITstream(keyword, tokens)
59 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
61 Foam::label Foam::primitiveEntry::startLineNumber() const
65 return operator[](0).lineNumber();
73 Foam::label Foam::primitiveEntry::endLineNumber() const
77 return operator[](size()-1).lineNumber();
86 Foam::ITstream& Foam::primitiveEntry::stream() const
88 ITstream& dataStream = const_cast<primitiveEntry&>(*this);
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"
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,
122 tokenList& tokens = *this;
124 if (varTokens.empty())
126 label end = tokens.size() - 1;
128 for (label j=posI; j<end; j++)
130 tokens[j] = tokens[j+1];
133 tokens.setSize(tokens.size() - 1);
135 else if (varTokens.size() > 1)
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--)
144 tokens[j] = tokens[j-offset];
150 tokens[posI + j] = varTokens[j];
155 // ************************************************************************* //