Initial commit for version 2.0.x patch release
[OpenFOAM-2.0.x.git] / src / meshTools / sets / topoSetSource / topoSetSource.H
blobb8371bfc0bf7300619240a1abd065a0e418ed8bd
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2004-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 types of sources
71         enum sourceType
72         {
73             CELLSETSOURCE,
74             FACESETSOURCE,
75             POINTSETSOURCE,
77             CELLZONESOURCE,
78             FACEZONESOURCE,
79             POINTZONESOURCE
80         };
82         //- Enumeration defining the valid actions
83         enum setAction
84         {
85             CLEAR,
86             NEW,
87             INVERT,
88             ADD,
89             DELETE,
90             SUBSET,
91             LIST,
92             REMOVE
93         };
95 protected:
97         //- A table of usage strings
98         static HashTable<string>* usageTablePtr_;
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             }
114             ~addToUsageTable()
115             {
116                 if (usageTablePtr_)
117                 {
118                     delete usageTablePtr_;
119                     usageTablePtr_ = NULL;
120                 }
121             }
122         };
125     // Protected data
127         const polyMesh& mesh_;
129         //- Add (if bool) cellI to set or delete cellI from set.
130         void addOrDelete(topoSet& set, const label cellI, const bool) const;
133 private:
135         static const NamedEnum<setAction, 8> actionNames_;
137         static const string illegalSource_;
140     // Private Member Functions
142         //- Disallow default bitwise copy construct
143         topoSetSource(const topoSetSource&);
145         //- Disallow default bitwise assignment
146         void operator=(const topoSetSource&);
149 public:
151     //- Runtime type information
152     TypeName("topoSetSource");
155     // Static Functions
157         //- Convert string to action
158         static setAction toAction(const word& actionName)
159         {
160             return actionNames_[actionName];
161         }
163         //- Check state of stream.
164         static Istream& checkIs(Istream& is);
166     // Declare run-time constructor selection table
168         // For the dictionary constructor
169         declareRunTimeSelectionTable
170         (
171             autoPtr,
172             topoSetSource,
173             word,
174             (
175                 const polyMesh& mesh,
176                 const dictionary& dict
177             ),
178             (mesh, dict)
179         );
181         // For the Istream constructor
182         declareRunTimeSelectionTable
183         (
184             autoPtr,
185             topoSetSource,
186             istream,
187             (
188                 const polyMesh& mesh,
189                 Istream& is
190             ),
191             (mesh, is)
192         );
195         //- Class used for the read-construction of
196         //  PtrLists of topoSetSource
197         class iNew
198         {
199             const polyMesh& mesh_;
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         };
217         static const string& usage(const word& name)
218         {
219             if (!usageTablePtr_)
220             {
221                 usageTablePtr_ = new HashTable<string>();
222             }
224             const HashTable<string>& usageTable = *usageTablePtr_;
226             if (usageTable.found(name))
227             {
228                 return usageTable[name];
229             }
230             else
231             {
232                 return illegalSource_;
233             }
234         }
237     // Constructors
239         //- Construct from components
240         topoSetSource(const polyMesh& mesh);
242         //- Clone
243         autoPtr<topoSetSource> clone() const
244         {
245             notImplemented("autoPtr<topoSetSource> clone() const");
246             return autoPtr<topoSetSource>(NULL);
247         }
250     // Selectors
252         //- Return a reference to the selected topoSetSource
253         static autoPtr<topoSetSource> New
254         (
255             const word& topoSetSourceType,
256             const polyMesh& mesh,
257             const dictionary& dict
258         );
260         //- Return a reference to the selected topoSetSource
261         static autoPtr<topoSetSource> New
262         (
263             const word& topoSetSourceType,
264             const polyMesh& mesh,
265             Istream& is
266         );
269     //- Destructor
270     virtual ~topoSetSource();
273     // Member Functions
275         const polyMesh& mesh() const
276         {
277             return mesh_;
278         }
281     // Member Functions
283         virtual sourceType setType() const = 0;
285         virtual void applyToSet(const setAction action, topoSet&) const = 0;
290 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
292 } // End namespace Foam
294 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
296 #endif
298 // ************************************************************************* //