OpenFOAM logo
The Open Source CFD Toolbox
  Programmer’s C++ Doxygen OpenCFD Solutions Contact OpenFOAM

topoSetSource.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2007 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Class
00026     topoSetSource
00027 
00028 Description
00029     Base class of source for a topoSet. Implementer has to modify
00030     the given set (see applyToSet) according to its function and the
00031     setAction (one of add/delete/new) 
00032 
00033 SourceFiles
00034     topoSetSource.C
00035 
00036 \*---------------------------------------------------------------------------*/
00037 
00038 #ifndef topoSetSource_H
00039 #define topoSetSource_H
00040 
00041 #include "pointField.H"
00042 #include "word.H"
00043 #include "labelList.H"
00044 #include "faceList.H"
00045 #include "typeInfo.H"
00046 #include "runTimeSelectionTables.H"
00047 #include "autoPtr.H"
00048 #include "NamedEnum.H"
00049 #include "HashTable.H"
00050 
00051 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00052 
00053 namespace Foam
00054 {
00055 
00056 // Class forward declarations
00057 class polyMesh;
00058 class topoSet;
00059 
00060 /*---------------------------------------------------------------------------*\
00061                            Class topoSetSource Declaration
00062 \*---------------------------------------------------------------------------*/
00063 
00064 class topoSetSource
00065 {
00066 public:
00067 
00068     // Public data types
00069 
00070         //- Enumeration defining the valid actions
00071         enum setAction
00072         {
00073             CLEAR,
00074             NEW,
00075             INVERT,
00076             ADD,
00077             DELETE,
00078             SUBSET,
00079             LIST
00080         };
00081 
00082 protected:
00083 
00084         //- Class with constructor to add usage string to table.
00085         static HashTable<string>* usageTablePtr_;
00086 
00087         class addToUsageTable
00088         {
00089         public:
00090 
00091             addToUsageTable(const word& name, const string& msg)
00092             {
00093                 if (!usageTablePtr_)
00094                 {
00095                     usageTablePtr_ = new HashTable<string>();
00096                 }
00097                 usageTablePtr_->insert(name, msg);
00098             }
00099 
00100             ~addToUsageTable()
00101             {
00102                 if (usageTablePtr_)
00103                 {
00104                     delete usageTablePtr_;
00105                     usageTablePtr_ = NULL;
00106                 }
00107             }
00108         };
00109 
00110 
00111     // Protected data
00112 
00113         const polyMesh& mesh_;
00114 
00115         //- Add (if bool) cellI to set or delete cellI from set.
00116         void addOrDelete(topoSet& set, const label cellI, const bool) const;
00117 
00118 
00119 private:
00120 
00121         static const NamedEnum<setAction, 7> actionNames_;
00122 
00123         static const string illegalSource_;
00124 
00125 
00126     // Private Member Functions
00127 
00128         //- Disallow default bitwise copy construct
00129         topoSetSource(const topoSetSource&);
00130 
00131         //- Disallow default bitwise assignment
00132         void operator=(const topoSetSource&);
00133 
00134 
00135 public:
00136 
00137     //- Runtime type information
00138     TypeName("topoSetSource");
00139 
00140 
00141     // Static Functions
00142 
00143         //- Convert string to action
00144         static setAction toAction(const word& actionName)
00145         {
00146             return actionNames_[actionName];
00147         }
00148 
00149         //- Check state of stream.
00150         static Istream& checkIs(Istream& is);
00151 
00152     // Declare run-time constructor selection table
00153 
00154         // For the dictionary constructor
00155         declareRunTimeSelectionTable
00156         (
00157             autoPtr,
00158             topoSetSource,
00159             word,
00160             (
00161                 const polyMesh& mesh,
00162                 const dictionary& dict
00163             ),
00164             (mesh, dict)
00165         );
00166 
00167         // For the Istream constructor
00168         declareRunTimeSelectionTable
00169         (
00170             autoPtr,
00171             topoSetSource,
00172             istream,
00173             (
00174                 const polyMesh& mesh,
00175                 Istream& is
00176             ),
00177             (mesh, is)
00178         );
00179 
00180 
00181         //- Class used for the read-construction of
00182         //  PtrLists of topoSetSource
00183         class iNew
00184         {
00185             const polyMesh& mesh_;
00186 
00187         public:
00188 
00189             iNew(const polyMesh& mesh)
00190             :
00191                 mesh_(mesh)
00192             {}
00193 
00194             autoPtr<topoSetSource> operator()(Istream& is) const
00195             {
00196                 word topoSetSourceType(is);
00197                 dictionary dict(is);                    
00198                 return topoSetSource::New(topoSetSourceType, mesh_, dict);
00199             }
00200         };
00201 
00202 
00203         static const string& usage(const word& name)
00204         {
00205             if (!usageTablePtr_)
00206             {
00207                 usageTablePtr_ = new HashTable<string>();
00208             }
00209 
00210             const HashTable<string>& usageTable = *usageTablePtr_;
00211 
00212             if (usageTable.found(name))
00213             {
00214                 return usageTable[name];
00215             }
00216             else
00217             {
00218                 return illegalSource_;
00219             }
00220         }
00221 
00222 
00223     // Constructors
00224 
00225         //- Construct from components
00226         topoSetSource(const polyMesh& mesh);
00227 
00228         //- Clone
00229         autoPtr<topoSetSource> clone() const
00230         {
00231             notImplemented("autoPtr<topoSetSource> clone() const");
00232             return autoPtr<topoSetSource>(NULL);
00233         }
00234 
00235 
00236     // Selectors
00237 
00238         //- Return a reference to the selected topoSetSource
00239         static autoPtr<topoSetSource> New
00240         (
00241             const word& topoSetSourceType,
00242             const polyMesh& mesh,
00243             const dictionary& dict
00244         );
00245 
00246         //- Return a reference to the selected topoSetSource
00247         static autoPtr<topoSetSource> New
00248         (
00249             const word& topoSetSourceType,
00250             const polyMesh& mesh,
00251             Istream& is
00252         );
00253 
00254 
00255     // Destructor
00256 
00257         virtual ~topoSetSource();
00258 
00259 
00260     // Member Functions
00261 
00262         const polyMesh& mesh() const
00263         {
00264             return mesh_;
00265         }
00266 
00267 
00268     // Member Functions
00269 
00270         virtual void applyToSet(const setAction action, topoSet&) const = 0;
00271 
00272 };
00273 
00274 
00275 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00276 
00277 } // End namespace Foam
00278 
00279 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00280 
00281 #endif
00282 
00283 // ************************************************************************* //
Copyright © 2000-2007 OpenCFD Ltd