File indexing completed on 2025-02-23 09:21:51
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038 #ifndef COMMANDLINEPARSER_HH
0039 #define COMMANDLINEPARSER_HH
0040
0041 #include "globals.hh"
0042
0043 #include <map>
0044
0045 namespace G4DNAPARSER
0046 {
0047 class Command
0048 {
0049 public:
0050 enum Type
0051 {
0052 WithOption,
0053 WithoutOption,
0054 OptionNotCompulsory
0055 };
0056
0057 virtual const G4String& GetOption() { return fNoOption; }
0058 Command::Type GetType() { return fType; }
0059 G4bool IsActive() { return fActive; }
0060 const G4String& GetDescription() { return fDescription; }
0061 virtual const G4String& GetOptionName() { return fNoOption; }
0062 virtual const G4String& GetDefaultOption() { return fNoOption; }
0063
0064 virtual void SetOption(const G4String&) { ; }
0065 virtual void SetOptionName(const G4String&) { ; }
0066 virtual void SetDefaultOption(const G4String&) { ; }
0067
0068 protected:
0069 friend class CommandLineParser;
0070 Type fType;
0071 G4bool fActive;
0072 G4String fDescription;
0073 static G4String fNoOption;
0074
0075 Command(Type, const G4String& description = "");
0076 virtual ~Command() { ; }
0077 };
0078
0079 class CommandWithOption : public Command
0080 {
0081 public:
0082 virtual const G4String& GetOption() { return fOption; }
0083 virtual const G4String& GetOptionName() { return fOptionName; }
0084 virtual const G4String& GetDefaultOption() { return fDefaultOption; }
0085
0086 virtual void SetOption(const G4String& in_op) { fOption = in_op; }
0087 virtual void SetOptionName(const G4String& in_op) { fOptionName = in_op; }
0088 virtual void SetDefaultOption(const G4String& in_op) { fDefaultOption = in_op; }
0089
0090 private:
0091 friend class CommandLineParser;
0092 CommandWithOption(Type, const G4String& description = "", const G4String& defaultOption = "",
0093 const G4String& optionName = "optionName");
0094
0095 virtual ~CommandWithOption() { ; }
0096
0097 G4String fOption;
0098 G4String fDefaultOption;
0099 G4String fOptionName;
0100 };
0101
0102 class CommandLineParser
0103 {
0104 public:
0105 static CommandLineParser* GetParser();
0106 CommandLineParser();
0107 ~CommandLineParser();
0108 static void DeleteInstance();
0109 int Parse(int& argc, char** argv);
0110 void PrintHelp();
0111 bool CheckIfNotHandledOptionsExists(int& argc, char** argv);
0112 void CorrectRemainingOptions(int& argc, char** argv);
0113 void AddCommand(const G4String& marker, Command::Type, const G4String& description = "",
0114 const G4String& defaultOption = "", const G4String& optionName = "");
0115 Command* FindCommand(const G4String& marker);
0116 Command* GetCommandIfActive(const G4String& marker);
0117 G4bool WereOptionsSetup() { return fOptionsWereSetup; }
0118
0119 private:
0120 static CommandLineParser* fpInstance;
0121 std::map<G4String, Command*> fCommandMap;
0122 G4bool fOptionsWereSetup;
0123 G4int fMaxMarkerLength;
0124 G4int fMaxOptionNameLength;
0125 G4int fVerbose;
0126 };
0127 }
0128 #endif