ENH: patchCloud: return pTraits<Type>::max for unfound points
[OpenFOAM-1.7.x.git] / src / meshTools / sets / topoSetSource / topoSetSource.H
blob8585161774fe69bb71f08e459555f42bc645a0df
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.
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.
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.
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/>.
24 Class
25     Foam::topoSetSource
27 Description
28     Base class of a source for a topoSet.
30     Implementer has to modify the given set (see applyToSet) according to
31     its function and the setAction (one of add/delete/new)
33 SourceFiles
34     topoSetSource.C
36 \*---------------------------------------------------------------------------*/
38 #ifndef topoSetSource_H
39 #define topoSetSource_H
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"
51 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
53 namespace Foam
56 // Forward declaration of classes
57 class polyMesh;
58 class topoSet;
60 /*---------------------------------------------------------------------------*\
61                            Class topoSetSource Declaration
62 \*---------------------------------------------------------------------------*/
64 class topoSetSource
66 public:
68     // Public data types
70         //- Enumeration defining the valid actions
71         enum setAction
72         {
73             CLEAR,
74             NEW,
75             INVERT,
76             ADD,
77             DELETE,
78             SUBSET,
79             LIST,
80             REMOVE
81         };
83 protected:
85         //- A table of usage strings
86         static HashTable<string>* usageTablePtr_;
88         //- Class with constructor to add usage string to table
89         class addToUsageTable
90         {
91         public:
93             addToUsageTable(const word& name, const string& msg)
94             {
95                 if (!usageTablePtr_)
96                 {
97                     usageTablePtr_ = new HashTable<string>();
98                 }
99                 usageTablePtr_->insert(name, msg);
100             }
102             ~addToUsageTable()
103             {
104                 if (usageTablePtr_)
105                 {
106                     delete usageTablePtr_;
107                     usageTablePtr_ = NULL;
108                 }
109             }
110         };
113     // Protected data
115         const polyMesh& mesh_;
117         //- Add (if bool) cellI to set or delete cellI from set.
118         void addOrDelete(topoSet& set, const label cellI, const bool) const;
121 private:
123         static const NamedEnum<setAction, 8> actionNames_;
125         static const string illegalSource_;
128     // Private Member Functions
130         //- Disallow default bitwise copy construct
131         topoSetSource(const topoSetSource&);
133         //- Disallow default bitwise assignment
134         void operator=(const topoSetSource&);
137 public:
139     //- Runtime type information
140     TypeName("topoSetSource");
143     // Static Functions
145         //- Convert string to action
146         static setAction toAction(const word& actionName)
147         {
148             return actionNames_[actionName];
149         }
151         //- Check state of stream.
152         static Istream& checkIs(Istream& is);
154     // Declare run-time constructor selection table
156         // For the dictionary constructor
157         declareRunTimeSelectionTable
158         (
159             autoPtr,
160             topoSetSource,
161             word,
162             (
163                 const polyMesh& mesh,
164                 const dictionary& dict
165             ),
166             (mesh, dict)
167         );
169         // For the Istream constructor
170         declareRunTimeSelectionTable
171         (
172             autoPtr,
173             topoSetSource,
174             istream,
175             (
176                 const polyMesh& mesh,
177                 Istream& is
178             ),
179             (mesh, is)
180         );
183         //- Class used for the read-construction of
184         //  PtrLists of topoSetSource
185         class iNew
186         {
187             const polyMesh& mesh_;
189         public:
191             iNew(const polyMesh& mesh)
192             :
193                 mesh_(mesh)
194             {}
196             autoPtr<topoSetSource> operator()(Istream& is) const
197             {
198                 word topoSetSourceType(is);
199                 dictionary dict(is);
200                 return topoSetSource::New(topoSetSourceType, mesh_, dict);
201             }
202         };
205         static const string& usage(const word& name)
206         {
207             if (!usageTablePtr_)
208             {
209                 usageTablePtr_ = new HashTable<string>();
210             }
212             const HashTable<string>& usageTable = *usageTablePtr_;
214             if (usageTable.found(name))
215             {
216                 return usageTable[name];
217             }
218             else
219             {
220                 return illegalSource_;
221             }
222         }
225     // Constructors
227         //- Construct from components
228         topoSetSource(const polyMesh& mesh);
230         //- Clone
231         autoPtr<topoSetSource> clone() const
232         {
233             notImplemented("autoPtr<topoSetSource> clone() const");
234             return autoPtr<topoSetSource>(NULL);
235         }
238     // Selectors
240         //- Return a reference to the selected topoSetSource
241         static autoPtr<topoSetSource> New
242         (
243             const word& topoSetSourceType,
244             const polyMesh& mesh,
245             const dictionary& dict
246         );
248         //- Return a reference to the selected topoSetSource
249         static autoPtr<topoSetSource> New
250         (
251             const word& topoSetSourceType,
252             const polyMesh& mesh,
253             Istream& is
254         );
257     // Destructor
259         virtual ~topoSetSource();
262     // Member Functions
264         const polyMesh& mesh() const
265         {
266             return mesh_;
267         }
270     // Member Functions
272         virtual void applyToSet(const setAction action, topoSet&) const = 0;
277 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
279 } // End namespace Foam
281 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
283 #endif
285 // ************************************************************************* //