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10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /intercoms/include/G4UIcommand.hh (Version 11.3.0) and /intercoms/include/G4UIcommand.hh (Version 11.2)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
 26 // G4UIcommand                                     26 // G4UIcommand
 27 //                                                 27 //
 28 // Class description:                              28 // Class description:
 29 //                                                 29 //
 30 // This G4UIcommand is the "concrete" base cla     30 // This G4UIcommand is the "concrete" base class which represents a command
 31 // used by Geant4 (G)UI. The user can use this     31 // used by Geant4 (G)UI. The user can use this class in case the parameter
 32 // arguments of a command are not suitable wit     32 // arguments of a command are not suitable with respect to the derived command
 33 // classes.                                        33 // classes.
 34 // Some methods defined in this base class are     34 // Some methods defined in this base class are used by the derived classes
 35                                                    35 
 36 // Author: Makoto Asai (SLAC), 1998                36 // Author: Makoto Asai (SLAC), 1998
 37 // -------------------------------------------     37 // --------------------------------------------------------------------
 38 #ifndef G4UIcommand_hh                             38 #ifndef G4UIcommand_hh
 39 #define G4UIcommand_hh 1                           39 #define G4UIcommand_hh 1
 40                                                    40 
 41 #include "G4ApplicationState.hh"                   41 #include "G4ApplicationState.hh"
 42 #include "G4ThreeVector.hh"                        42 #include "G4ThreeVector.hh"
 43 #include "G4UIparameter.hh"                        43 #include "G4UIparameter.hh"
                                                   >>  44 #include "G4UItokenNum.hh"
 44 #include "globals.hh"                              45 #include "globals.hh"
 45                                                    46 
 46 #include <vector>                                  47 #include <vector>
 47                                                    48 
 48 class G4UImessenger;                               49 class G4UImessenger;
 49                                                    50 
 50 class G4UIcommand                                  51 class G4UIcommand
 51 {                                                  52 {
 52   public:                                          53   public:
 53     // Dummy default constructor                   54     // Dummy default constructor
 54     G4UIcommand() = default;                       55     G4UIcommand() = default;
 55                                                    56 
 56     // Constructor. The command string with fu     57     // Constructor. The command string with full path directory
 57     // and the pointer to the messenger must b     58     // and the pointer to the messenger must be given.
 58     // If tBB is set to false, this command wo     59     // If tBB is set to false, this command won't be sent to worker threads.
 59     // This tBB parameter could be changed wit     60     // This tBB parameter could be changed with SetToBeBroadcasted() method
 60     // except for G4UIdirectory                    61     // except for G4UIdirectory
 61     G4UIcommand(const char* theCommandPath, G4     62     G4UIcommand(const char* theCommandPath, G4UImessenger* theMessenger, G4bool tBB = true);
 62                                                    63 
 63     virtual ~G4UIcommand();                        64     virtual ~G4UIcommand();
 64                                                    65 
 65     G4bool operator==(const G4UIcommand& right     66     G4bool operator==(const G4UIcommand& right) const;
 66     G4bool operator!=(const G4UIcommand& right     67     G4bool operator!=(const G4UIcommand& right) const;
 67                                                    68 
 68     virtual G4int DoIt(const G4String& paramet <<  69     virtual G4int DoIt(G4String parameterList);
 69                                                    70 
 70     G4String GetCurrentValue();                    71     G4String GetCurrentValue();
 71                                                    72 
 72     // These methods define the states where t     73     // These methods define the states where the command is available.
 73     // Once one of these commands is invoked,      74     // Once one of these commands is invoked, the command application will
 74     // be denied when Geant4 is NOT in the ass     75     // be denied when Geant4 is NOT in the assigned states
 75     void AvailableForStates(G4ApplicationState     76     void AvailableForStates(G4ApplicationState s1);
 76     void AvailableForStates(G4ApplicationState     77     void AvailableForStates(G4ApplicationState s1, G4ApplicationState s2);
 77     void AvailableForStates(G4ApplicationState     78     void AvailableForStates(G4ApplicationState s1, G4ApplicationState s2, G4ApplicationState s3);
 78     void AvailableForStates(G4ApplicationState     79     void AvailableForStates(G4ApplicationState s1, G4ApplicationState s2, G4ApplicationState s3,
 79                             G4ApplicationState     80                             G4ApplicationState s4);
 80     void AvailableForStates(G4ApplicationState     81     void AvailableForStates(G4ApplicationState s1, G4ApplicationState s2, G4ApplicationState s3,
 81                             G4ApplicationState     82                             G4ApplicationState s4, G4ApplicationState s5);
 82                                                    83 
 83     G4bool IsAvailable();                          84     G4bool IsAvailable();
 84                                                    85 
 85     virtual void List();                           86     virtual void List();
 86                                                    87 
 87     // Static methods for conversion from valu     88     // Static methods for conversion from value(s) to a string.
 88     // These methods are to be used by GetCurr     89     // These methods are to be used by GetCurrentValues() methods
 89     // of concrete messengers                      90     // of concrete messengers
 90     static G4String ConvertToString(G4bool boo     91     static G4String ConvertToString(G4bool boolVal);
 91     static G4String ConvertToString(G4int intV     92     static G4String ConvertToString(G4int intValue);
 92     static G4String ConvertToString(G4long lon     93     static G4String ConvertToString(G4long longValue);
 93     static G4String ConvertToString(G4double d     94     static G4String ConvertToString(G4double doubleValue);
 94     static G4String ConvertToString(G4double d     95     static G4String ConvertToString(G4double doubleValue, const char* unitName);
 95     static G4String ConvertToString(const G4Th     96     static G4String ConvertToString(const G4ThreeVector& vec);
 96     static G4String ConvertToString(const G4Th     97     static G4String ConvertToString(const G4ThreeVector& vec, const char* unitName);
 97                                                    98 
 98     // Static methods for conversion from a st     99     // Static methods for conversion from a string to a value of the returning
 99     // type. These methods are to be used dire    100     // type. These methods are to be used directly by SetNewValues() methods
100     // of concrete messengers, or GetNewXXXVal    101     // of concrete messengers, or GetNewXXXValue() of classes derived from
101     // this G4UIcommand class                     102     // this G4UIcommand class
102     static G4bool ConvertToBool(const char* st    103     static G4bool ConvertToBool(const char* st);
103     static G4int ConvertToInt(const char* st);    104     static G4int ConvertToInt(const char* st);
104     static G4long ConvertToLongInt(const char*    105     static G4long ConvertToLongInt(const char* st);
105     static G4double ConvertToDouble(const char    106     static G4double ConvertToDouble(const char* st);
106     static G4double ConvertToDimensionedDouble    107     static G4double ConvertToDimensionedDouble(const char* st);
107     static G4ThreeVector ConvertTo3Vector(cons    108     static G4ThreeVector ConvertTo3Vector(const char* st);
108     static G4ThreeVector ConvertToDimensioned3    109     static G4ThreeVector ConvertToDimensioned3Vector(const char* st);
109                                                   110 
110     // Static methods for unit and its categor    111     // Static methods for unit and its category
111     static G4double ValueOf(const char* unitNa    112     static G4double ValueOf(const char* unitName);
112     static G4String CategoryOf(const char* uni    113     static G4String CategoryOf(const char* unitName);
113     static G4String UnitsList(const char* unit    114     static G4String UnitsList(const char* unitCategory);
114                                                   115 
115     // Defines the range the command parameter    116     // Defines the range the command parameter(s) can take.
116     // The variable name(s) appear in the rang    117     // The variable name(s) appear in the range expression must be the same
117     // as the name(s) of the parameter(s).        118     // as the name(s) of the parameter(s).
118     // All the C++ syntax of relational operat    119     // All the C++ syntax of relational operators are allowed for the
119     // range expression                           120     // range expression
120     inline void SetRange(const char* rs) { ran    121     inline void SetRange(const char* rs) { rangeExpression = rs; }
121                                                   122 
122     inline const G4String& GetRange() const {     123     inline const G4String& GetRange() const { return rangeExpression; }
123     inline std::size_t GetGuidanceEntries() co    124     inline std::size_t GetGuidanceEntries() const { return commandGuidance.size(); }
124     inline const G4String& GetGuidanceLine(G4i    125     inline const G4String& GetGuidanceLine(G4int i) const { return commandGuidance[i]; }
125     inline const G4String& GetCommandPath() co    126     inline const G4String& GetCommandPath() const { return commandPath; }
126     inline const G4String& GetCommandName() co    127     inline const G4String& GetCommandName() const { return commandName; }
127     inline std::size_t GetParameterEntries() c    128     inline std::size_t GetParameterEntries() const { return parameter.size(); }
128     inline G4UIparameter* GetParameter(G4int i    129     inline G4UIparameter* GetParameter(G4int i) const { return parameter[i]; }
129     inline std::vector<G4ApplicationState>* Ge    130     inline std::vector<G4ApplicationState>* GetStateList() { return &availabelStateList; }
130     inline G4UImessenger* GetMessenger() const    131     inline G4UImessenger* GetMessenger() const { return messenger; }
131                                                   132 
132     // Defines a parameter. This method is use    133     // Defines a parameter. This method is used by the derived command
133     // classes but the user can directly use t    134     // classes but the user can directly use this command when defining
134     // a command, without using the derived cl    135     // a command, without using the derived class. For this case, the order
135     // of the parameters is the order of invok    136     // of the parameters is the order of invoking this method
136     inline void SetParameter(G4UIparameter* co    137     inline void SetParameter(G4UIparameter* const newParameter)
137     {                                             138     {
138       parameter.push_back(newParameter);          139       parameter.push_back(newParameter);
                                                   >> 140       newVal.resize(parameter.size());
139     }                                             141     }
140                                                   142 
141     // Adds a guidance line. Unlimited times o    143     // Adds a guidance line. Unlimited times of invokation of this method is
142     // allowed. The given lines of guidance wi    144     // allowed. The given lines of guidance will appear for the help.
143     // The first line of the guidance will be     145     // The first line of the guidance will be used as the title of the
144     // command, i.e. one line list of the comm    146     // command, i.e. one line list of the commands
145     inline void SetGuidance(const char* aGuida    147     inline void SetGuidance(const char* aGuidance) { commandGuidance.emplace_back(aGuidance); }
146                                                   148 
147     inline const G4String GetTitle() const        149     inline const G4String GetTitle() const
148     {                                             150     {
149       return (commandGuidance.empty()) ? G4Str    151       return (commandGuidance.empty()) ? G4String("...Title not available...") : commandGuidance[0];
150     }                                             152     }
151                                                   153 
152     inline void SetToBeBroadcasted(G4bool val)    154     inline void SetToBeBroadcasted(G4bool val) { toBeBroadcasted = val; }
153     inline G4bool ToBeBroadcasted() const { re    155     inline G4bool ToBeBroadcasted() const { return toBeBroadcasted; }
154     inline void SetToBeFlushed(G4bool val) { t    156     inline void SetToBeFlushed(G4bool val) { toBeFlushed = val; }
155     inline G4bool ToBeFlushed() const { return    157     inline G4bool ToBeFlushed() const { return toBeFlushed; }
156     inline void SetWorkerThreadOnly(G4bool val    158     inline void SetWorkerThreadOnly(G4bool val = true) { workerThreadOnly = val; }
157     inline G4bool IsWorkerThreadOnly() const {    159     inline G4bool IsWorkerThreadOnly() const { return workerThreadOnly; }
158                                                   160 
159     inline void CommandFailed(G4int errCode, G    161     inline void CommandFailed(G4int errCode, G4ExceptionDescription& ed)
160     {                                             162     {
161       commandFailureCode = errCode;               163       commandFailureCode = errCode;
162       failureDescription = ed.str();              164       failureDescription = ed.str();
163     }                                             165     }
164     inline void CommandFailed(G4ExceptionDescr    166     inline void CommandFailed(G4ExceptionDescription& ed)
165     {                                             167     {
166       commandFailureCode = 1;                     168       commandFailureCode = 1;
167       failureDescription = ed.str();              169       failureDescription = ed.str();
168     }                                             170     }
169     inline G4int IfCommandFailed() { return co    171     inline G4int IfCommandFailed() { return commandFailureCode; }
170     inline const G4String& GetFailureDescripti    172     inline const G4String& GetFailureDescription() { return failureDescription; }
171     inline void ResetFailure()                    173     inline void ResetFailure()
172     {                                             174     {
173       commandFailureCode = 0;                     175       commandFailureCode = 0;
174       failureDescription = "";                    176       failureDescription = "";
175     }                                             177     }
176                                                   178 
177   public:                                         179   public:
178     enum CommandType                              180     enum CommandType
179     {                                             181     {
180       BaseClassCmd,                               182       BaseClassCmd,
181       WithoutParameterCmd,                        183       WithoutParameterCmd,
182       WithABoolCmd,                               184       WithABoolCmd,
183       WithAnIntegerCmd,                           185       WithAnIntegerCmd,
184       WithALongIntCmd,                            186       WithALongIntCmd,
185       WithADoubleCmd,                             187       WithADoubleCmd,
186       WithADoubleAndUnitCmd,                      188       WithADoubleAndUnitCmd,
187       With3VectorCmd,                             189       With3VectorCmd,
188       With3VectorAndUnitCmd,                      190       With3VectorAndUnitCmd,
189       WithAStringCmd,                             191       WithAStringCmd,
190       CmdDirectory = -1                           192       CmdDirectory = -1
191     };                                            193     };
192                                                   194 
193     inline CommandType GetCommandType() const     195     inline CommandType GetCommandType() const { return commandType; }
194     void SetCommandType(CommandType);             196     void SetCommandType(CommandType);
195                                                   197 
196     inline void SetDefaultSortFlag(G4bool val)    198     inline void SetDefaultSortFlag(G4bool val) { ifSort = val; }
197                                                   199 
198   protected:                                      200   protected:
                                                   >> 201     // --- the following is used by CheckNewValue() --------
                                                   >> 202     using yystype = G4UItokenNum::yystype;
                                                   >> 203     using tokenNum = G4UItokenNum::tokenNum;
                                                   >> 204 
199     G4int CheckNewValue(const char* newValue);    205     G4int CheckNewValue(const char* newValue);
200                                                   206 
201     G4bool toBeBroadcasted = false;               207     G4bool toBeBroadcasted = false;
202     G4bool toBeFlushed = false;                   208     G4bool toBeFlushed = false;
203     G4bool workerThreadOnly = false;              209     G4bool workerThreadOnly = false;
204                                                   210 
205     G4int commandFailureCode = 0;                 211     G4int commandFailureCode = 0;
206     G4String failureDescription = "";             212     G4String failureDescription = "";
207                                                   213 
208     G4bool ifSort = false;                        214     G4bool ifSort = false;
209                                                   215 
210   private:                                        216   private:
211     void G4UIcommandCommonConstructorCode(cons    217     void G4UIcommandCommonConstructorCode(const char* theCommandPath);
212                                                   218 
                                                   >> 219     G4bool RangeCheck(const char* t);
                                                   >> 220 
                                                   >> 221     //  syntax nodes
                                                   >> 222     yystype Expression();
                                                   >> 223     yystype LogicalORExpression();
                                                   >> 224     yystype LogicalANDExpression();
                                                   >> 225     yystype EqualityExpression();
                                                   >> 226     yystype RelationalExpression();
                                                   >> 227     yystype AdditiveExpression();
                                                   >> 228     yystype MultiplicativeExpression();
                                                   >> 229     yystype UnaryExpression();
                                                   >> 230     yystype PrimaryExpression();
                                                   >> 231     //  semantics routines
                                                   >> 232     G4int Eval2(const yystype& arg1, G4int op, const yystype& arg2);
                                                   >> 233     //  utility
                                                   >> 234     tokenNum Yylex();  // returns next token
                                                   >> 235     unsigned IndexOf(const char*);  // returns the index of the var name
                                                   >> 236     unsigned IsParameter(const char*);  // returns 1 or 0
                                                   >> 237     G4int G4UIpGetc();  // read one char from rangeBuf
                                                   >> 238     G4int G4UIpUngetc(G4int c);  // put back
                                                   >> 239     G4int Backslash(G4int c);
                                                   >> 240     G4int Follow(G4int expect, G4int ifyes, G4int ifno);
                                                   >> 241 
                                                   >> 242     // Data -----------------------------------------------------------
                                                   >> 243 
213   private:                                        244   private:
214     CommandType commandType = BaseClassCmd;       245     CommandType commandType = BaseClassCmd;
215     G4UImessenger* messenger = nullptr;           246     G4UImessenger* messenger = nullptr;
216     G4String commandPath;                         247     G4String commandPath;
217     G4String commandName;                         248     G4String commandName;
218     G4String rangeExpression;                     249     G4String rangeExpression;
219     std::vector<G4UIparameter*> parameter;        250     std::vector<G4UIparameter*> parameter;
220     std::vector<G4String> commandGuidance;        251     std::vector<G4String> commandGuidance;
221     std::vector<G4ApplicationState> availabelS    252     std::vector<G4ApplicationState> availabelStateList;
                                                   >> 253 
                                                   >> 254     G4int bp = 0;  // current index into rangeExpression
                                                   >> 255     tokenNum token = G4UItokenNum::IDENTIFIER;
                                                   >> 256     yystype yylval;
                                                   >> 257     std::vector<yystype> newVal;
                                                   >> 258     G4int paramERR = 0;
222 };                                                259 };
223                                                   260 
224 #endif                                            261 #endif
225                                                   262