G4UIcommand.hh

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id$
00028 //
00029 //
00030 
00031 #ifndef G4UIcommand_h
00032 #define G4UIcommand_h 1
00033 
00034 #include "G4UIparameter.hh"
00035 class G4UImessenger;
00036 #include "globals.hh"
00037 #include "G4ApplicationState.hh"
00038 #include <vector>
00039 #include "G4UItokenNum.hh"
00040 #include "G4ThreeVector.hh"
00041 
00042 // class description:
00043 //
00044 //  This G4UIcommand is the "concrete" base class which represents a command
00045 // used by Geant4 (G)UI. The user can use this class in case the parameter
00046 // arguments of a command are not suitable with respect to the derived command
00047 // classes.
00048 //  Some methods defined in this base class are used by the derived classes.
00049 //
00050 
00051 class G4UIcommand
00052 {
00053   public:
00054       G4UIcommand();
00055   public: // with description
00056       G4UIcommand(const char * theCommandPath, G4UImessenger * theMessenger);
00057       //  Constructor. The command string with full path directory
00058       // and the pointer to the messenger must be given.
00059   public:
00060       virtual ~G4UIcommand();
00061 
00062       G4int operator==(const G4UIcommand &right) const;
00063       G4int operator!=(const G4UIcommand &right) const;
00064 
00065       virtual G4int DoIt(G4String parameterList);
00066       G4String GetCurrentValue();
00067   public: // with description
00068       void AvailableForStates(G4ApplicationState s1);
00069       void AvailableForStates(G4ApplicationState s1,G4ApplicationState s2);
00070       void AvailableForStates(G4ApplicationState s1,G4ApplicationState s2,
00071                               G4ApplicationState s3);
00072       void AvailableForStates(G4ApplicationState s1,G4ApplicationState s2,
00073                               G4ApplicationState s3,G4ApplicationState s4);
00074       void AvailableForStates(G4ApplicationState s1,G4ApplicationState s2,
00075                               G4ApplicationState s3,G4ApplicationState s4,
00076                               G4ApplicationState s5);
00077       //  These methods define the states where the command is available.
00078       // Once one of these commands is invoked, the command application will
00079       // be denied when Geant4 is NOT in the assigned states.
00080   public:
00081       G4bool IsAvailable();
00082       virtual void List();
00083 
00084   public: // with description
00085       static G4String ConvertToString(G4bool boolVal);
00086       static G4String ConvertToString(G4int intValue);
00087       static G4String ConvertToString(G4double doubleValue);
00088       static G4String ConvertToString(G4double doubleValue,const char* unitName);
00089       static G4String ConvertToString(G4ThreeVector vec);
00090       static G4String ConvertToString(G4ThreeVector vec,const char* unitName);
00091       // Static methods for conversion from value(s) to a string. These methods are to be
00092       // used by GetCurrentValues() methods of concrete messengers.
00093 
00094       static G4bool ConvertToBool(const char* st);
00095       static G4int ConvertToInt(const char* st);
00096       static G4double ConvertToDouble(const char* st);
00097       static G4double ConvertToDimensionedDouble(const char* st);
00098       static G4ThreeVector ConvertTo3Vector(const char* st);
00099       static G4ThreeVector ConvertToDimensioned3Vector(const char* st);
00100       // Static methods for conversion from a string to a value of the returning type.
00101       // These methods are to be used directly by SetNewValues() methods of concrete
00102       // messengers, or GetNewXXXValue() of classes derived from this G4UIcommand class.
00103 
00104       static G4double ValueOf(const char* unitName);
00105       static G4String CategoryOf(const char* unitName);
00106       static G4String UnitsList(const char* unitCategory);
00107       // Static methods for unit and its category.
00108 
00109   private:
00110       void G4UIcommandCommonConstructorCode (const char * theCommandPath);
00111       G4UImessenger *messenger;
00112       G4String commandPath;
00113       G4String commandName;
00114       G4String rangeString;
00115       std::vector<G4UIparameter*> parameter;
00116       std::vector<G4String> commandGuidance;
00117       std::vector<G4ApplicationState> availabelStateList;
00118 
00119   public: // with description
00120       inline void SetRange(const char* rs)
00121       { rangeString = rs; }
00122       //  Defines the range the command parameter(s) can take.
00123       //  The variable name(s) appear in the range expression must be same
00124       // as the name(s) of the parameter(s).
00125       //  All the C++ syntax of relational operators are allowed for the
00126       // range expression.
00127   public:
00128       inline const G4String & GetRange() const
00129       { return rangeString; };
00130       inline G4int GetGuidanceEntries() const
00131       { return commandGuidance.size(); }
00132       inline const G4String & GetGuidanceLine(G4int i) const
00133       { return commandGuidance[i]; }
00134       inline const G4String & GetCommandPath() const
00135       { return commandPath; }
00136       inline const G4String & GetCommandName() const
00137       { return commandName; }
00138       inline G4int GetParameterEntries() const
00139       { return parameter.size(); }
00140       inline G4UIparameter * GetParameter(G4int i) const
00141       { return parameter[i]; }
00142       inline std::vector<G4ApplicationState>* GetStateList()
00143       { return &availabelStateList; }
00144       inline G4UImessenger * GetMessenger() const
00145       { return messenger; }
00146   public: // with description
00147       inline void SetParameter(G4UIparameter *const newParameter)
00148       {
00149   parameter.push_back( newParameter );
00150   newVal.resize( parameter.size() );
00151       }
00152       //  Defines a parameter. This method is used by the derived command classes
00153       // but the user can directly use this command when he/she defines a command
00154       // by hem(her)self without using the derived class. For this case, the order
00155       // of the parameters is the order of invoking this method.
00156       inline void SetGuidance(const char * aGuidance)
00157       {
00158         commandGuidance.push_back( G4String( aGuidance ) );
00159       }
00160       //  Adds a guidance line. Unlimitted number of invokation of this method is
00161       // allowed. The given lines of guidance will appear for the help. The first
00162       // line of the guidance will be used as the title of the command, i.e. one
00163       // line list of the commands.
00164   public:
00165       inline const G4String GetTitle() const
00166       {
00167       if(commandGuidance.size() == 0)
00168       { return G4String("...Title not available..."); }
00169       else
00170       { return commandGuidance[0]; }
00171       }
00172 
00173   protected:
00174     G4int CheckNewValue(const char* newValue);
00175 
00176     // --- the following is used by CheckNewValue() --------
00177   private:
00178     G4int TypeCheck(const char* t);
00179     G4int RangeCheck(const char* t);
00180     G4int IsInt(const char* str, short maxLength);
00181     G4int IsDouble(const char* str);
00182     G4int ExpectExponent(const char* str);
00183     //  syntax nodes
00184     yystype Expression( void );
00185     yystype LogicalORExpression( void );
00186     yystype LogicalANDExpression( void );
00187     yystype EqualityExpression ( void );
00188     yystype RelationalExpression( void );
00189     yystype AdditiveExpression( void );
00190     yystype MultiplicativeExpression( void );
00191     yystype UnaryExpression( void );
00192     yystype PrimaryExpression( void );
00193     //  semantics routines
00194     G4int Eval2( yystype arg1, G4int op, yystype arg2 );
00195     G4int CompareInt( G4int arg1, G4int op, G4int arg2);
00196     G4int CompareDouble( G4double arg1, G4int op, G4double arg2);
00197     //  utility
00198     tokenNum Yylex( void );      // returns next token
00199     unsigned IndexOf( const char* ); // returns the index of the var name
00200     unsigned IsParameter( const char* ); // returns 1 or 0
00201     G4int G4UIpGetc( void );      // read one char from rangeBuf
00202     G4int G4UIpUngetc( G4int c );   // put back
00203     G4int Backslash( G4int c );
00204     G4int Follow( G4int expect, G4int ifyes, G4int ifno );
00205     G4String TokenToStr(G4int token);
00206     void PrintToken(void);      // for debug
00207     //  data
00208     G4String rangeBuf;
00209     G4int bp;                      // buffer pointer for rangeBuf
00210     tokenNum token;
00211     yystype yylval;
00212     std::vector<yystype>  newVal;
00213     G4int paramERR;
00214 };
00215 
00216 #endif
00217 

Generated on Mon May 27 17:50:05 2013 for Geant4 by  doxygen 1.4.7