Merge branch 'upstream/OpenFOAM' into master
[freefoam.git] / src / meshTools / sets / topoSetSource / topoSetSource.H
blob9b0aa212e3ac5897d987d1ceac7e2ad309c0ded2
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     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, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Class
26     Foam::topoSetSource
28 Description
29     Base class of a source for a topoSet.
31     Implementer has to modify the given set (see applyToSet) according to
32     its function and the setAction (one of add/delete/new)
34 SourceFiles
35     topoSetSource.C
37 \*---------------------------------------------------------------------------*/
39 #ifndef topoSetSource_H
40 #define topoSetSource_H
42 #include <OpenFOAM/pointField.H>
43 #include <OpenFOAM/word.H>
44 #include <OpenFOAM/labelList.H>
45 #include <OpenFOAM/faceList.H>
46 #include <OpenFOAM/typeInfo.H>
47 #include <OpenFOAM/runTimeSelectionTables.H>
48 #include <OpenFOAM/autoPtr.H>
49 #include <OpenFOAM/NamedEnum.H>
50 #include <OpenFOAM/HashTable.H>
52 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
54 namespace Foam
57 // Forward declaration of classes
58 class polyMesh;
59 class topoSet;
61 /*---------------------------------------------------------------------------*\
62                            Class topoSetSource Declaration
63 \*---------------------------------------------------------------------------*/
65 class topoSetSource
67 public:
69     // Public data types
71         //- Enumeration defining the valid actions
72         enum setAction
73         {
74             CLEAR,
75             NEW,
76             INVERT,
77             ADD,
78             DELETE,
79             SUBSET,
80             LIST
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, 7> 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 // ************************ vim: set sw=4 sts=4 et: ************************ //