1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
28 A class that holds the data needed to identify things (zones, patches)
31 The thing is identified by name.
32 Its indices are updated if the mesh has changed.
34 \*---------------------------------------------------------------------------*/
40 #include "labelList.H"
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 // Forward declaration of friend functions and operators
48 template<class> class DynamicID;
50 template<class ObjectType>
51 Ostream& operator<<(Ostream&, const DynamicID<ObjectType>&);
53 /*---------------------------------------------------------------------------*\
54 Class DynamicID Declaration
55 \*---------------------------------------------------------------------------*/
57 template<class ObjectType>
73 //- Construct from name
74 DynamicID(const keyType& key, const ObjectType& obj)
77 indices_(obj.findIndices(key_))
80 //- Construct from Istream
81 DynamicID(Istream& is, const ObjectType& obj)
84 indices_(obj.findIndices(key_))
88 // Destructor - default
96 const keyType& name() const
101 //- Return indices of matching zones
102 const labelList& indices() const
107 //- Return index of first matching zone
110 return indices_.empty() ? -1 : indices_[0];
113 //- Has the zone been found
116 return !indices_.empty();
123 void update(const ObjectType& obj)
125 indices_ = obj.findIndices(key_);
129 // IOstream Operators
131 friend Ostream& operator<< <ObjectType>
132 (Ostream&, const DynamicID<ObjectType>&);
136 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
138 template<class ObjectType>
139 Ostream& operator<<(Ostream& os, const DynamicID<ObjectType>& dynId)
141 os << token::BEGIN_LIST
142 << dynId.name() << token::SPACE << dynId.index()
145 // Check state of Ostream
146 os.check("Ostream& operator<<(Ostream&, const DynamicID<ObjectType>&)");
152 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
154 } // End namespace Foam
156 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
160 // ************************************************************************* //