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