Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-01 07:50:56

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 /// \file CommandLineParser.hh
0027 /// \brief Definition of the G4DNAPARSER::CommandLineParser class
0028 
0029 // This example is provided by the Geant4-DNA collaboration
0030 // Any report or published results obtained using the Geant4-DNA software
0031 // shall cite the following Geant4-DNA collaboration publication:
0032 // Med. Phys. 37 (2010) 4692-4708
0033 // J. Comput. Phys. 274 (2014) 841-882
0034 // The Geant4-DNA web site is available at http://geant4-dna.org
0035 //
0036 // Author: Mathieu Karamitros
0037 //
0038 //
0039 
0040 #ifndef COMMANDLINEPARSER_HH
0041 #define COMMANDLINEPARSER_HH
0042 
0043 #include "globals.hh"
0044 
0045 #include <map>
0046 
0047 namespace G4DNAPARSER
0048 {
0049 class Command
0050 {
0051   public:
0052     enum Type
0053     {
0054       WithOption,
0055       WithoutOption,
0056       OptionNotCompulsory
0057     };
0058 
0059     virtual const G4String& GetOption() { return fNoOption; }
0060     Command::Type GetType() { return fType; }
0061     G4bool IsActive() { return fActive; }
0062     const G4String& GetDescription() { return fDescription; }
0063     virtual const G4String& GetOptionName() { return fNoOption; }
0064     virtual const G4String& GetDefaultOption() { return fNoOption; }
0065 
0066     virtual void SetOption(const G4String&) { ; }
0067     virtual void SetOptionName(const G4String&) { ; }
0068     virtual void SetDefaultOption(const G4String&) { ; }
0069 
0070   protected:
0071     friend class CommandLineParser;
0072     Type fType;
0073     G4bool fActive;
0074     G4String fDescription;
0075     static G4String fNoOption;
0076 
0077     Command(Type, const G4String& description = "");
0078     virtual ~Command() { ; }
0079 };
0080 
0081 class CommandWithOption : public Command
0082 {
0083   public:
0084     virtual const G4String& GetOption() { return fOption; }
0085     virtual const G4String& GetOptionName() { return fOptionName; }
0086     virtual const G4String& GetDefaultOption() { return fDefaultOption; }
0087 
0088     virtual void SetOption(const G4String& in_op) { fOption = in_op; }
0089     virtual void SetOptionName(const G4String& in_op) { fOptionName = in_op; }
0090     virtual void SetDefaultOption(const G4String& in_op) { fDefaultOption = in_op; }
0091 
0092   private:
0093     friend class CommandLineParser;
0094     CommandWithOption(Type, const G4String& description = "", const G4String& defaultOption = "",
0095                       const G4String& optionName = "optionName");
0096 
0097     virtual ~CommandWithOption() { ; }
0098 
0099     G4String fOption;
0100     G4String fDefaultOption;
0101     G4String fOptionName;
0102 };
0103 
0104 class CommandLineParser
0105 {
0106     static CommandLineParser* fpInstance;
0107     std::map<G4String, Command*> fCommandMap;
0108     G4bool fOptionsWereSetup;
0109     G4int fMaxMarkerLength;
0110     G4int fMaxOptionNameLength;
0111     G4int fVerbose;
0112 
0113   public:
0114     static CommandLineParser* GetParser();
0115     CommandLineParser();
0116     ~CommandLineParser();
0117     static void DeleteInstance();
0118     int Parse(int& argc, char** argv);
0119     void PrintHelp();
0120     bool CheckIfNotHandledOptionsExists(int& argc, char** argv);
0121     void CorrectRemainingOptions(int& argc, char** argv);
0122     void AddCommand(const G4String& marker, Command::Type, const G4String& description = "",
0123                     const G4String& defaultOption = "", const G4String& optionName = "");
0124     Command* FindCommand(const G4String& marker);
0125     Command* GetCommandIfActive(const G4String& marker);
0126     G4bool WereOptionsSetup() { return fOptionsWereSetup; }
0127 };
0128 }  // namespace G4DNAPARSER
0129 #endif  // PARSER_HH