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

token.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 <OpenFOAM/token.H>
00027 
00028 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00029 
00030 const char* const Foam::token::typeName = "token";
00031 Foam::token Foam::token::undefinedToken;
00032 
00033 defineTypeNameAndDebug(Foam::token::compound, 0);
00034 defineRunTimeSelectionTable(Foam::token::compound, Istream);
00035 
00036 
00037 // * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * * //
00038 
00039 void Foam::token::parseError(const char* expected) const
00040 {
00041     FatalIOError
00042         << "Parse error, expected a " << expected
00043         << ", found \n    " << info() << endl;
00044 }
00045 
00046 
00047 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00048 
00049 Foam::token::compound::~compound()
00050 {}
00051 
00052 
00053 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
00054 
00055 Foam::autoPtr<Foam::token::compound> Foam::token::compound::New
00056 (
00057     const word& compoundType,
00058     Istream& is
00059 )
00060 {
00061     IstreamConstructorTable::iterator cstrIter =
00062         IstreamConstructorTablePtr_->find(compoundType);
00063 
00064     if (cstrIter == IstreamConstructorTablePtr_->end())
00065     {
00066         FatalErrorIn("token::compound::New(const word&, Istream&)")
00067             << "Unknown compound type " << compoundType << nl << nl
00068             << "Valid compound types:" << endl
00069             << IstreamConstructorTablePtr_->sortedToc()
00070             << abort(FatalError);
00071     }
00072 
00073     return autoPtr<Foam::token::compound>(cstrIter()(is));
00074 }
00075 
00076 
00077 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00078 
00079 bool Foam::token::compound::isCompound(const word& name)
00080 {
00081     return
00082     (
00083         IstreamConstructorTablePtr_
00084      && IstreamConstructorTablePtr_->found(name)
00085     );
00086 }
00087 
00088 
00089 Foam::token::compound& Foam::token::transferCompoundToken()
00090 {
00091     if (type_ == COMPOUND)
00092     {
00093         if (compoundTokenPtr_->empty())
00094         {
00095             FatalErrorIn("token::transferCompoundToken()")
00096                 << "compound has already been transfered from token\n    "
00097                 << info() << abort(FatalError);
00098         }
00099         else
00100         {
00101             compoundTokenPtr_->empty() = true;
00102         }
00103 
00104         return *compoundTokenPtr_;
00105     }
00106     else
00107     {
00108         parseError("compound");
00109         return *compoundTokenPtr_;
00110     }
00111 }
00112 
00113 
00114 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines