G4GenericMessenger.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: G4UImessenger.hh,v 1.9 2006-06-29 19:08:19 gunter Exp $
00028 //
00029 
00030 #ifndef G4GenericMessenger_h
00031 #define G4GenericMmessenger_h 1
00032 
00033 #include "G4UImessenger.hh"
00034 #include "G4UIcommand.hh"
00035 #include "G4AnyType.hh"
00036 #include "G4AnyMethod.hh"
00037 #include "G4ApplicationState.hh"
00038 
00039 #include <map>
00040 #include <vector>
00041 
00042 class G4UIdirectory;
00043 
00045 
00046 class G4GenericMessenger : public G4UImessenger
00047 {
00048 public:
00050   G4GenericMessenger(void* obj, const G4String& dir = "", const G4String& doc = "");
00052   virtual ~G4GenericMessenger();
00054   virtual G4String GetCurrentValue(G4UIcommand* command);
00056   virtual void SetNewValue(G4UIcommand* command, G4String newValue);
00057   
00058 public:
00059   struct Command {
00060     enum UnitSpec {UnitCategory, UnitDefault};
00061     Command(G4UIcommand* cmd, const std::type_info& ti) : command(cmd), type(&ti) {}
00062     Command() : command(0), type(0) {}
00063     //    Command& operator =(const Command& rhs) { command = rhs.command; type = rhs.type; }
00064     Command& SetStates(G4ApplicationState s0) {command->AvailableForStates(s0); return *this;}
00065     Command& SetStates(G4ApplicationState s0, G4ApplicationState s1) {command->AvailableForStates(s0, s1); return *this;}
00066     Command& SetStates(G4ApplicationState s0, G4ApplicationState s1, G4ApplicationState s2){command->AvailableForStates(s0,s1,s2); return *this;}
00067     Command& SetStates(G4ApplicationState s0, G4ApplicationState s1, G4ApplicationState s2, G4ApplicationState s3) {command->AvailableForStates(s0,s1,s2,s3); return *this;}
00068     Command& SetStates(G4ApplicationState s0, G4ApplicationState s1, G4ApplicationState s2, G4ApplicationState s3, G4ApplicationState s4) {command->AvailableForStates(s0,s1,s2,s3,s4); return *this;}
00069     Command& SetRange(const G4String& range) {command->SetRange(range.c_str()); return *this;}
00070     Command& SetGuidance(const G4String& s) { command->SetGuidance(s); return *this; }
00071     Command& SetUnit(const G4String&, UnitSpec = UnitDefault);
00072     Command& SetUnitCategory(const G4String& u) {return SetUnit(u, UnitCategory);}
00073     Command& SetDefaultUnit(const G4String& u) {return SetUnit(u, UnitDefault);}
00074     Command& SetParameterName(const G4String&, G4bool, G4bool =false);
00075     Command& SetDefaultValue(const G4String&);
00076     Command& SetCandidates(const G4String&);
00077     
00078     G4UIcommand* command;
00079     const std::type_info* type;
00080   };
00081   struct Property : public Command {
00082     Property(const G4AnyType& var, G4UIcommand* cmd) : Command(cmd, var.TypeInfo()) , variable(var) {}
00083     Property() {}
00084     G4AnyType variable;
00085   };
00086   struct Method : public Command {
00087     Method(const G4AnyMethod& fun, void* obj, G4UIcommand* cmd) : Command(cmd, fun.ArgType()), method(fun), object(obj) {}
00088     Method() : object(0) {}
00089     G4AnyMethod method;
00090     void* object;
00091   };
00092   
00094   //Command& DeclarePropertyWithUnit(const G4String& name, const G4Any& variable, const G4String& unit, const G4String& doc = "");
00095   Command& DeclareProperty(const G4String& name, const G4AnyType& variable, const G4String& doc = "");
00096   Command& DeclareMethod(const G4String& name, const G4AnyMethod& fun, const G4String& doc = "");
00097   //Command& DeclareMethodWithUnit(const G4String& name, const G4AnyFunc& fun, const G4String& unit, const G4String& doc = "");
00098   void SetDirectory(const G4String& dir) {directory = dir;}
00099   void SetGuidance(const G4String& s);
00100     
00101 private:
00102   std::map<G4String, Property> properties;
00103   std::map<G4String, Method> methods;
00104   G4UIdirectory* dircmd;
00105   G4String directory;
00106   void* object;
00107 };
00108 
00109 
00110 #endif
00111 

Generated on Mon May 27 17:48:21 2013 for Geant4 by  doxygen 1.4.7