BLCMDdefine Class Reference

Inheritance diagram for BLCMDdefine:

BLCommand

List of all members.


Detailed Description

class BLCMDdefine implements the "define" command to define a macro (an argument-expanded set of commands).

Public Member Functions

 BLCMDdefine ()
G4String commandName ()
int command (BLArgumentVector &argv, BLArgumentMap &namedArgs)

Constructor & Destructor Documentation

BLCMDdefine::BLCMDdefine (  ) 

References BLCMDTYPE_CONTROL, BLCommand::registerCommand(), BLCommand::setDescription(), and BLCommand::setSynopsis().

00060                          : BLCommand()
00061 {
00062         registerCommand(BLCMDTYPE_CONTROL);
00063         setSynopsis("defines a macro (argument-expanded set of commands).");
00064         setDescription("The first argument is the macro name, additional arguments\n"
00065           "become lines in the body of the expanded macro. The macro name\n"
00066           "becomes a command with up to 9 positional arguments. When the\n"
00067           "command is issued, the body is expanded and executed, with\n"
00068           "these substitutions:\n"
00069           "  $0     MacroName\n"
00070           "  $1-$9  Positional arguments of the command\n"
00071           "  $#     # macro expansions (for generating unique names)\n"
00072           "NOTE: $paramname is expanded in the define command, but $$paramname "
00073           "is expanded when the macro is invoked.");
00074 }


Member Function Documentation

G4String BLCMDdefine::commandName (  )  [inline, virtual]

Implements BLCommand.

Referenced by command().

00031 { return "define"; }

int BLCMDdefine::command ( BLArgumentVector argv,
BLArgumentMap namedArgs 
) [virtual]

Implements BLCommand.

References commandName(), IndentDesc(), and BLCommand::printError().

00077 {
00078         if(argv.size() < 1) {
00079                 printError("define: need command name being defined");
00080                 return -1;
00081         }
00082 
00083         // the arguments are the body
00084         G4String body;
00085         for(unsigned i=1; i<argv.size(); ++i) {
00086                 if(argv[i].size() > 0) {body += argv[i]; body += "\n";}
00087         }
00088 
00089         new Macro(argv[0],body);
00090 
00091         // print the definition
00092         G4String indent1(commandName());
00093         do { indent1 += " "; } while(indent1.size() < IndentDesc.size());
00094         printf("%s%s:\n",indent1.c_str(),argv[0].c_str());
00095         for(unsigned i=1; i<argv.size(); ++i) {
00096                 if(argv[i].size() > 0) 
00097                         printf("%s%s\n",IndentDesc.c_str(),argv[i].c_str());
00098         }
00099 
00100         return 0;
00101 }


The documentation for this class was generated from the following file:
g4beamline