topoSetSource.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
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::topoSetSource
26 
27 Description
28  Base class of a source for a topoSet.
29 
30  Implementer has to modify the given set (see applyToSet) according to
31  its function and the setAction (one of add/delete/new)
32 
33 SourceFiles
34  topoSetSource.C
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #ifndef topoSetSource_H
39 #define topoSetSource_H
40 
41 #include "pointField.H"
42 #include "word.H"
43 #include "labelList.H"
44 #include "faceList.H"
45 #include "typeInfo.H"
46 #include "runTimeSelectionTables.H"
47 #include "autoPtr.H"
48 #include "NamedEnum.H"
49 #include "HashTable.H"
50 
51 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
52 
53 namespace Foam
54 {
55 
56 // Forward declaration of classes
57 class polyMesh;
58 class topoSet;
59 
60 /*---------------------------------------------------------------------------*\
61  Class topoSetSource Declaration
62 \*---------------------------------------------------------------------------*/
63 
64 class topoSetSource
65 {
66 public:
67 
68  // Public data types
69 
70  //- Enumeration defining the types of sources
71  enum sourceType
72  {
76 
80  };
81 
82  //- Enumeration defining the valid actions
83  enum setAction
84  {
86  NEW,
88  ADD,
92  REMOVE
93  };
94 
95 protected:
96 
97  //- A table of usage strings
99 
100  //- Class with constructor to add usage string to table
101  class addToUsageTable
102  {
103  public:
105  addToUsageTable(const word& name, const string& msg)
106  {
107  if (!usageTablePtr_)
108  {
109  usageTablePtr_ = new HashTable<string>();
110  }
111  usageTablePtr_->insert(name, msg);
112  }
115  {
116  if (usageTablePtr_)
117  {
118  delete usageTablePtr_;
119  usageTablePtr_ = nullptr;
120  }
121  }
122  };
123 
124 
125  // Protected data
127  const polyMesh& mesh_;
128 
129  //- Add (if bool) celli to set or delete celli from set.
130  void addOrDelete(topoSet& set, const label celli, const bool) const;
131 
132 
133 private:
134 
135  static const NamedEnum<setAction, 8> actionNames_;
136 
137  static const string illegalSource_;
138 
139 
140 public:
141 
142  //- Runtime type information
143  TypeName("topoSetSource");
144 
145 
146  // Static Functions
147 
148  //- Convert string to action
149  static setAction toAction(const word& actionName)
150  {
151  return actionNames_[actionName];
152  }
153 
154  //- Check state of stream.
155  static Istream& checkIs(Istream& is);
156 
157  // Declare run-time constructor selection table
158 
159  // For the dictionary constructor
161  (
162  autoPtr,
164  word,
165  (
166  const polyMesh& mesh,
167  const dictionary& dict
168  ),
169  (mesh, dict)
170  );
171 
172  // For the Istream constructor
174  (
175  autoPtr,
177  istream,
178  (
179  const polyMesh& mesh,
180  Istream& is
181  ),
182  (mesh, is)
183  );
184 
185 
186  //- Class used for the read-construction of
187  // PtrLists of topoSetSource
188  class iNew
189  {
190  const polyMesh& mesh_;
191 
192  public:
194  iNew(const polyMesh& mesh)
195  :
196  mesh_(mesh)
197  {}
199  autoPtr<topoSetSource> operator()(Istream& is) const
200  {
201  word topoSetSourceType(is);
202  dictionary dict(is);
203  return topoSetSource::New(topoSetSourceType, mesh_, dict);
204  }
205  };
206 
208  static const string& usage(const word& name)
209  {
210  if (!usageTablePtr_)
211  {
212  usageTablePtr_ = new HashTable<string>();
213  }
214 
215  const HashTable<string>& usageTable = *usageTablePtr_;
216 
217  if (usageTable.found(name))
218  {
219  return usageTable[name];
220  }
221  else
222  {
223  return illegalSource_;
224  }
225  }
226 
227 
228  // Constructors
229 
230  //- Construct from components
231  topoSetSource(const polyMesh& mesh);
232 
233  //- Disallow default bitwise copy construction
234  topoSetSource(const topoSetSource&) = delete;
235 
236  //- Clone
238  {
240  return autoPtr<topoSetSource>(nullptr);
241  }
242 
243 
244  // Selectors
245 
246  //- Return a reference to the selected topoSetSource
248  (
249  const word& topoSetSourceType,
250  const polyMesh& mesh,
251  const dictionary& dict
252  );
253 
254  //- Return a reference to the selected topoSetSource
256  (
257  const word& topoSetSourceType,
258  const polyMesh& mesh,
259  Istream& is
260  );
261 
262 
263  //- Destructor
264  virtual ~topoSetSource();
265 
266 
267  // Member Functions
269  const polyMesh& mesh() const
270  {
271  return mesh_;
272  }
273 
274 
275  // Member Functions
276 
277  virtual sourceType setType() const = 0;
278 
279  virtual void applyToSet(const setAction action, topoSet&) const = 0;
280 
281 
282  // Member Operators
283 
284  //- Disallow default bitwise assignment
285  void operator=(const topoSetSource&) = delete;
286 };
287 
288 
289 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
290 
291 } // End namespace Foam
292 
293 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
294 
295 #endif
296 
297 // ************************************************************************* //
dictionary dict
void operator=(const topoSetSource &)=delete
Disallow default bitwise assignment.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
topoSetSource(const polyMesh &mesh)
Construct from components.
static const string & usage(const word &name)
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
declareRunTimeSelectionTable(autoPtr, topoSetSource, word,(const polyMesh &mesh, const dictionary &dict),(mesh, dict))
static Istream & checkIs(Istream &is)
Check state of stream.
virtual sourceType setType() const =0
void addOrDelete(topoSet &set, const label celli, const bool) const
Add (if bool) celli to set or delete celli from set.
Base class of a source for a topoSet.
Definition: topoSetSource.H:63
const polyMesh & mesh() const
bool insert(const Key &, const T &newElmt)
Insert a new hashedEntry.
Definition: HashTableI.H:80
Class used for the read-construction of.
bool found(const Key &) const
Return true if hashedEntry is found in table.
Definition: HashTable.C:113
A class for handling words, derived from string.
Definition: word.H:59
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:82
An STL-conforming hash table.
Definition: HashTable.H:61
TypeName("topoSetSource")
Runtime type information.
const polyMesh & mesh_
addToUsageTable(const word &name, const string &msg)
autoPtr< topoSetSource > clone() const
Clone.
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:61
static autoPtr< topoSetSource > New(const word &topoSetSourceType, const polyMesh &mesh, const dictionary &dict)
Return a reference to the selected topoSetSource.
Definition: topoSetSource.C:74
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
Class with constructor to add usage string to table.
virtual ~topoSetSource()
Destructor.
static HashTable< string > * usageTablePtr_
A table of usage strings.
Definition: topoSetSource.H:97
sourceType
Enumeration defining the types of sources.
Definition: topoSetSource.H:70
static setAction toAction(const word &actionName)
Convert string to action.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Macros to ease declaration of run-time selection tables.
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:366
virtual void applyToSet(const setAction action, topoSet &) const =0
Namespace for OpenFOAM.