Loading...
Searching...
No Matches
argList.H
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011-2017 OpenFOAM Foundation
9 Copyright (C) 2016-2023 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27Class
28 Foam::argList
29
30Description
31 Extract command arguments and options from the supplied
32 \a argc and \a argv parameters.
33
34 Sequences with "(" ... ")" are transformed into a stringList.
35 For example,
36 \verbatim
37 program -listFiles \‍( *.txt \‍)
38 \endverbatim
39 would create a stringList:
40 \verbatim
41 ( "file1.txt" "file2.txt" ... "fileN.txt" )
42 \endverbatim
43 The backslash-escaping is required to avoid interpretation by the shell.
44
45 Default command-line options:
46 - \par -case <dir>
47 Select a case directory instead of the current working directory
48 - \par -decomposeParDict <file>
49 Read decomposePar dictionary from specified location
50 - \par -parallel
51 Specify case as a parallel job
52 - \par -doc
53 Display the documentation in browser
54 - \par -srcDoc
55 Display the source documentation in browser
56 - \par -help
57 Print the usage
58
59 Additionally, the \b -noFunctionObjects and \b -postProcess options
60 may be present for some solvers or utilities.
61
62 Environment variables set by argList or by Time:
63 - \par FOAM_API
64 The value of foamVersion::api
65 - \par FOAM_CASE
66 The path of the global case.
67 It is the same for serial and parallel jobs.
68 - \par FOAM_CASENAME
69 The name of the global case.
70 - \par FOAM_EXECUTABLE
71 If not already present in the calling environment,
72 it is set to the \a name portion of the calling executable.
73 - \par FOAM_APPLICATION
74 If not already present in the calling environment,
75 it is set to the value of the \c application entry
76 (from \c controlDict) if that entry is present.
77
78 The value of the \b FOAM_APPLICATION may be inconsistent if the value of
79 the \c application entry is adjusted during runtime.
80
81Note
82 - The document browser used is defined by the \b FOAM_DOC_BROWSER
83 environment variable or the <tt>Documentation/docBrowser</tt> entry
84 in the <tt><etc>/controlDict</tt> file.
85 The \%f token is used as a placeholder for the file name.
86 - The valid (mandatory) arguments can be adjusted
87 via the addArgument static method instead of directly
88 manipulating the argList::validArgs static member.
89 - The valid options can be adjusted
90 via the addOption/removeOption static methods instead of directly
91 manipulating the argList::validOptions static member.
92
93SourceFiles
94 argList.C
95 argListI.H
96
97\*---------------------------------------------------------------------------*/
98
99#ifndef Foam_argList_H
100#define Foam_argList_H
101
102#include "stringList.H"
103#include "SLList.H"
104#include "HashSet.H"
105#include "fileName.H"
106#include "parRun.H" // "ParRunControl"
107#include "ITstream.H"
108#include "dlLibraryTable.H"
109#include "OSspecific.H"
110
111// Transitional features - older style access (including 1712 release)
112#define Foam_argList_1712
113
114// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
115
116namespace Foam
117{
119/*---------------------------------------------------------------------------*\
120 Class argList Declaration
121\*---------------------------------------------------------------------------*/
122
123class argList
124{
125 // Private Data
126
127 //- Command arguments are mandatory (default) or optional
128 static bool argsMandatory_;
129
130 //- Check presence of processor directories (default: on)
131 static bool checkProcessorDirectories_;
132
133 //- MPI threads are desired for the application (default: off)
134 static bool parallelThreads_;
135
136 //- Switch on/off parallel mode, dry-run etc.
137 // Construct first so destructor is done last.
138 ParRunControl runControl_;
139
140 //- The arguments after removing known options
141 stringList args_;
142
143 //- The extracted options
144 HashTable<string> options_;
145
146 //- Additional libraries
147 mutable dlLibraryTable libs_;
148
149 word executable_;
150 fileName rootPath_;
151 fileName globalCase_;
152 fileName case_;
153
154 //- The command line options and arguments concatenated as a string
155 string commandLine_;
156
157
158 // Private Member Functions
159
160 //- Helper for resolving aliases for -options within validOptionsCompat
161 static word optionCompat(const word& optName);
162
163 //- Helper for resolving ignored options
164 static int optionIgnore(const word& optName);
165
166 //- Check after reading if the input token stream has unconsumed
167 //- tokens remaining or if there were no tokens in the first place.
168 // Emits Warning
169 static void checkITstream(const ITstream& is, const label index);
170
171 //- Check after reading if the input token stream has unconsumed
172 //- tokens remaining or if there were no tokens in the first place.
173 // Emits Warning
174 static void checkITstream(const ITstream& is, const word& optName);
175
176 //- Read a List of values from ITstream,
177 //- treating a single entry like a list of size 1.
178 template<class T>
179 static inline void readList(ITstream& is, List<T>& list);
180
181 //- Trigger FatalError for given option
182 void raiseBadInput(const word& optName) const;
183
184 //- Set rootPath_, globalCase_, case_ from one of the following forms
185 // * [-case dir]
186 // * cwd
187 //
188 // Exports FOAM_CASE and FOAM_CASENAME env variables so they can
189 // be used immediately (eg, in decomposeParDict).
190 // Exports FOAM_EXECUTABLE env variable.
191 //
192 // Detects -dry-run option
193 void setCasePaths();
194
195 //- Transcribe argv into internal args_.
196 // Transform sequences with "(" ... ")" into string lists
197 // return true if any "(" ... ")" sequences were captured
198 bool regroupArgv(int& argc, char**& argv);
199
200 //- Print option compatibility
201 void printManCompat() const;
202
203
204public:
205
206 // Static Data Members
207
208 //- A list of valid (mandatory) arguments
210
211 //- The "advanced" options are shown with -help-full (not with --help)
213
214 //- A list of valid options
216
217 //- A list of valid parallel options
219
220 //- A list of aliases for options.
221 // Stored as (alias = canonical, version)
223
224 //- A list of options to ignore.
225 // Stored as (option = bool, version)
227
228 //- Short description for program arguments
230
231 //- Short description for validOptions
233
234 //- General usage notes
235 static SLList<string> notes;
236
237 //- Min indentation when displaying usage (default: 20)
238 static std::string::size_type usageMin;
239
240 //- Max screen width when displaying usage (default: 80)
241 static std::string::size_type usageMax;
242
243 //- Standard name for the post-processing option
247 // The constructor populates the standard options
248 struct initValidTables
249 {
250 initValidTables();
251 };
253
254
255 // Constructors
256
257 //- Construct from argc and argv
258 //- checking the arguments and options as requested.
259 //
260 // By default, the argument check respects the value of
261 // argsMandatory() to decide if the arguments should be checked
262 // (when they are mandatory) or not (when they are optional)
263 argList
264 (
265 int& argc,
266 char**& argv,
267 bool checkArgs = argList::argsMandatory(),
268 bool checkOpts = true,
269 bool initialise = true
270 );
271
272 //- Construct copy with new options
273 argList
275 const argList& args,
277 bool checkArgs = true,
278 bool checkOpts = true,
279 bool initialise = true
280 );
281
282
283 //- Destructor
284 virtual ~argList();
285
286
287 // Member Functions
288
289 // Environment
290
291 //- Name of the executable from environment variable
292 //
293 // Returns the contents of the \c FOAM_EXECUTABLE variable,
294 // which has previously been set by argList.
295 //
296 // This will normally be identical to the value of executable(),
297 // but obtained from the environment.
298 static word envExecutable();
300 //- Global case (directory) from environment variable
301 //
302 // Returns the contents of the \c FOAM_CASE variable,
303 // which has previously been set by argList or by Time.
304 //
305 // This will normally be identical to the value of globalPath(),
306 // but obtained via the environment.
307 static fileName envGlobalPath();
308
309 //- Return the input relative to the globalPath by stripping off
310 //- a leading value of the envGlobalPath
311 //
312 // \param input the directory or filename to make case-relative
313 // \param caseTag replace globalPath with <case> for later
314 // use with expand(), or prefix <case> if the file name was
315 // not an absolute location
317 (
318 const fileName& input,
319 const bool caseTag = false
320 );
321
322
323 // Low-level
324
325 //- Scan for -help, -doc options etc prior to checking the validity
326 //- of other args/opts and finally initialising.
327 void parse(bool checkArgs, bool checkOpts, bool initialise);
328
329
330 // Access
331
332 //- Name of executable without the path
333 inline const word& executable() const noexcept;
334
335 //- The command line options and arguments concatenated as a string
336 inline const string& commandLine() const noexcept;
337
338 //- Return root path
339 inline const fileName& rootPath() const noexcept;
340
341 //- Return case name (parallel run) or global case (serial run)
342 inline const fileName& caseName() const noexcept;
343
344 //- Return global case name
345 inline const fileName& globalCaseName() const noexcept;
346
347 //- Return the full path to the (processor local) case
348 // \note This is guaranteed to be an absolute path
349 inline fileName path() const;
350
351 //- Return the full path to the global case
352 // \note This is guaranteed to be an absolute path
353 inline fileName globalPath() const;
354
355 //- Return the input relative to the globalPath by stripping off
356 //- a leading value of the globalPath
357 //
358 // \param input the directory or filename to make case-relative
359 // \param caseTag replace globalPath with <case> for later
360 // use with expand(), or prefix <case> if the file name was
361 // not an absolute location
363 (
364 const fileName& input,
365 const bool caseTag = false
366 ) const;
367
368 //- Return the run control (parallel, dry-run etc)
369 inline const ParRunControl& runControl() const noexcept;
370
371 //- Return distributed flag
372 //- (i.e. are rootPaths different on different machines)
373 inline bool distributed() const noexcept;
374
375 //- Return the dry-run flag
376 inline int dryRun() const noexcept;
377
378 //- Modify the dry-run flag
379 inline int dryRun(const int level) noexcept;
380
381 //- Return the verbose flag
382 inline int verbose() const noexcept;
383
384 //- Modify the verbose flag
385 inline int verbose(const int level) noexcept;
386
387 //- The controlDict 'functions' entry is allowed to be used.
388 // There must be a command-line option to enable/disable
389 // (-withFunctionObjects, -noFunctionObjects)
390 // and has not been explicitly disabled
391 bool allowFunctionObjects() const;
392
393 //- The controlDict 'libs' entry is allowed to be used.
394 //- (eg, has not been disabled by the -no-libs option)
395 bool allowLibs() const;
396
397 //- Mutable access to the loaded dynamic libraries
398 inline dlLibraryTable& libs() const noexcept;
399
400 //- The number of arguments
401 inline label size() const noexcept;
402
403 //- Return arguments
404 inline const stringList& args() const noexcept;
405
406 //- Non-const access to the command arguments (non-options)
407 inline stringList& args() noexcept;
408
409 //- Return options
410 inline const HashTable<string>& options() const noexcept;
411
412 //- Return non-const access to the command options
413 inline HashTable<string>& options() noexcept;
414
415 //- Return true if the named option is found
416 inline bool found(const word& optName) const;
417
418 //- Return how many of the specified options were used
419 label count(const UList<word>& optionNames) const;
420
421 //- Return how many of the specified options were used
422 label count(std::initializer_list<word> optionNames) const;
423
424 //- Return an input stream from the named option
425 inline ITstream lookup(const word& optName) const;
426
427 //- Get a value from the argument at index.
428 // Index 1 is the first (non-option) argument.
429 // For fileName type, invokes fileName::validate()
430 template<class T>
431 inline T get(const label index) const;
432
433 //- Get a List of values from the argument at index.
434 // Index 1 is the first (non-option) argument.
435 template<class T>
436 inline List<T> getList(const label index) const;
437
438 //- Get a value from the named option
439 // The default template parameter is string (ie, no conversion).
440 // For fileName type, invokes fileName::validate()
441 template<class T=string>
442 inline T get(const word& optName) const;
443
444 //- Get a value from the named option if present, or return default.
445 template<class T>
446 inline T getOrDefault(const word& optName, const T& deflt) const;
447
448 //- Get a List of values from the named option,
449 //- treating a single entry like a list of size 1.
450 // \param optName the option name to read from
451 // \param mandatory if the option is non-mandatory, the behaviour
452 // is similar to readListIfPresent().
453 template<class T>
454 inline List<T> getList(const word& optName, bool mandatory=true) const;
455
456 //- Read a value from the named option if present.
457 // \return true if the named option was found.
458 template<class T>
459 inline bool readIfPresent(const word& optName, T& val) const;
460
461 //- Read a value from the named option if present.
462 // \return true if the named option was found, otherwise
463 // use the supplied default and return false.
464 template<class T>
465 inline bool readIfPresent
466 (
467 const word& optName,
468 T& val,
469 const T& deflt
470 ) const;
471
472 //- If named option is present, get a List of values
473 //- treating a single entry like a list of size 1.
474 // \return true if the named option was found.
475 template<class T>
476 inline bool readListIfPresent(const word& optName, List<T>& list) const;
477
478 //- Read the named option and check its validity.
479 // FatalError if mandatory and not found, or if the predicate check
480 // failed.
481 //
482 // \param optName the option name
483 // \param val the value to read into
484 // \param pred the value check predicate
485 //
486 // \return true if the entry was found.
487 template<class T, class Predicate>
488 inline bool readCheck
489 (
490 const word& optName,
491 T& val,
492 const Predicate& pred,
493 bool mandatory = true
494 ) const;
495
496 //- Read the named option if present and check its validity.
497 // FatalError if found and the predicate check failed.
498 //
499 // \param optName the option name
500 // \param val the value to read into
501 // \param pred the value check predicate
502 //
503 // \return true if the entry was found.
504 template<class T, class Predicate>
505 inline bool readCheckIfPresent
506 (
507 const word& optName,
508 T& val,
509 const Predicate& pred
510 ) const;
511
512 //- Get a value from the named option with additional checking.
513 // FatalError if the predicate check failed.
514 //
515 // \param optName the option name
516 // \param pred the value check predicate
517 template<class T, class Predicate>
518 T getCheck
519 (
520 const word& optName,
521 const Predicate& pred
522 ) const;
523
524 //- Get a value from the named option with additional checking
525 //- (if present), or return default.
526 // FatalError if the predicate check on the retrieved value failed.
527 //
528 // \param optName the option name
529 // \param deflt the default return value
530 // \param pred the value check predicate
531 template<class T, class Predicate>
533 (
534 const word& optName,
535 const T& deflt,
536 const Predicate& pred
537 ) const;
538
539
540 // Edit
541
542 //- Append a (mandatory) argument to validArgs
543 static void addArgument
544 (
545 const string& argName,
546 const string& usage = ""
547 );
548
549 //- Add a bool option to validOptions with usage information
550 static void addBoolOption
551 (
552 const word& optName,
553 const string& usage = "",
554 bool advanced = false
555 );
556
557 //- Add an option to validOptions with usage information
558 // An option with an empty param is a bool option
559 static void addOption
560 (
561 const word& optName,
562 const string& param = "",
563 const string& usage = "",
564 bool advanced = false
565 );
566
567 //- Set an existing option as being 'advanced' or normal
568 static void setAdvanced(const word& optName, bool advanced = true);
569
570 //- Specify an alias for the option name.
571 //
572 // \param optName the currently used option name
573 // \param compat alias name and the last OpenFOAM version (YYMM)
574 // when the alias was not needed.
575 // Setting a zero or negative version suppresses warnings about
576 // the alias.
577 static void addOptionCompat
578 (
579 const word& optName,
580 std::pair<const char*, int> compat
581 );
582
583 //- Specify an option to be ignored.
584 //
585 // \param compat optName and the last OpenFOAM version (YYMM)
586 // when the option was directly supported.
587 // Setting a zero or negative version suppresses warnings about
588 // the alias.
589 // \param expectArg the option is non-bool
590 static void ignoreOptionCompat
591 (
592 std::pair<const char*,int> compat,
593 bool expectArg
594 );
595
596 //- Add option usage information to optionUsage
597 static void addUsage
598 (
599 const word& optName,
600 const string& usage
601 );
603 //- Add extra notes for the usage information
604 // This string is used "as-is" without additional formatting
605 static void addNote(const string& note);
606
607 //- Remove option from validOptions and from optionUsage
608 static void removeOption(const word& optName);
609
610 //- Flag command arguments as being optional (non-mandatory)
611 static void noMandatoryArgs();
612
613 //- Command arguments type (optional/mandatory).
614 static bool argsMandatory();
615
616 //- Disable emitting the banner information.
617 // Adjusts the Foam::infoDetailLevel flag.
618 static void noBanner();
619
620 //- Banner status (enabled/disabled).
621 // Queries the Foam::infoDetailLevel flag.
622 static bool bannerEnabled();
623
624 //- Enable a 'dry-run' bool option, with usage information
625 static void addDryRunOption
626 (
627 const string& usage,
628 bool advanced = false
629 );
630
631 //- Enable a 'verbose' bool option, with usage information
632 static void addVerboseOption
633 (
634 const string& usage = "",
635 bool advanced = false
636 );
637
638 //- Remove '-noFunctionObjects' option and ignore any occurrences.
639 // Optionally add a '-withFunctionObjects' option instead
640 static void noFunctionObjects(bool addWithOption = false);
641
642 //- Suppress JobInfo, overriding controlDict setting
643 static void noJobInfo();
644
645 //- Add the '-no-libs' command line option
646 static void noLibs();
647
648 //- Remove the parallel options
649 static void noParallel();
650
651 //- Disable checking of processor directories
652 static void noCheckProcessorDirectories();
653
654 //- MPI threads are desired for the application
655 static void parallelThreads_on();
656
657 //- Set option directly (use with caution)
658 // An option with an empty param is a bool option.
659 // Not all valid options can also be set: eg, -case, -roots, ...
660 // Return true if the existing option value needed changing,
661 // or if the option did not previously exist.
662 bool setOption(const word& optName, const string& param = "");
663
664 //- Unset option directly (use with caution)
665 // Not all valid options can also be unset: eg, -case, -roots ...
666 // Return true if the option existed before being unset.
667 bool unsetOption(const word& optName);
668
669
670 // Helpers
671
672 //- True if the post-processing option is found in the \c argv list
673 static bool postProcess(int argc, char *argv[]);
674
675 //- The number of times -verbose is found in the \c argv list
676 static int verbose(int argc, char *argv[]);
677
678
679 // Print
680
681 //- Print option compatibility
682 void printCompat() const;
683
684 //- Print notes (if any)
685 void printNotes() const;
686
687 //- Print usage
688 void printUsage(bool full=true) const;
689
690 //- Print usage as nroff-man format (Experimental)
691 void printMan() const;
692
693 //- Display documentation in browser
694 // Optionally display the application source code
695 void displayDoc(bool source=false) const;
696
697
698 // Check
699
700 //- Check the parsed command-line for mandatory arguments and
701 //- that all the options are correct.
702 //
703 // By default, the argument check respects the value of
704 // argsMandatory() to decide if the arguments should be checked
705 // (when they are mandatory) or not (when they are optional)
706 bool check
707 (
708 bool checkArgs = argList::argsMandatory(),
709 bool checkOpts = true
710 ) const;
711
712 //- Check root path and case path
713 bool checkRootCase() const;
714
715
716 // Member Operators
717
718 //- The string corresponding to the argument index.
719 // Index 0 is the executable.
720 // Index 1 is the first (non-option) argument.
721 inline const string& operator[](const label index) const;
722
723 //- The string associated with the named option
724 inline const string& operator[](const word& optName) const;
725
726
727 // Housekeeping
728
729 //- Deprecated(2020-05) identical to get(const word& optName)
730 // \deprecated(2020-05) - use get() method
731 template<class T=string>
732 FOAM_DEPRECATED_STRICT(2020-06, "get()")
733 T opt(const word& optName) const
734 {
735 return this->get<T>(optName);
736 }
737
738 //- Deprecated(2020-05) identical to getOrDefault(...)
739 // \deprecated(2020-05) - use getOrDefault() method
740 template<class T>
741 FOAM_DEPRECATED_STRICT(2020-06, "getOrDefault()")
742 T opt(const word& optName, const T& deflt) const
743 {
744 return this->getOrDefault<T>(optName, deflt);
745 }
746
747 //- Deprecated(2020-05) identical to getOrDefault(...)
748 // \deprecated(2020-05) - use getOrDefault() method
749 template<class T>
750 FOAM_DEPRECATED_STRICT(2020-06, "getOrDefault()")
751 T get(const word& optName, const T& deflt) const
752 {
753 return this->getOrDefault<T>(optName, deflt);
754 }
755
756 //- Deprecated(2020-05) identical to getOrDefault(...)
757 // \deprecated(2020-05) - use getOrDefault() method
758 template<class T>
759 FOAM_DEPRECATED_STRICT(2020-06, "getOrDefault()")
760 T lookupOrDefault(const word& optName, const T& deflt) const
761 {
762 return this->getOrDefault<T>(optName, deflt);
763 }
764
765 //- Same as runControl() - v2106 and earlier
766 const ParRunControl& parRunControl() const { return runControl_; }
767
768
769 // Older style access (including 1712 release)
770
771 #ifdef Foam_argList_1712
772
773 //- Deprecated(2018-08) read a value from the argument at index.
774 // Index 1 is the first (non-option) argument.
775 // \deprecated(2018-08) - use get() method
776 template<class T>
777 FOAM_DEPRECATED_FOR(2018-08, "get() method")
778 T read(const label index) const
779 {
780 return this->get<T>(index);
781 }
782
783 //- Deprecated(2018-01) read a value from the argument at index.
784 // Index 1 is the first (non-option) argument.
785 // \deprecated(2018-01) - use get() method
786 template<class T>
787 FOAM_DEPRECATED_FOR(2018-01, "get() method")
788 T argRead(const label index) const
789 {
790 return this->get<T>(index);
791 }
792
793 //- Deprecated(2018-01) return true if the named option is found
794 // \deprecated(2018-01) - use found() method
795 FOAM_DEPRECATED_FOR(2018-01, "found() method")
796 bool optionFound(const word& optName) const
797 {
798 return found(optName);
799 }
800
801 //- Deprecated(2018-01) return an input stream from the named option
802 // \deprecated(2018-01) - use lookup() method
803 FOAM_DEPRECATED_FOR(2018-01, "lookup() method")
804 ITstream optionLookup(const word& optName) const
805 {
806 return lookup(optName);
807 }
808
809 //- Deprecated(2018-01) read a value from the named option
810 // \deprecated(2018-01) - use get() method
811 template<class T>
812 FOAM_DEPRECATED_FOR(2018-01, "get() method")
813 T optionRead(const word& optName) const
814 {
815 return get<T>(optName);
816 }
817
818 //- Deprecated(2018-01) read a value from the named option if present.
819 // Return true if the named option was found.
820 // \deprecated(2018-01) - use readIfPresent() method
821 template<class T>
822 FOAM_DEPRECATED_FOR(2018-01, "readIfPresent() method")
824 (
825 const word& optName,
826 T& val
827 ) const
828 {
829 return readIfPresent<T>(optName, val);
830 }
831
832 //- Deprecated(2018-01) read a value from the named option if present.
833 // Return true if the named option was found, otherwise
834 // use the supplied default and return false.
835 // \deprecated(2018-01) - use readIfPresent() method
836 template<class T>
837 FOAM_DEPRECATED_FOR(2018-01, "readIfPresent() method")
839 (
840 const word& optName,
841 T& val,
842 const T& deflt
843 ) const
844 {
845 return readIfPresent<T>(optName, val, deflt);
846 }
847
848 //- Deprecated(2018-01) read a value from the named option if present.
849 // Return supplied default otherwise.
850 // \deprecated(2018-01) - use getOrDefault() method
851 template<class T>
852 FOAM_DEPRECATED_FOR(2018-01, "getOrDefault() method")
854 (
855 const word& optName,
856 const T& deflt
857 ) const
858 {
859 return getOrDefault<T>(optName, deflt);
860 }
861
862 //- Deprecated(2018-01) read a List of values from the named option
863 // \deprecated(2018-01) - use getList() method
864 template<class T>
865 FOAM_DEPRECATED_FOR(2018-01, "getList() method")
866 List<T> optionReadList(const word& optName) const
867 {
868 return this->getList<T>(optName);
869 }
870
871 #endif /* Foam_argList_1712 */
872};
873
874
875// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
876
877} // End namespace Foam
878
879// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
880
881#include "argListI.H"
882
883// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
884
885#endif
886
887// ************************************************************************* //
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
Non-intrusive singly-linked list.
bool found
A HashTable with keys but without contents that is similar to std::unordered_set.
Definition HashSet.H:96
A HashTable similar to std::unordered_map.
Definition HashTable.H:124
An input stream of tokens.
Definition ITstream.H:56
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition List.H:72
Helper class for initializing parallel jobs from the command arguments, storing 'dry-run' state etc....
Definition parRun.H:49
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition UList.H:89
Extract command arguments and options from the supplied argc and argv parameters.
Definition argList.H:119
void parse(bool checkArgs, bool checkOpts, bool initialise)
Scan for -help, -doc options etc prior to checking the validity of other args/opts and finally initia...
Definition argList.C:1242
static word postProcessOptionName
Standard name for the post-processing option.
Definition argList.H:304
T get(const label index) const
Get a value from the argument at index.
Definition argListI.H:271
static HashTable< string, label, Hash< label > > argUsage
Short description for program arguments.
Definition argList.H:279
int dryRun() const noexcept
Return the dry-run flag.
Definition argListI.H:109
static void noBanner()
Disable emitting the banner information.
Definition argList.C:506
static std::string::size_type usageMin
Min indentation when displaying usage (default: 20).
Definition argList.H:294
static void noFunctionObjects(bool addWithOption=false)
Remove '-noFunctionObjects' option and ignore any occurrences.
Definition argList.C:562
static HashTable< std::pair< word, int > > validOptionsCompat
A list of aliases for options.
Definition argList.H:267
static HashTable< string > validParOptions
A list of valid parallel options.
Definition argList.H:260
static void removeOption(const word &optName)
Remove option from validOptions and from optionUsage.
Definition argList.C:486
const ParRunControl & parRunControl() const
Same as runControl() - v2106 and earlier.
Definition argList.H:1029
const stringList & args() const noexcept
Return arguments.
Definition argListI.H:145
static void addVerboseOption(const string &usage="", bool advanced=false)
Enable a 'verbose' bool option, with usage information.
Definition argList.C:535
bool distributed() const noexcept
Return distributed flag (i.e. are rootPaths different on different machines).
Definition argListI.H:103
argList(int &argc, char **&argv, bool checkArgs=argList::argsMandatory(), bool checkOpts=true, bool initialise=true)
Construct from argc and argv checking the arguments and options as requested.
Definition argList.C:913
static std::string::size_type usageMax
Max screen width when displaying usage (default: 80).
Definition argList.H:299
bool unsetOption(const word &optName)
Unset option directly (use with caution).
Definition argList.C:2336
static bool postProcess(int argc, char *argv[])
True if the post-processing option is found in the argv list.
Definition argList.C:625
bool optionFound(const word &optName) const
Deprecated(2018-01) return true if the named option is found.
Definition argList.H:1068
const HashTable< string > & options() const noexcept
Return options.
Definition argListI.H:158
T opt(const word &optName) const
Deprecated(2020-05) identical to get(const word& optName).
Definition argList.H:985
int verbose() const noexcept
Return the verbose flag.
Definition argListI.H:121
const ParRunControl & runControl() const noexcept
Return the run control (parallel, dry-run etc).
Definition argListI.H:97
const fileName & rootPath() const noexcept
Return root path.
Definition argListI.H:56
static void addArgument(const string &argName, const string &usage="")
Append a (mandatory) argument to validArgs.
Definition argList.C:366
static bool bannerEnabled()
Banner status (enabled/disabled).
Definition argList.C:512
bool readCheck(const word &optName, T &val, const Predicate &pred, bool mandatory=true) const
Read the named option and check its validity.
Definition argListI.H:409
static fileName envGlobalPath()
Global case (directory) from environment variable.
Definition argList.C:668
static void noLibs()
Add the '-no-libs' command line option.
Definition argList.C:588
static void noJobInfo()
Suppress JobInfo, overriding controlDict setting.
Definition argList.C:582
bool allowLibs() const
The controlDict 'libs' entry is allowed to be used. (eg, has not been disabled by the -no-libs option...
Definition argList.C:2272
bool optionReadIfPresent(const word &optName, T &val) const
Deprecated(2018-01) read a value from the named option if present.
Definition argList.H:1105
void printUsage(bool full=true) const
Print usage.
static void setAdvanced(const word &optName, bool advanced=true)
Set an existing option as being 'advanced' or normal.
Definition argList.C:419
List< T > optionReadList(const word &optName) const
Deprecated(2018-01) read a List of values from the named option.
Definition argList.H:1156
bool check(bool checkArgs=argList::argsMandatory(), bool checkOpts=true) const
Check the parsed command-line for mandatory arguments and that all the options are correct.
Definition argList.C:2431
virtual ~argList()
Destructor.
Definition argList.C:2243
fileName relativePath(const fileName &input, const bool caseTag=false) const
Return the input relative to the globalPath by stripping off a leading value of the globalPath.
Definition argListI.H:87
bool readListIfPresent(const word &optName, List< T > &list) const
If named option is present, get a List of values treating a single entry like a list of size 1.
Definition argListI.H:387
T optionLookupOrDefault(const word &optName, const T &deflt) const
Deprecated(2018-01) read a value from the named option if present.
Definition argList.H:1141
static HashTable< string > optionUsage
Short description for validOptions.
Definition argList.H:284
bool allowFunctionObjects() const
The controlDict 'functions' entry is allowed to be used.
Definition argList.C:2254
static fileName envRelativePath(const fileName &input, const bool caseTag=false)
Return the input relative to the globalPath by stripping off a leading value of the envGlobalPath.
Definition argList.C:675
static bool argsMandatory()
Command arguments type (optional/mandatory).
Definition argList.C:500
label count(const UList< word > &optionNames) const
Return how many of the specified options were used.
Definition argList.C:2280
static HashSet< string > advancedOptions
The "advanced" options are shown with -help-full (not with –help).
Definition argList.H:250
bool setOption(const word &optName, const string &param="")
Set option directly (use with caution).
Definition argList.C:2308
T lookupOrDefault(const word &optName, const T &deflt) const
Deprecated(2020-05) identical to getOrDefault(...).
Definition argList.H:1021
static void addDryRunOption(const string &usage, bool advanced=false)
Enable a 'dry-run' bool option, with usage information.
Definition argList.C:519
label size() const noexcept
The number of arguments.
Definition argListI.H:139
static void noCheckProcessorDirectories()
Disable checking of processor directories.
Definition argList.C:619
static SLList< string > notes
General usage notes.
Definition argList.H:289
bool checkRootCase() const
Check root path and case path.
Definition argList.C:2479
void displayDoc(bool source=false) const
Display documentation in browser.
Definition argList.C:2357
static void noMandatoryArgs()
Flag command arguments as being optional (non-mandatory).
Definition argList.C:494
bool found(const word &optName) const
Return true if the named option is found.
Definition argListI.H:171
static void addBoolOption(const word &optName, const string &usage="", bool advanced=false)
Add a bool option to validOptions with usage information.
Definition argList.C:389
ITstream optionLookup(const word &optName) const
Deprecated(2018-01) return an input stream from the named option.
Definition argList.H:1079
T optionRead(const word &optName) const
Deprecated(2018-01) read a value from the named option.
Definition argList.H:1091
void printCompat() const
Print option compatibility.
bool readIfPresent(const word &optName, T &val) const
Read a value from the named option if present.
Definition argListI.H:316
const fileName & globalCaseName() const noexcept
Return global case name.
Definition argListI.H:68
static void noParallel()
Remove the parallel options.
Definition argList.C:599
static void addUsage(const word &optName, const string &usage)
Add option usage information to optionUsage.
Definition argList.C:461
void printMan() const
Print usage as nroff-man format (Experimental).
static void addOption(const word &optName, const string &param="", const string &usage="", bool advanced=false)
Add an option to validOptions with usage information.
Definition argList.C:400
void printNotes() const
Print notes (if any).
static void parallelThreads_on()
MPI threads are desired for the application.
Definition argList.C:613
fileName path() const
Return the full path to the (processor local) case.
Definition argListI.H:74
static HashTable< string > validOptions
A list of valid options.
Definition argList.H:255
T getCheck(const word &optName, const Predicate &pred) const
Get a value from the named option with additional checking.
Definition argListI.H:450
static SLList< string > validArgs
A list of valid (mandatory) arguments.
Definition argList.H:245
T argRead(const label index) const
Deprecated(2018-01) read a value from the argument at index.
Definition argList.H:1057
ITstream lookup(const word &optName) const
Return an input stream from the named option.
Definition argListI.H:177
List< T > getList(const label index) const
Get a List of values from the argument at index.
bool readCheckIfPresent(const word &optName, T &val, const Predicate &pred) const
Read the named option if present and check its validity.
Definition argListI.H:438
T getOrDefault(const word &optName, const T &deflt) const
Get a value from the named option if present, or return default.
Definition argListI.H:300
const word & executable() const noexcept
Name of executable without the path.
Definition argListI.H:44
static word envExecutable()
Name of the executable from environment variable.
Definition argList.C:662
const string & commandLine() const noexcept
The command line options and arguments concatenated as a string.
Definition argListI.H:50
T getCheckOrDefault(const word &optName, const T &deflt, const Predicate &pred) const
Get a value from the named option with additional checking (if present), or return default.
Definition argListI.H:463
static HashTable< std::pair< bool, int > > ignoreOptionsCompat
A list of options to ignore.
Definition argList.H:274
static void addNote(const string &note)
Add extra notes for the usage information.
Definition argList.C:477
static void ignoreOptionCompat(std::pair< const char *, int > compat, bool expectArg)
Specify an option to be ignored.
Definition argList.C:447
dlLibraryTable & libs() const noexcept
Mutable access to the loaded dynamic libraries.
Definition argListI.H:133
T read(const label index) const
Deprecated(2018-08) read a value from the argument at index.
Definition argList.H:1044
static void addOptionCompat(const word &optName, std::pair< const char *, int > compat)
Specify an alias for the option name.
Definition argList.C:433
const fileName & caseName() const noexcept
Return case name (parallel run) or global case (serial run).
Definition argListI.H:62
fileName globalPath() const
Return the full path to the global case.
Definition argListI.H:80
A table of dynamically loaded libraries.
A class for handling file names.
Definition fileName.H:75
Lookup type of boundary radiation properties.
Definition lookup.H:60
A class for handling words, derived from Foam::string.
Definition word.H:66
fileName path(UMean.rootPath()/UMean.caseName()/"graphs"/UMean.instance())
const volScalarField & T
Namespace for OpenFOAM.
LList< SLListBase, T > SLList
Definition SLListFwd.H:41
List< string > stringList
List of string.
Definition stringList.H:32
const direction noexcept
Definition scalarImpl.H:265
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Foam::argList args(argc, argv)
#define FOAM_DEPRECATED_FOR(since, replacement)
Definition stdFoam.H:43
#define FOAM_DEPRECATED_STRICT(since, replacement)
Definition stdFoam.H:53