topoSetSource.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) 2011-2016 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  // Private Member Functions
141 
142  //- Disallow default bitwise copy construct
144 
145  //- Disallow default bitwise assignment
146  void operator=(const topoSetSource&);
147 
148 
149 public:
150 
151  //- Runtime type information
152  TypeName("topoSetSource");
153 
154 
155  // Static Functions
156 
157  //- Convert string to action
158  static setAction toAction(const word& actionName)
159  {
160  return actionNames_[actionName];
161  }
162 
163  //- Check state of stream.
164  static Istream& checkIs(Istream& is);
165 
166  // Declare run-time constructor selection table
167 
168  // For the dictionary constructor
170  (
171  autoPtr,
173  word,
174  (
175  const polyMesh& mesh,
176  const dictionary& dict
177  ),
178  (mesh, dict)
179  );
180 
181  // For the Istream constructor
183  (
184  autoPtr,
186  istream,
187  (
188  const polyMesh& mesh,
189  Istream& is
190  ),
191  (mesh, is)
192  );
193 
194 
195  //- Class used for the read-construction of
196  // PtrLists of topoSetSource
197  class iNew
198  {
199  const polyMesh& mesh_;
200 
201  public:
203  iNew(const polyMesh& mesh)
204  :
205  mesh_(mesh)
206  {}
208  autoPtr<topoSetSource> operator()(Istream& is) const
209  {
210  word topoSetSourceType(is);
211  dictionary dict(is);
212  return topoSetSource::New(topoSetSourceType, mesh_, dict);
213  }
214  };
215 
217  static const string& usage(const word& name)
218  {
219  if (!usageTablePtr_)
220  {
221  usageTablePtr_ = new HashTable<string>();
222  }
223 
224  const HashTable<string>& usageTable = *usageTablePtr_;
225 
226  if (usageTable.found(name))
227  {
228  return usageTable[name];
229  }
230  else
231  {
232  return illegalSource_;
233  }
234  }
235 
236 
237  // Constructors
238 
239  //- Construct from components
240  topoSetSource(const polyMesh& mesh);
241 
242  //- Clone
244  {
246  return autoPtr<topoSetSource>(nullptr);
247  }
248 
249 
250  // Selectors
251 
252  //- Return a reference to the selected topoSetSource
254  (
255  const word& topoSetSourceType,
256  const polyMesh& mesh,
257  const dictionary& dict
258  );
259 
260  //- Return a reference to the selected topoSetSource
262  (
263  const word& topoSetSourceType,
264  const polyMesh& mesh,
265  Istream& is
266  );
267 
268 
269  //- Destructor
270  virtual ~topoSetSource();
271 
272 
273  // Member Functions
275  const polyMesh& mesh() const
276  {
277  return mesh_;
278  }
279 
280 
281  // Member Functions
282 
283  virtual sourceType setType() const = 0;
284 
285  virtual void applyToSet(const setAction action, topoSet&) const = 0;
286 
287 };
288 
289 
290 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
291 
292 } // End namespace Foam
293 
294 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
295 
296 #endif
297 
298 // ************************************************************************* //
dictionary dict
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
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:137
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:62
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.