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

argList.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     argList
00027 
00028 Description
00029     Make, print and check argList
00030 
00031 \*---------------------------------------------------------------------------*/
00032 
00033 #ifndef argList_H
00034 #define argList_H
00035 
00036 #include "stringList.H"
00037 #include "SubList.H"
00038 #include "SLList.H"
00039 #include "HashTable.H"
00040 #include "word.H"
00041 #include "fileName.H"
00042 #include "parRun.H"
00043 #include "sigFpe.H"
00044 #include "sigInt.H"
00045 #include "sigQuit.H"
00046 #include "sigSegv.H"
00047 
00048 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00049 
00050 namespace Foam
00051 {
00052 
00053 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00054 
00055 class argList
00056 {
00057     // Private data
00058 
00059         stringList args_;
00060         HashTable<string> options_;
00061 
00062         word executable_;
00063         fileName rootPath_;
00064         fileName globalCase_;
00065         fileName case_;
00066         bool parRun_;
00067 
00068         ParRunControl parRunControl_;
00069 
00070         // Signal handlers
00071         sigFpe sigFpe_;
00072         sigInt sigInt_;
00073         sigQuit sigQuit_;
00074         sigSegv sigSegv_;
00075 
00076 
00077     // Private member functions
00078 
00079         int findArg(const string& arg) const;
00080 
00081 
00082 public:
00083 
00084     // Static data members
00085 
00086         static SLList<string> validArgs;
00087         static HashTable<string> validOptions;
00088         static HashTable<string> validParOptions;
00089 
00090         class initValidTables
00091         {
00092         public:
00093 
00094             initValidTables();
00095         };
00096 
00097 
00098     // Constructors
00099 
00100         //- Construct from argc and argv
00101         //  checking the arguments and options as requested
00102         argList
00103         (
00104             int& argc,
00105             char**& argv,
00106             bool checkArgs = true,
00107             bool checkOpts = true
00108         );
00109 
00110 
00111     // Destructor
00112 
00113         virtual ~argList();
00114 
00115 
00116     // Member functions
00117 
00118         // Access
00119 
00120             //- Return arguments
00121             const stringList& args() const
00122             {
00123                 return args_;
00124             }
00125 
00126             //- Return parameters - ie, arguments without args[0] (executable)
00127             stringList::subList params() const
00128             {
00129                 return stringList::subList(args_, args_.size() - 1, 1);
00130             }
00131 
00132             //- Return options
00133             const HashTable<string>& options() const
00134             {
00135                 return options_;
00136             }
00137 
00138             //- Name of executable
00139             const word& executable() const
00140             {
00141                 return executable_;
00142             }
00143 
00144             //- Return root path
00145             const fileName& rootPath() const
00146             {
00147                 return rootPath_;
00148             }
00149 
00150             //- Return case name
00151             const fileName& globalCaseName() const
00152             {
00153                 return globalCase_;
00154             }
00155 
00156             //- Return case name
00157             //  or parallel processor case name for parallel run
00158             const fileName& caseName() const
00159             {
00160                 return case_;
00161             }
00162 
00163             //- Return path
00164             fileName path() const
00165             {
00166                 return rootPath()/caseName();
00167             }
00168 
00169             //- Is this a parallel run
00170             bool parRun() const
00171             {
00172                 return parRun_;
00173             }
00174 
00175 
00176         // Edit
00177 
00178             //- Remove the parallel options
00179             static void noParallel();
00180 
00181 
00182         // Print
00183 
00184             //- Print usage
00185             void printUsage() const;
00186 
00187 
00188         // Check
00189 
00190             //- Check argument list
00191             bool check(bool checkArgs = true, bool checkOpts = true) const;
00192 
00193             //- Check root path and case path
00194             bool checkRootCase() const;
00195 };
00196 
00197 
00198 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00199 
00200 } // End namespace Foam
00201 
00202 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00203 
00204 #endif
00205 
00206 // ************************************************************************* //
Copyright © 2000-2007 OpenCFD Ltd