ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CommandLineParser.hh
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file CommandLineParser.hh
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 // This example is provided by the Geant4-DNA collaboration
27 // Any report or published results obtained using the Geant4-DNA software
28 // shall cite the following Geant4-DNA collaboration publication:
29 // Med. Phys. 37 (2010) 4692-4708
30 // The Geant4-DNA web site is available at http://geant4-dna.org
31 //
32 // Author: Mathieu Karamitros
33 //
34 //
37 
38 #ifndef COMMANDLINEPARSER_HH
39 #define COMMANDLINEPARSER_HH
40 
41 #include "globals.hh"
42 #include <map>
43 
44 namespace G4DNAPARSER
45 {
46 class Command
47 {
48 public:
49  enum Type
50  {
51  WithOption,
54  };
55 
56  virtual const G4String& GetOption() { return fNoOption;}
58  G4bool IsActive() {return fActive;}
60  virtual const G4String& GetOptionName() { return fNoOption;}
61  virtual const G4String& GetDefaultOption() { return fNoOption;}
62 
63  virtual void SetOption(const G4String&){;}
64  virtual void SetOptionName(const G4String&){;}
65  virtual void SetDefaultOption(const G4String&){;}
66 
67 protected:
68  friend class CommandLineParser;
69  Type fType;
72  static G4String fNoOption;
73 
74  Command(Type,
75  const G4String &description = "");
76  virtual ~Command(){;}
77 };
78 
79 class CommandWithOption : public Command
80 {
81 public:
82  virtual const G4String& GetOption() {return fOption;}
83  virtual const G4String& GetOptionName() {return fOptionName;}
84  virtual const G4String& GetDefaultOption() { return fDefaultOption;}
85 
86  virtual void SetOption(const G4String& in_op){ fOption = in_op;}
87  virtual void SetOptionName(const G4String& in_op){ fOptionName = in_op;}
88  virtual void SetDefaultOption(const G4String& in_op){ fDefaultOption = in_op;}
89 
90 private:
91  friend class CommandLineParser;
93  const G4String &description = "",
94  const G4String &defaultOption = "",
95  const G4String &optionName ="optionName");
96 
97  virtual ~CommandWithOption(){;}
98 
102 };
103 
104 class CommandLineParser
105 {
106 
107 public:
108  static CommandLineParser* GetParser();
111  static void DeleteInstance();
112  int Parse(int& argc, char **argv);
113  void PrintHelp();
114  bool CheckIfNotHandledOptionsExists(int& argc, char** argv);
115  void CorrectRemainingOptions(int& argc, char **argv);
116  void AddCommand(const G4String & marker,Command::Type,
117  const G4String& description = "",
118  const G4String& defaultOption = "",
119  const G4String& optionName = "");
120  Command* FindCommand(const G4String &marker);
121  Command* GetCommandIfActive(const G4String &marker);
123 
124 private:
126  std::map<G4String, Command*> fCommandMap;
130  G4int fVerbose;
131 
132 };
133 }
134 #endif // PARSER_HH