00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
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
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
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
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