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-2015 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:
104 
105  addToUsageTable(const word& name, const string& msg)
106  {
107  if (!usageTablePtr_)
108  {
110  }
111  usageTablePtr_->insert(name, msg);
112  }
113 
115  {
116  if (usageTablePtr_)
117  {
118  delete usageTablePtr_;
119  usageTablePtr_ = NULL;
120  }
121  }
122  };
123 
124 
125  // Protected data
126 
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 
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:
202 
203  iNew(const polyMesh& mesh)
204  :
205  mesh_(mesh)
206  {}
207 
209  {
210  word topoSetSourceType(is);
211  dictionary dict(is);
212  return topoSetSource::New(topoSetSourceType, mesh_, dict);
213  }
214  };
215 
216 
217  static const string& usage(const word& name)
218  {
219  if (!usageTablePtr_)
220  {
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>(NULL);
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
274 
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 // ************************************************************************* //
Foam::topoSetSource::iNew::operator()
autoPtr< topoSetSource > operator()(Istream &is) const
Definition: topoSetSource.H:207
Foam::topoSetSource::~topoSetSource
virtual ~topoSetSource()
Destructor.
Definition: topoSetSource.C:167
Foam::topoSetSource::usageTablePtr_
static HashTable< string > * usageTablePtr_
A table of usage strings.
Definition: topoSetSource.H:97
Foam::topoSetSource::sourceType
sourceType
Enumeration defining the types of sources.
Definition: topoSetSource.H:70
Foam::topoSetSource::ADD
@ ADD
Definition: topoSetSource.H:87
Foam::topoSetSource::CLEAR
@ CLEAR
Definition: topoSetSource.H:84
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
HashTable.H
Foam::topoSetSource::FACESETSOURCE
@ FACESETSOURCE
Definition: topoSetSource.H:73
Foam::topoSetSource::addToUsageTable::~addToUsageTable
~addToUsageTable()
Definition: topoSetSource.H:113
typeInfo.H
Foam::topoSetSource::toAction
static setAction toAction(const word &actionName)
Convert string to action.
Definition: topoSetSource.H:157
Foam::topoSetSource::FACEZONESOURCE
@ FACEZONESOURCE
Definition: topoSetSource.H:77
Foam::topoSetSource::POINTZONESOURCE
@ POINTZONESOURCE
Definition: topoSetSource.H:78
NamedEnum.H
Foam::topoSetSource::usage
static const string & usage(const word &name)
Definition: topoSetSource.H:216
Foam::topoSetSource::addToUsageTable
Class with constructor to add usage string to table.
Definition: topoSetSource.H:100
Foam::topoSetSource::topoSetSource
topoSetSource(const topoSetSource &)
Disallow default bitwise copy construct.
Foam::topoSetSource::setAction
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:82
Foam::topoSetSource::illegalSource_
static const string illegalSource_
Definition: topoSetSource.H:136
Foam::topoSetSource::NEW
@ NEW
Definition: topoSetSource.H:85
faceList.H
Foam::topoSetSource::mesh
const polyMesh & mesh() const
Definition: topoSetSource.H:274
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Foam::topoSetSource::iNew::mesh_
const polyMesh & mesh_
Definition: topoSetSource.H:198
NotImplemented
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:365
Foam::label
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
Foam::topoSetSource::applyToSet
virtual void applyToSet(const setAction action, topoSet &) const =0
Foam::topoSetSource::POINTSETSOURCE
@ POINTSETSOURCE
Definition: topoSetSource.H:74
labelList.H
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:57
Foam::topoSetSource::CELLZONESOURCE
@ CELLZONESOURCE
Definition: topoSetSource.H:76
Foam::topoSetSource::DELETE
@ DELETE
Definition: topoSetSource.H:88
Foam::topoSetSource::TypeName
TypeName("topoSetSource")
Runtime type information.
Foam::topoSetSource::operator=
void operator=(const topoSetSource &)
Disallow default bitwise assignment.
Foam::topoSet
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:61
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::topoSetSource::SUBSET
@ SUBSET
Definition: topoSetSource.H:89
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
Foam::topoSetSource::clone
autoPtr< topoSetSource > clone() const
Clone.
Definition: topoSetSource.H:242
Foam::topoSetSource::CELLSETSOURCE
@ CELLSETSOURCE
Definition: topoSetSource.H:72
Foam::HashTable::found
bool found(const Key &) const
Return true if hashedEntry is found in table.
Definition: HashTable.C:109
Foam::topoSetSource::New
static autoPtr< topoSetSource > New(const word &topoSetSourceType, const polyMesh &mesh, const dictionary &dict)
Return a reference to the selected topoSetSource.
Definition: topoSetSource.C:74
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::topoSetSource
Base class of a source for a topoSet.
Definition: topoSetSource.H:63
Foam::topoSetSource::iNew::iNew
iNew(const polyMesh &mesh)
Definition: topoSetSource.H:202
Foam::topoSetSource::actionNames_
static const NamedEnum< setAction, 8 > actionNames_
Definition: topoSetSource.H:134
Foam::HashTable
An STL-conforming hash table.
Definition: HashTable.H:61
pointField.H
Foam::autoPtr
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:117
Foam::topoSetSource::declareRunTimeSelectionTable
declareRunTimeSelectionTable(autoPtr, topoSetSource, word,(const polyMesh &mesh, const dictionary &dict),(mesh, dict))
Foam::topoSetSource::LIST
@ LIST
Definition: topoSetSource.H:90
runTimeSelectionTables.H
Macros to ease declaration of run-time selection tables.
Foam::topoSetSource::checkIs
static Istream & checkIs(Istream &is)
Check state of stream.
Definition: topoSetSource.C:121
Foam::topoSetSource::setType
virtual sourceType setType() const =0
Foam::topoSetSource::REMOVE
@ REMOVE
Definition: topoSetSource.H:91
Foam::topoSetSource::INVERT
@ INVERT
Definition: topoSetSource.H:86
Foam::topoSetSource::addToUsageTable::addToUsageTable
addToUsageTable(const word &name, const string &msg)
Definition: topoSetSource.H:104
word.H
Foam::topoSetSource::mesh_
const polyMesh & mesh_
Definition: topoSetSource.H:126
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
Foam::topoSetSource::addOrDelete
void addOrDelete(topoSet &set, const label cellI, const bool) const
Add (if bool) cellI to set or delete cellI from set.
Definition: topoSetSource.C:140
Foam::NamedEnum< setAction, 8 >
Foam::topoSetSource::iNew
Class used for the read-construction of.
Definition: topoSetSource.H:196
autoPtr.H