From 072c1b070b61740486df96dfd5699acccbe09eb3 Mon Sep 17 00:00:00 2001
From: andy <andy>
Date: Wed, 8 May 2013 11:38:18 +0100
Subject: [PATCH] ENH: Added copy constructor to argList

---
 src/OpenFOAM/global/argList/argList.C  | 190 +++++++++++++++----------
 src/OpenFOAM/global/argList/argList.H  |  44 +++++-
 src/OpenFOAM/global/argList/argListI.H |  20 ++-
 3 files changed, 172 insertions(+), 82 deletions(-)

diff --git a/src/OpenFOAM/global/argList/argList.C b/src/OpenFOAM/global/argList/argList.C
index 4db10a99410..b75a8864ada 100644
--- a/src/OpenFOAM/global/argList/argList.C
+++ b/src/OpenFOAM/global/argList/argList.C
@@ -373,7 +373,8 @@ Foam::argList::argList
     int& argc,
     char**& argv,
     bool checkArgs,
-    bool checkOpts
+    bool checkOpts,
+    const bool initialise
 )
 :
     args_(argc),
@@ -405,12 +406,12 @@ Foam::argList::argList
 
     // Check arguments and options, we already have argv[0]
     int nArgs = 1;
-    string argListString = args_[0];
+    argListStr_ = args_[0];
 
     for (int argI = 1; argI < args_.size(); ++argI)
     {
-        argListString += ' ';
-        argListString += args_[argI];
+        argListStr_ += ' ';
+        argListStr_ += args_[argI];
 
         if (args_[argI][0] == '-')
         {
@@ -438,8 +439,8 @@ Foam::argList::argList
                     FatalError.exit();
                 }
 
-                argListString += ' ';
-                argListString += args_[argI];
+                argListStr_ += ' ';
+                argListStr_ += args_[argI];
                 options_.insert(optionName, args_[argI]);
             }
             else
@@ -459,6 +460,39 @@ Foam::argList::argList
 
     args_.setSize(nArgs);
 
+    parse(checkArgs, checkOpts, initialise);
+}
+
+
+Foam::argList::argList
+(
+    const argList& args,
+    const HashTable<string>& options,
+    bool checkArgs,
+    bool checkOpts,
+    bool initialise
+)
+:
+    args_(args.args_),
+    options_(options),
+    executable_(args.executable_),
+    rootPath_(args.rootPath_),
+    globalCase_(args.globalCase_),
+    case_(args.case_),
+    argListStr_(args.argListStr_),
+    parRunControl_(args.parRunControl_)
+{
+    parse(checkArgs, checkOpts, initialise);
+}
+
+
+void Foam::argList::parse
+(
+    bool checkArgs,
+    bool checkOpts,
+    bool initialise
+)
+{
     // Help/documentation options:
     //   -help    print the usage
     //   -doc     display application documentation in browser
@@ -495,42 +529,44 @@ Foam::argList::argList
     }
 
 
-    string dateString = clock::date();
-    string timeString = clock::clockTime();
-
-    // Print the banner once only for parallel runs
-    if (Pstream::master() && bannerEnabled)
+    if (initialise)
     {
-        IOobject::writeBanner(Info, true)
-            << "Build  : " << Foam::FOAMbuild << nl
-            << "Exec   : " << argListString.c_str() << nl
-            << "Date   : " << dateString.c_str() << nl
-            << "Time   : " << timeString.c_str() << nl
-            << "Host   : " << hostName() << nl
-            << "PID    : " << pid() << endl;
-    }
+        string dateString = clock::date();
+        string timeString = clock::clockTime();
 
-    jobInfo.add("startDate", dateString);
-    jobInfo.add("startTime", timeString);
-    jobInfo.add("userName", userName());
-    jobInfo.add("foamVersion", word(FOAMversion));
-    jobInfo.add("code", executable_);
-    jobInfo.add("argList", argListString);
-    jobInfo.add("currentDir", cwd());
-    jobInfo.add("PPID", ppid());
-    jobInfo.add("PGID", pgid());
-
-    // add build information - only use the first word
-    {
-        std::string build(Foam::FOAMbuild);
-        std::string::size_type found = build.find(' ');
-        if (found != std::string::npos)
+        // Print the banner once only for parallel runs
+        if (Pstream::master() && bannerEnabled)
         {
-            build.resize(found);
+            IOobject::writeBanner(Info, true)
+                << "Build  : " << Foam::FOAMbuild << nl
+                << "Exec   : " << argListStr_.c_str() << nl
+                << "Date   : " << dateString.c_str() << nl
+                << "Time   : " << timeString.c_str() << nl
+                << "Host   : " << hostName() << nl
+                << "PID    : " << pid() << endl;
         }
-        jobInfo.add("foamBuild", build);
-    }
 
+        jobInfo.add("startDate", dateString);
+        jobInfo.add("startTime", timeString);
+        jobInfo.add("userName", userName());
+        jobInfo.add("foamVersion", word(FOAMversion));
+        jobInfo.add("code", executable_);
+        jobInfo.add("argList", argListStr_);
+        jobInfo.add("currentDir", cwd());
+        jobInfo.add("PPID", ppid());
+        jobInfo.add("PGID", pgid());
+
+        // add build information - only use the first word
+        {
+            std::string build(Foam::FOAMbuild);
+            std::string::size_type found = build.find(' ');
+            if (found != std::string::npos)
+            {
+                build.resize(found);
+            }
+            jobInfo.add("foamBuild", build);
+        }
+    }
 
     // Case is a single processor run unless it is running parallel
     int nProcs = 1;
@@ -781,52 +817,56 @@ Foam::argList::argList
         }
     }
 
-    jobInfo.add("root", rootPath_);
-    jobInfo.add("case", globalCase_);
-    jobInfo.add("nProcs", nProcs);
-    if (slaveProcs.size())
-    {
-        jobInfo.add("slaves", slaveProcs);
-    }
-    if (roots.size())
+    if (initialise)
     {
-        jobInfo.add("roots", roots);
-    }
-    jobInfo.write();
-
-    // Switch on signal trapping. We have to wait until after Pstream::init
-    // since this sets up its own ones.
-    sigFpe_.set(bannerEnabled);
-    sigInt_.set(bannerEnabled);
-    sigQuit_.set(bannerEnabled);
-    sigSegv_.set(bannerEnabled);
+        jobInfo.add("root", rootPath_);
+        jobInfo.add("case", globalCase_);
+        jobInfo.add("nProcs", nProcs);
+        if (slaveProcs.size())
+        {
+            jobInfo.add("slaves", slaveProcs);
+        }
+        if (roots.size())
+        {
+            jobInfo.add("roots", roots);
+        }
+        jobInfo.write();
 
-    if (bannerEnabled)
-    {
-        Info<< "fileModificationChecking : "
-            << "Monitoring run-time modified files using "
-            << regIOobject::fileCheckTypesNames
-                [
-                    regIOobject::fileModificationChecking
-                ]
-            << endl;
+        // Switch on signal trapping. We have to wait until after Pstream::init
+        // since this sets up its own ones.
+        sigFpe_.set(bannerEnabled);
+        sigInt_.set(bannerEnabled);
+        sigQuit_.set(bannerEnabled);
+        sigSegv_.set(bannerEnabled);
 
-        Info<< "allowSystemOperations : ";
-        if (dynamicCode::allowSystemOperations)
+        if (bannerEnabled)
         {
-            Info<< "Allowing user-supplied system call operations" << endl;
+            Info<< "fileModificationChecking : "
+                << "Monitoring run-time modified files using "
+                << regIOobject::fileCheckTypesNames
+                    [
+                        regIOobject::fileModificationChecking
+                    ]
+                << endl;
+
+            Info<< "allowSystemOperations : ";
+            if (dynamicCode::allowSystemOperations)
+            {
+                Info<< "Allowing user-supplied system call operations" << endl;
+            }
+            else
+            {
+                Info<< "Disallowing user-supplied system call operations"
+                    << endl;
+            }
         }
-        else
+
+        if (Pstream::master() && bannerEnabled)
         {
-            Info<< "Disallowing user-supplied system call operations" << endl;
+            Info<< endl;
+            IOobject::writeDivider(Info);
         }
     }
-
-    if (Pstream::master() && bannerEnabled)
-    {
-        Info<< endl;
-        IOobject::writeDivider(Info);
-    }
 }
 
 
diff --git a/src/OpenFOAM/global/argList/argList.H b/src/OpenFOAM/global/argList/argList.H
index 4cc354d2cbe..c7e07026bdc 100644
--- a/src/OpenFOAM/global/argList/argList.H
+++ b/src/OpenFOAM/global/argList/argList.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011-2012 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2011-2013 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -41,7 +41,7 @@ Description
 
     \par Default command-line options
     \param -case \<dir\> \n
-        select an case directory instead of the current working directory
+        select a case directory instead of the current working directory
     \param -parallel \n
         specify case as a parallel job
     \param -doc \n
@@ -69,6 +69,7 @@ Note
 
 SourceFiles
     argList.C
+    argListI.H
 
 \*---------------------------------------------------------------------------*/
 
@@ -111,6 +112,7 @@ class argList
         fileName rootPath_;
         fileName globalCase_;
         fileName case_;
+        string argListStr_;
 
         ParRunControl parRunControl_;
 
@@ -186,17 +188,37 @@ public:
         (
             int& argc,
             char**& argv,
-            bool checkArgs=true,
-            bool checkOpts=true
+            bool checkArgs = true,
+            bool checkOpts = true,
+            bool initialise = true
         );
 
+        //- Construct copy with new options
+        argList
+        (
+            const argList& args,
+            const HashTable<string>& options,
+            bool checkArgs = true,
+            bool checkOpts = true,
+            bool initialise = true
+        );
 
-        //- Destructor
-        virtual ~argList();
+
+    //- Destructor
+    virtual ~argList();
 
 
     // Member functions
 
+        //- Parse
+        void parse
+        (
+            bool checkArgs,
+            bool checkOpts,
+            bool initialise
+        );
+
+
         // Access
 
             //- Name of executable without the path
@@ -211,12 +233,18 @@ public:
             //- Return case name
             inline const fileName& globalCaseName() const;
 
+            //- Return parRunControl
+            inline const ParRunControl& parRunControl() const;
+
             //- Return the path to the caseName
             inline fileName path() const;
 
             //- Return arguments
             inline const stringList& args() const;
 
+            //- Return non-const access to arguments
+            inline stringList& args();
+
             //- Return the argument corresponding to index.
             inline const string& arg(const label index) const;
 
@@ -240,6 +268,9 @@ public:
             //- Return options
             inline const Foam::HashTable<string>& options() const;
 
+            //- Return non-const access to options
+            inline Foam::HashTable<string>& options();
+
             //- Return the argument string associated with the named option
             inline const string& option(const word& opt) const;
 
@@ -295,6 +326,7 @@ public:
             //  \sa option()
             inline const string& operator[](const word& opt) const;
 
+
         // Edit
 
             //- Add to a bool option to validOptions with usage information
diff --git a/src/OpenFOAM/global/argList/argListI.H b/src/OpenFOAM/global/argList/argListI.H
index e35663540be..47ad29a58eb 100644
--- a/src/OpenFOAM/global/argList/argListI.H
+++ b/src/OpenFOAM/global/argList/argListI.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2011-2013 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -51,6 +51,12 @@ inline const Foam::fileName& Foam::argList::globalCaseName() const
 }
 
 
+inline const Foam::ParRunControl& Foam::argList::parRunControl() const
+{
+    return parRunControl_;
+}
+
+
 inline Foam::fileName Foam::argList::path() const
 {
     return rootPath()/caseName();
@@ -63,6 +69,12 @@ inline const Foam::stringList& Foam::argList::args() const
 }
 
 
+inline Foam::stringList& Foam::argList::args()
+{
+    return args_;
+}
+
+
 inline const Foam::string& Foam::argList::arg(const label index) const
 {
     return args_[index];
@@ -81,6 +93,12 @@ inline const Foam::HashTable<Foam::string>& Foam::argList::options() const
 }
 
 
+inline Foam::HashTable<Foam::string>& Foam::argList::options()
+{
+    return options_;
+}
+
+
 inline const Foam::string& Foam::argList::option(const word& opt) const
 {
     return options_[opt];
-- 
GitLab