1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
28 Extract command arguments and options from the supplied
29 @a argc and @a argv parameters.
31 Sequences with "(" ... ")" are transformed into a stringList.
34 program -listFiles \( *.txt \)
36 would create a stringList:
38 ( "file1.txt" "file2.txt" ... "fileN.txt" )
40 The backslash-escaping has been used to avoid shell expansions.
42 @par Default command-line options
43 @param -case \<dir\> \n
44 select an case directory instead of the current working directory
46 specify case as a parallel job
48 display the documentation in browser
50 display the source documentation in browser
54 The environment variable @b FOAM_CASE is set to the path of the
55 global case (same for serial and parallel jobs).
56 The environment variable @b FOAM_CASENAME is set to the name of the
60 - Adjustment of the valid (mandatory) arguments
61 by directly manipulating the static member argList::validArgs.
62 - Adjustment of the valid options
63 by directly manipulating the static member argList::validOptions.
68 \*---------------------------------------------------------------------------*/
73 #include "stringList.H"
76 #include "HashTable.H"
80 #include "IStringStream.H"
87 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
92 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
97 static bool bannerEnabled;
100 HashTable<string> options_;
104 fileName globalCase_;
107 ParRunControl parRunControl_;
116 // Private member functions
120 //- Transcribe argv into internal args_
121 // return true if any "(" ... ")" sequences were captured
122 bool regroupArgv(int& argc, char**& argv);
127 // Static data members
129 //- A list of valid (mandatory) arguments
130 static SLList<string> validArgs;
132 //- A list of valid options
133 static HashTable<string> validOptions;
135 //- A list of valid parallel options
136 static HashTable<string> validParOptions;
138 //- Name of the application-specific dictionary
139 static word appDictName_;
141 //! @cond ignoreDocumentation
142 class initValidTables
148 //! @endcond ignoreDocumentation
153 //- Construct from argc and argv
154 // checking the arguments and options as requested
173 //- Name of executable
174 const word& executable() const
180 const fileName& rootPath() const
186 const fileName& globalCaseName() const
191 //- Return case name (parallel run) or global case (serial run)
192 const fileName& caseName() const
198 fileName path() const
200 return rootPath()/caseName();
204 const stringList& args() const
209 //- Return additionl arguments,
210 // i.e. those additional to the executable itself
211 stringList::subList additionalArgs() const;
214 const Foam::HashTable<string>& options() const
219 //- Return the argument string associated with the named option
220 const string& option(const word& opt) const
222 return options_.operator[](opt);
225 //- Return true if the named option is found
226 bool optionFound(const word& opt) const
228 return options_.found(opt);
231 //- Return an IStringStream to the named option
232 IStringStream optionLookup(const word& opt) const
234 return IStringStream(option(opt));
237 //- Read a value from the named option
239 T optionRead(const word& opt) const
242 optionLookup(opt)() >> val;
246 //- Read a value from the named option if present.
247 // Return true if the named option was found.
249 bool optionReadIfPresent(const word& opt, T& val) const
251 if (optionFound(opt))
253 optionLookup(opt)() >> val;
262 //- Read a List of values from the named option
264 List<T> optionReadList(const word& opt) const
266 return readList<T>(optionLookup(opt)());
269 //- Return appDictName_
270 const word appDictName() const
277 //- Disable emitting the banner information
278 static void noBanner();
280 //- Remove the parallel options
281 static void noParallel();
287 void printUsage() const;
289 //- Display documentation in browser
290 // Optionally display the application source code
291 void displayDoc(bool source=false) const;
296 //- Check argument list
297 bool check(bool checkArgs=true, bool checkOpts=true) const;
299 //- Check root path and case path
300 bool checkRootCase() const;
304 // Allow overriding the application-specific dictionary using the command-line
305 // parameter -appDict. The dictionary file must still be located in the case's
306 // "system" directory, or accessible using a path relative to the case's
307 // "system" directory.
309 // cellSet # Default will be cellSetDict
310 // cellSet -appDict cellSetDict # Same as above
311 // cellSet -appDict cellSetDict.rotorOnly
313 #define AppSpecificDictionary(DefaultAppDict) \
314 argList::appDictName_ = (DefaultAppDict); \
315 argList::validOptions.insert("appDict", argList::appDictName_);
317 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
319 } // End namespace Foam
321 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
325 // ************************************************************************* //