initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / db / IOstreams / token / token.C
blobf74dbd7381eaee285962b76fbc9896fe4ccf8345
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 "token.H"
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 const char* const Foam::token::typeName = "token";
32 Foam::token Foam::token::undefinedToken;
34 defineTypeNameAndDebug(Foam::token::compound, 0);
35 defineRunTimeSelectionTable(Foam::token::compound, Istream);
38 // * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * * //
40 void Foam::token::parseError(const char* expected) const
42     FatalIOError
43         << "Parse error, expected a " << expected
44         << ", found \n    " << info() << endl;
48 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
50 Foam::token::compound::~compound()
54 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
56 Foam::autoPtr<Foam::token::compound> Foam::token::compound::New
58     const word& compoundType,
59     Istream& is
62     IstreamConstructorTable::iterator cstrIter =
63         IstreamConstructorTablePtr_->find(compoundType);
65     if (cstrIter == IstreamConstructorTablePtr_->end())
66     {
67         FatalErrorIn("token::compound::New(const word&, Istream&)")
68             << "Unknown compound type " << compoundType << nl << nl
69             << "Valid compound types:" << endl
70             << IstreamConstructorTablePtr_->toc()
71             << abort(FatalError);
72     }
74     return autoPtr<Foam::token::compound>(cstrIter()(is));
78 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
80 bool Foam::token::compound::isCompound(const word& name)
82     return
83     (
84         IstreamConstructorTablePtr_
85      && IstreamConstructorTablePtr_->found(name)
86     );
90 Foam::token::compound& Foam::token::transferCompoundToken()
92     if (type_ == COMPOUND)
93     {
94         if (compoundTokenPtr_->empty())
95         {
96             FatalErrorIn("token::transferCompoundToken()")
97                 << "compound has already been transfered from token\n    "
98                 << info() << abort(FatalError);
99         }
100         else
101         {
102             compoundTokenPtr_->empty() = true;
103         }
105         return *compoundTokenPtr_;
106     }
107     else
108     {
109         parseError("compound");
110         return *compoundTokenPtr_;
111     }
115 // ************************************************************************* //