FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

primitiveEntry.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software: you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
00023 
00024 \*---------------------------------------------------------------------------*/
00025 
00026 #include "primitiveEntry.H"
00027 #include <OpenFOAM/dictionary.H>
00028 
00029 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00030 
00031 Foam::primitiveEntry::primitiveEntry(const keyType& key, const ITstream& tokens)
00032 :
00033     entry(key),
00034     ITstream(tokens)
00035 {
00036     name() += "::" + keyword();
00037 }
00038 
00039 
00040 Foam::primitiveEntry::primitiveEntry(const keyType& keyword, const token& t)
00041 :
00042     entry(keyword),
00043     ITstream(keyword, tokenList(1, t))
00044 {}
00045 
00046 
00047 Foam::primitiveEntry::primitiveEntry
00048 (
00049     const keyType& keyword,
00050     const tokenList& tokens
00051 )
00052 :
00053     entry(keyword),
00054     ITstream(keyword, tokens)
00055 {}
00056 
00057 
00058 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00059 
00060 Foam::label Foam::primitiveEntry::startLineNumber() const
00061 {
00062     if (size())
00063     {
00064         return operator[](0).lineNumber();
00065     }
00066     else
00067     {
00068         return -1;
00069     }
00070 }
00071 
00072 Foam::label Foam::primitiveEntry::endLineNumber() const
00073 {
00074     if (size())
00075     {
00076         return operator[](size()-1).lineNumber();
00077     }
00078     else
00079     {
00080         return -1;
00081     }
00082 }
00083 
00084 
00085 Foam::ITstream& Foam::primitiveEntry::stream() const
00086 {
00087     ITstream& dataStream = const_cast<primitiveEntry&>(*this);
00088     dataStream.rewind();
00089     return dataStream;
00090 }
00091 
00092 
00093 const Foam::dictionary& Foam::primitiveEntry::dict() const
00094 {
00095     FatalErrorIn("const dictionary& primitiveEntry::dict() const")
00096         << "Attempt to return primitive entry " << info()
00097         << " as a sub-dictionary"
00098         << abort(FatalError);
00099 
00100     return dictionary::null;
00101 }
00102 
00103 
00104 Foam::dictionary& Foam::primitiveEntry::dict()
00105 {
00106     FatalErrorIn("const dictionary& primitiveEntry::dict()")
00107         << "Attempt to return primitive entry " << info()
00108         << " as a sub-dictionary"
00109         << abort(FatalError);
00110 
00111     return const_cast<dictionary&>(dictionary::null);
00112 }
00113 
00114 
00115 void Foam::primitiveEntry::insert
00116 (
00117     const tokenList& varTokens,
00118     const label posI
00119 )
00120 {
00121     tokenList& tokens = *this;
00122 
00123     if (varTokens.empty())
00124     {
00125         label end = tokens.size() - 1;
00126 
00127         for (label j=posI; j<end; j++)
00128         {
00129             tokens[j] = tokens[j+1];
00130         }
00131 
00132         tokens.setSize(tokens.size() - 1);
00133     }
00134     else if (varTokens.size() > 1)
00135     {
00136         tokens.setSize(tokens.size() + varTokens.size() - 1);
00137 
00138         label end = tokens.size() - 1;
00139         label offset = varTokens.size() - 1;
00140 
00141         for (label j=end; j>posI; j--)
00142         {
00143             tokens[j] = tokens[j-offset];
00144         }
00145     }
00146 
00147     forAll(varTokens, j)
00148     {
00149         tokens[posI + j] = varTokens[j];
00150     }
00151 }
00152 
00153 
00154 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines