initial commit for version 1.5.x patch release
[OpenFOAM-1.5.x.git] / src / meshTools / coordinateSystems / coordinateSystems.C
blobe8dce6bcf4c8a8bf2f12f50b5b916282a4a13873
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 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 "coordinateSystems.H"
28 #include "IOPtrList.H"
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 namespace Foam
34     defineTemplateTypeNameAndDebug(IOPtrList<coordinateSystem>, 0);
37 const Foam::word Foam::coordinateSystems::dataType("coordinateSystem");
39 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
41 Foam::coordinateSystems::coordinateSystems()
45 Foam::coordinateSystems::coordinateSystems
47     const objectRegistry& registry,
48     const word& name,
49     const fileName& instance
52     IOPtrList<coordinateSystem> newList
53     (
54         IOobject
55         (
56             name,
57             instance,
58             registry,
59             IOobject::READ_IF_PRESENT,
60             IOobject::NO_WRITE,
61             false               // don't register
62         )
63     );
65     transfer(newList);
69 Foam::coordinateSystems::coordinateSystems
71     const IOobject& io
74     IOPtrList<coordinateSystem> newList(io);
75     transfer(newList);
79 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
82 Foam::label Foam::coordinateSystems::find(const word& keyword) const
84     forAll(*this, i)
85     {
86         if (keyword == operator[](i).name())
87         {
88             return i;
89         }
90     }
92     return -1;
96 bool Foam::coordinateSystems::found(const word& keyword) const
98     return find(keyword) >= 0;
102 Foam::wordList Foam::coordinateSystems::toc() const
104     wordList keywords(size());
106     forAll(*this, i)
107     {
108         keywords[i] = operator[](i).name();
109     }
111     return keywords;
115 bool Foam::coordinateSystems::rewriteDict(dictionary& dict, bool noType) const
117     if (dict.found(dataType) && !dict.isDict(dataType))
118     {
119         word name(dict.lookup(dataType));
120         label i = find(name);
122         if (i >= 0)
123         {
124             dict.remove(dataType);
125             dict.add(dataType, operator[](i).dict(noType));
126             return true;
127         }
129         FatalErrorIn
130         (
131             "Foam::coordinateSystems::rewriteDict(dictionary&, bool) const"
132         )   << "could not rewrite " << dataType << " " << name << nl
133             << "available coordinate systems: " << toc() << nl << nl
134             << "context: " << nl
135             << dict << nl
136             << exit(FatalError);
137     }
139     return false;
143 bool Foam::coordinateSystems::writeData(Ostream& os, bool subDict) const
145     // Write size of list
146     os << nl << size();
148     // Write beginning of contents
149     os << nl << token::BEGIN_LIST;
151     // Write list contents
152     forAll(*this, i)
153     {
154         os << nl;
155         operator[](i).writeDict(os, subDict);
156     }
158     // Write end of contents
159     os << token::END_LIST << nl;
161     // Check state of IOstream
162     return os.good();
166 // ************************************************************************* //