FreeFOAM The Cross-Platform CFD Toolkit
ZoneID.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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.
20 
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/>.
23 
24 Class
25  Foam::ZoneID
26 
27 Description
28  A class that holds the data needed to identify a zone in a dynamic mesh.
29 
30  The zone is identified by name.
31  Its index in the zoneMesh is updated if the mesh has changed.
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef ZoneID_H
36 #define ZoneID_H
37 
38 #include <OpenFOAM/label.H>
39 #include <OpenFOAM/word.H>
40 #include <OpenFOAM/polyMesh.H>
41 
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 
44 namespace Foam
45 {
46 
47 template<class ZoneType, class MeshType> class ZoneMesh;
48 
49 // Forward declaration of friend functions and operators
50 
51 template<class ZoneType> class ZoneID;
52 
53 template<class ZoneType>
54 Ostream& operator<<(Ostream&, const ZoneID<ZoneType>&);
55 
56 /*---------------------------------------------------------------------------*\
57  Class ZoneID Declaration
58 \*---------------------------------------------------------------------------*/
59 
60 template<class ZoneType>
61 class ZoneID
62 {
63  // Private data
64 
65  //- Zone name
66  word name_;
67 
68  //- Zone index
69  label index_;
70 
71 
72 public:
73 
74  // Constructors
75 
76  //- Construct from name
78  :
79  name_(name),
80  index_(zm.findZoneID(name))
81  {}
82 
83  //- Construct from Istream
85  :
86  name_(is),
87  index_(zm.findZoneID(name_))
88  {}
89 
90 
91  // Destructor - default
92 
93 
94  // Member Functions
95 
96  // Access
97 
98  //- Return name
99  const word& name() const
100  {
101  return name_;
102  }
103 
104  //- Return index
105  label index() const
106  {
107  return index_;
108  }
109 
110  //- Has the zone been found
111  bool active() const
112  {
113  return index_ > -1;
114  }
115 
116  // Edit
117 
118  //- Update
120  {
121  index_ = zm.findZoneID(name_);
122  }
123 
124 
125  // IOstream Operators
126 
127  friend Ostream& operator<< <ZoneType>
128  (
129  Ostream& os, const ZoneID<ZoneType>& p
130  );
131 };
132 
133 
134 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
135 
136 template<class ZoneType>
137 Ostream& operator<<
138 (
139  Ostream& os, const ZoneID<ZoneType>& p
140 )
141 {
142  os << token::BEGIN_LIST
143  << p.name_ << token::SPACE
144  << p.index_
145  << token::END_LIST;
146 
147  // Check state of Ostream
148  os.check("Ostream& operator<<(Ostream&, const ZoneID<ZoneType>&)");
149 
150  return os;
151 }
152 
153 
154 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
155 
156 } // End namespace Foam
157 
158 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
159 
160 #endif
161 
162 // ************************ vim: set sw=4 sts=4 et: ************************ //