DynamicID.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011 OpenFOAM Foundation
9  Copyright (C) 2018-2021 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::DynamicID
29 
30 Description
31  A class that holds the data needed to identify things (zones, patches)
32  in a dynamic mesh.
33 
34  The thing is identified by name.
35  Its indices are updated if the mesh has changed.
36 
37 \*---------------------------------------------------------------------------*/
38 
39 #ifndef DynamicID_H
40 #define DynamicID_H
41 
42 #include "wordRe.H"
43 #include "labelList.H"
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 namespace Foam
48 {
49 
50 /*---------------------------------------------------------------------------*\
51  Class DynamicID Declaration
52 \*---------------------------------------------------------------------------*/
53 
54 template<class ObjectType>
55 class DynamicID
56 {
57  // Private Data
58 
59  //- Selector name
60  wordRe key_;
61 
62  //- Selection indices
63  labelList indices_;
64 
65 
66 public:
67 
68  // Constructors
69 
70  //- Construct from selector name and object
71  DynamicID(const wordRe& key, const ObjectType& obj)
72  :
73  key_(key),
74  indices_(obj.indices(key_))
75  {}
76 
77  //- Construct from selector name and object
78  DynamicID(wordRe&& key, const ObjectType& obj)
79  :
80  key_(std::move(key)),
81  indices_(obj.indices(key_))
82  {}
83 
84  //- Construct from selector name and object
85  DynamicID(const word& key, const ObjectType& obj)
86  :
87  DynamicID(wordRe(key), obj)
88  {}
89 
90  //- Construct from selector name and object
91  DynamicID(const keyType& key, const ObjectType& obj)
92  :
93  DynamicID(wordRe(key), obj)
94  {}
95 
96  //- Construct from Istream and object
97  DynamicID(Istream& is, const ObjectType& obj)
98  :
99  DynamicID(wordRe(is), obj)
100  {}
101 
102 
103  //- Destructor
104  ~DynamicID() = default;
105 
106 
107  // Member Functions
108 
109  // Access
110 
111  //- The selector name
112  const wordRe& name() const noexcept
113  {
114  return key_;
115  }
116 
117  //- The indices of matching items
118  const labelList& indices() const noexcept
119  {
120  return indices_;
121  }
122 
123  //- The index of the first matching items, -1 if no matches
124  label index() const
125  {
126  return indices_.empty() ? -1 : indices_.first();
127  }
128 
129  //- Has the zone been found
130  bool active() const noexcept
131  {
132  return !indices_.empty();
133  }
134 
135 
136  // Edit
137 
138  //- Update
139  void update(const ObjectType& obj)
140  {
141  indices_ = obj.indices(key_);
142  }
143 };
144 
145 
146 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
148 template<class ObjectType>
149 Ostream& operator<<(Ostream& os, const DynamicID<ObjectType>& obj)
150 {
152  << obj.name() << token::SPACE << obj.index()
153  << token::END_LIST;
154 
156  return os;
157 }
159 
160 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
161 
162 } // End namespace Foam
163 
164 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
165 
166 #endif
167 
168 // ************************************************************************* //
void update(const ObjectType &obj)
Update.
Definition: DynamicID.H:158
A class for handling keywords in dictionaries.
Definition: keyType.H:66
const wordRe & name() const noexcept
The selector name.
Definition: DynamicID.H:123
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:45
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
bool empty() const noexcept
True if List is empty (ie, size() is zero)
Definition: UList.H:666
A class that holds the data needed to identify things (zones, patches) in a dynamic mesh...
Definition: DynamicID.H:48
T & first()
Access first element of the list, position [0].
Definition: UList.H:853
Begin list [isseparator].
Definition: token.H:161
bool active() const noexcept
Has the zone been found.
Definition: DynamicID.H:147
const labelList & indices() const noexcept
The indices of matching items.
Definition: DynamicID.H:131
A class for handling words, derived from Foam::string.
Definition: word.H:63
Space [isspace].
Definition: token.H:131
End list [isseparator].
Definition: token.H:162
~DynamicID()=default
Destructor.
A wordRe is a Foam::word, but can contain a regular expression for matching words or strings...
Definition: wordRe.H:78
DynamicID(const wordRe &key, const ObjectType &obj)
Construct from selector name and object.
Definition: DynamicID.H:70
label index() const
The index of the first matching items, -1 if no matches.
Definition: DynamicID.H:139
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
const direction noexcept
Definition: Scalar.H:258
OBJstream os(runTime.globalPath()/outputName)
#define FUNCTION_NAME
auto key(const Type &t) -> typename std::enable_if< std::is_enum< Type >::value, typename std::underlying_type< Type >::type >::type
Definition: foamGltfBase.H:103
Namespace for OpenFOAM.