BLCommandAlias.hh

Go to the documentation of this file.
00001 //      BLCommandAlias.hh
00002 
00003 #ifndef BLCOMMANDALIAS_HH
00004 #define BLCOMMANDALIAS_HH
00005 
00006 #include "BLCommand.hh"
00007 
00008 /**     class BLCommandAlias defines an alias for an existing command
00009  *
00010  *      Usage: To define "alias" as an aslias for "mycommand":
00011  *      class BLCMDmycommand : public BLCommand {
00012  *              ...
00013  *      };
00014  *      BLCMDmycommand defaultMycommand;
00015  *      BLCommandAlias aliasMycommand("alias",defaultMycommand);
00016  *
00017  *      Note this is a global instantiation of BLCommandAlias, and that the
00018  *      second argument must be the global default instantiation of the desired
00019  *      command. This also works if BLCMDmycommand is derived from BLElement.
00020  *
00021  *      The alias will be registered as a command to BLCommand, and will get
00022  *      an appropriate entry in the help text.
00023  **/
00024 class BLCommandAlias : public BLCommand {
00025         const char *alias;
00026         BLCommand *instance;
00027 public:
00028         BLCommandAlias(const char *_alias, BLCommand &_instance) : BLCommand(){
00029                 alias = strdup(_alias);
00030                 instance = &_instance;
00031                 registerCommand(instance->getCmdType());
00032                 char tmp[256];
00033                 sprintf(tmp,"Alias for '%s'.",instance->commandName().c_str());
00034                 setSynopsis(strdup(tmp));
00035                 setDescription("");
00036         }
00037 
00038         G4String commandName() { return G4String(alias); }
00039 
00040         int command(BLArgumentVector& argv, BLArgumentMap& namedArgs)
00041                 { return instance->command(argv,namedArgs); }
00042 
00043 };
00044 
00045 #endif // BLCOMMANDALIAS_HH
g4beamline