G4UIcommandTree Class Reference

#include <G4UIcommandTree.hh>


Public Member Functions

 G4UIcommandTree ()
 G4UIcommandTree (const char *thePathName)
 ~G4UIcommandTree ()
G4int operator== (const G4UIcommandTree &right) const
G4int operator!= (const G4UIcommandTree &right) const
void AddNewCommand (G4UIcommand *newCommand)
void RemoveCommand (G4UIcommand *aCommand)
G4UIcommand * FindPath (const char *commandPath) const
G4UIcommandTree * FindCommandTree (const char *commandPath)
G4String CompleteCommandPath (const G4String &commandPath)
void List () const
void ListCurrent () const
void ListCurrentWithNum () const
void CreateHTML ()
const G4UIcommand * GetGuidance () const
const G4String GetPathName () const
G4int GetTreeEntry () const
G4int GetCommandEntry () const
G4UIcommandTree * GetTree (G4int i)
G4UIcommandTree * GetTree (const char *comNameC)
G4UIcommand * GetCommand (G4int i)
const G4String GetTitle () const


Detailed Description

Definition at line 44 of file G4UIcommandTree.hh.


Constructor & Destructor Documentation

G4UIcommandTree::G4UIcommandTree (  ) 

Definition at line 35 of file G4UIcommandTree.cc.

Referenced by AddNewCommand().

00036 :guidance(NULL)
00037 { }

G4UIcommandTree::G4UIcommandTree ( const char *  thePathName  ) 

Definition at line 39 of file G4UIcommandTree.cc.

00040 :guidance(NULL)
00041 {
00042   pathName = thePathName;
00043 }

G4UIcommandTree::~G4UIcommandTree (  ) 

Definition at line 45 of file G4UIcommandTree.cc.

00046 {
00047   G4int i;
00048   G4int n_treeEntry = tree.size();
00049   for( i=0; i < n_treeEntry; i++ )
00050   { delete tree[i]; }
00051 }


Member Function Documentation

void G4UIcommandTree::AddNewCommand ( G4UIcommand *  newCommand  ) 

Definition at line 63 of file G4UIcommandTree.cc.

References AddNewCommand(), G4String::append(), G4String::first(), G4UIcommandTree(), G4UIcommand::GetCommandPath(), GetPathName(), G4String::isNull(), and G4String::remove().

Referenced by G4UImanager::AddNewCommand(), and AddNewCommand().

00064 {
00065   G4String commandPath = newCommand->GetCommandPath();
00066   G4String remainingPath = commandPath;
00067   remainingPath.remove(0,pathName.length());
00068   if( remainingPath.isNull() )
00069   {
00070     guidance = newCommand;
00071     return;
00072   }
00073   G4int i = remainingPath.first('/');
00074   if( i == G4int(std::string::npos) )
00075   {
00076     // Find command
00077     G4int n_commandEntry = command.size();
00078     for( G4int i_thCommand = 0; i_thCommand < n_commandEntry; i_thCommand++ )
00079     {
00080       if( remainingPath == command[i_thCommand]->GetCommandName() )
00081       { return; }
00082     }
00083     command.push_back( newCommand );
00084     return;
00085   }
00086   else
00087   {
00088     // Find path
00089     G4String nextPath = pathName;
00090     nextPath.append(remainingPath(0,i+1));
00091     G4int n_treeEntry = tree.size();
00092     for( G4int i_thTree = 0; i_thTree < n_treeEntry; i_thTree++ )
00093     {
00094       if( nextPath == tree[i_thTree]->GetPathName() )
00095       { 
00096         tree[i_thTree]->AddNewCommand( newCommand );
00097         return; 
00098       }
00099     }
00100     G4UIcommandTree * newTree = new G4UIcommandTree( nextPath );
00101     tree.push_back( newTree );
00102     newTree->AddNewCommand( newCommand );
00103     return;
00104   }
00105 }

G4String G4UIcommandTree::CompleteCommandPath ( const G4String &  commandPath  ) 

Definition at line 227 of file G4UIcommandTree.cc.

References FindCommandTree(), G4cout, G4endl, GetCommand(), GetCommandEntry(), GetPathName(), GetTree(), GetTreeEntry(), G4String::index(), G4String::last(), and G4String::remove().

00228 {
00229   G4String pName = aCommandPath;
00230   G4String remainingPath = aCommandPath;
00231   G4String empty = "";
00232   G4String matchingPath = empty;
00233 
00234   // find the tree
00235   G4int jpre= pName.last('/');
00236   if(jpre != G4int(G4String::npos)) pName.remove(jpre+1);
00237   G4UIcommandTree* aTree = FindCommandTree(pName);
00238 
00239   if (!aTree) {
00240     return empty;
00241   }
00242   
00243   if( pName.index( pName ) == std::string::npos ) return empty;
00244 
00245   std::vector<G4String> paths;
00246 
00247   // list matched directories/commands
00248   G4String strtmp;
00249   G4int nMatch= 0;
00250 
00251   int Ndir= aTree-> GetTreeEntry();
00252   int Ncmd= aTree-> GetCommandEntry();
00253   
00254   // directory ...
00255   for(G4int idir=1; idir<=Ndir; idir++) {
00256     G4String fpdir= aTree-> GetTree(idir)-> GetPathName();
00257     // matching test
00258     if( fpdir.index(remainingPath, 0) == 0) {
00259       if(nMatch==0) {
00260         matchingPath = fpdir;
00261       } else {
00262         matchingPath = GetFirstMatchedString(fpdir,matchingPath);
00263       }
00264       nMatch++;
00265       paths.push_back(fpdir);
00266     }
00267   }
00268   
00269   if (paths.size()>=2) {
00270     G4cout << "Matching directories :" << G4endl; 
00271     for( unsigned int i_thCommand = 0; i_thCommand < paths.size(); i_thCommand++ ) {
00272       G4cout << paths[i_thCommand] << G4endl; 
00273     }
00274   }
00275   
00276   // command ...
00277   std::vector<G4String> commands;
00278 
00279   for(G4int icmd=1; icmd<=Ncmd; icmd++){
00280     G4String fpcmd= aTree-> GetPathName() +
00281                     aTree-> GetCommand(icmd) -> GetCommandName();
00282     // matching test
00283     if( fpcmd.index(remainingPath, 0) ==0) {
00284       if(nMatch==0) {
00285         matchingPath= fpcmd + " ";
00286       } else {
00287         strtmp= fpcmd + " ";
00288         matchingPath= GetFirstMatchedString(matchingPath, strtmp);
00289       }
00290       nMatch++;
00291       commands.push_back(fpcmd+" ");
00292     }
00293   }
00294 
00295   if (commands.size()>=2) {
00296     G4cout << "Matching commands :" << G4endl; 
00297     for( unsigned int i_thCommand = 0; i_thCommand < commands.size(); i_thCommand++ ) {
00298       G4cout << commands[i_thCommand] << G4endl; 
00299     }
00300   }
00301 
00302   return matchingPath;
00303 }

void G4UIcommandTree::CreateHTML (  ) 

Definition at line 418 of file G4UIcommandTree.cc.

References G4endl, G4UIcommand::GetGuidanceEntries(), G4UIcommand::GetGuidanceLine(), GetPathName(), G4StateManager::GetStateManager(), G4StateManager::GetStateString(), and GetTitle().

Referenced by G4UImanager::CreateHTML().

00419 {
00420   G4String ofileName = CreateFileName(pathName);
00421   std::ofstream oF(ofileName, std::ios::out);
00422 
00423   oF << "<html><head><title>Commands in " << ModStr(pathName) << "</title></head>" << G4endl;
00424   oF << "<body bgcolor=\"#ffffff\"><h2>" << ModStr(pathName) << "</h2><p>" << G4endl;
00425 
00426   if( guidance != NULL ) 
00427   {
00428     for(G4int i=0;i<guidance->GetGuidanceEntries();i++)
00429     { oF << ModStr(guidance->GetGuidanceLine(i)) << "<br>" << G4endl; }
00430   }
00431 
00432   oF << "<p><hr><p>" << G4endl;
00433   
00434   oF << "<h2>Sub-directories : </h2><dl>" << G4endl;
00435   for( G4int i_thTree = 0; i_thTree < G4int(tree.size()); i_thTree++ )
00436   {
00437     oF << "<p><br><p><dt><a href=\"" << CreateFileName(tree[i_thTree]->GetPathName())
00438        << "\">" << ModStr(tree[i_thTree]->GetPathName()) << "</a>" << G4endl;
00439     oF << "<p><dd>" << ModStr(tree[i_thTree]->GetTitle()) << G4endl;
00440     tree[i_thTree]->CreateHTML();
00441   }
00442 
00443   oF << "</dl><p><hr><p>" << G4endl;
00444   
00445   oF << "<h2>Commands : </h2><dl>" << G4endl;
00446   for( G4int i_thCommand = 0; i_thCommand < G4int(command.size()); i_thCommand++ )
00447   {
00448     G4UIcommand* cmd = command[i_thCommand];
00449     oF << "<p><br><p><dt><b>" << ModStr(cmd->GetCommandName());
00450     if(cmd->GetParameterEntries()>0)
00451     {
00452       for(G4int i_thParam=0;i_thParam<cmd->GetParameterEntries();i_thParam++)
00453       { oF << " [<i>" << ModStr(cmd->GetParameter(i_thParam)->GetParameterName()) << "</i>]"; }
00454     }
00455     oF << "</b>" << G4endl;
00456     oF << "<p><dd>" << G4endl;
00457     for(G4int i=0;i<cmd->GetGuidanceEntries();i++)
00458     { oF << ModStr(cmd->GetGuidanceLine(i)) << "<br>" << G4endl; }
00459     if(!(cmd->GetRange()).isNull())
00460     { oF << "<p><dd>Range : " << ModStr(cmd->GetRange()) << G4endl; }
00461     std::vector<G4ApplicationState>* availabelStateList = cmd->GetStateList();
00462     if(availabelStateList->size()==6)
00463     { oF << "<p><dd>Available at all Geant4 states." << G4endl; }
00464     else
00465     {
00466       oF << "<p><dd>Available Geant4 state(s) : ";
00467       for(G4int ias=0;ias<G4int(availabelStateList->size());ias++)
00468       { oF << G4StateManager::GetStateManager()->GetStateString((*availabelStateList)[ias]) << " " << G4endl; }
00469     }
00470     if(cmd->GetParameterEntries()>0)
00471     {
00472       oF << "<p><dd>Parameters<table border=1>" << G4endl;
00473       for(G4int i_thParam=0;i_thParam<cmd->GetParameterEntries();i_thParam++)
00474       {
00475         G4UIparameter* prm = cmd->GetParameter(i_thParam);
00476         oF << "<tr><td>" << ModStr(prm->GetParameterName()) << G4endl;
00477         oF << "<td>type " << prm->GetParameterType() << G4endl;
00478         oF << "<td>";
00479         if(prm->IsOmittable())
00480         { 
00481           oF << "Omittable : ";
00482           if(prm->GetCurrentAsDefault())
00483           { oF << "current value is used as the default value." << G4endl; }
00484           else
00485           { oF << "default value = " << prm->GetDefaultValue() << G4endl; }
00486         }
00487         oF << "<td>";
00488         if(!(prm->GetParameterRange()).isNull())
00489         { oF << "Parameter range : " << ModStr(prm->GetParameterRange()) << G4endl; }
00490         else if(!(prm->GetParameterCandidates()).isNull())
00491         { oF << "Parameter candidates : " << ModStr(prm->GetParameterCandidates()) << G4endl; }
00492       }
00493       oF << "</table>" << G4endl;
00494     }
00495 
00496   }
00497   
00498   oF << "</dl></body></html>" << G4endl;
00499   oF.close();
00500 }

G4UIcommandTree * G4UIcommandTree::FindCommandTree ( const char *  commandPath  ) 

Try to match a command or a path with the one given. : command or path to match

Returns:
the commandTree found or NULL if not

Definition at line 199 of file G4UIcommandTree.cc.

References G4String::append(), G4String::first(), GetPathName(), G4String::index(), and G4String::remove().

Referenced by CompleteCommandPath().

00200 {
00201   G4String remainingPath = commandPath;
00202   if( remainingPath.index( pathName ) == std::string::npos )
00203   { return NULL; }
00204   remainingPath.remove(0,pathName.length());
00205   G4int i = remainingPath.first('/');
00206   if( i != G4int(std::string::npos) )
00207   {
00208     // Find path
00209     G4String nextPath = pathName;
00210     nextPath.append(remainingPath(0,i+1));
00211     G4int n_treeEntry = tree.size();
00212     for( G4int i_thTree = 0; i_thTree < n_treeEntry; i_thTree++ )
00213     {
00214       if (tree[i_thTree]->GetPathName() == commandPath) {
00215         return tree[i_thTree];
00216       }
00217       else if( nextPath == tree[i_thTree]->GetPathName() ) {
00218         return tree[i_thTree]->FindCommandTree( commandPath );
00219       }
00220     }
00221   } else {
00222     return this;
00223   }
00224   return NULL;
00225 }

G4UIcommand * G4UIcommandTree::FindPath ( const char *  commandPath  )  const

Definition at line 161 of file G4UIcommandTree.cc.

References G4String::append(), G4String::first(), GetPathName(), G4String::index(), and G4String::remove().

Referenced by G4UImanager::ApplyCommand(), G4CascadeParamMessenger::CreateDirectory(), G4VBasicShell::FindCommand(), G4UImanager::GetCurrentValues(), and G4VBasicShell::TerminalHelp().

00162 {
00163   G4String remainingPath = commandPath;
00164   if( remainingPath.index( pathName ) == std::string::npos )
00165   { return NULL; }
00166   remainingPath.remove(0,pathName.length());
00167   G4int i = remainingPath.first('/');
00168   if( i == G4int(std::string::npos) )
00169   {
00170     // Find command
00171     G4int n_commandEntry = command.size();
00172     for( G4int i_thCommand = 0; i_thCommand < n_commandEntry; i_thCommand++ )
00173     {
00174       if( remainingPath == command[i_thCommand]->GetCommandName() )
00175       { return command[i_thCommand]; }
00176     }
00177   }
00178   else
00179   {
00180     // Find path
00181     G4String nextPath = pathName;
00182     nextPath.append(remainingPath(0,i+1));
00183     G4int n_treeEntry = tree.size();
00184     for( G4int i_thTree = 0; i_thTree < n_treeEntry; i_thTree++ )
00185     {
00186       if( nextPath == tree[i_thTree]->GetPathName() )
00187       { return tree[i_thTree]->FindPath( commandPath ); }
00188     }
00189   }
00190   return NULL;
00191 }

G4UIcommand* G4UIcommandTree::GetCommand ( G4int  i  )  [inline]

Definition at line 98 of file G4UIcommandTree.hh.

Referenced by CompleteCommandPath(), and G4VBasicShell::TerminalHelp().

00099       { return command[i-1]; };

G4int G4UIcommandTree::GetCommandEntry (  )  const [inline]

Definition at line 84 of file G4UIcommandTree.hh.

Referenced by CompleteCommandPath().

00085       { return command.size(); };

const G4UIcommand* G4UIcommandTree::GetGuidance (  )  const [inline]

Definition at line 78 of file G4UIcommandTree.hh.

00079       { return guidance; };

const G4String G4UIcommandTree::GetPathName (  )  const [inline]

Definition at line 80 of file G4UIcommandTree.hh.

Referenced by AddNewCommand(), CompleteCommandPath(), CreateHTML(), FindCommandTree(), FindPath(), GetTree(), ListCurrent(), operator!=(), operator==(), and RemoveCommand().

00081       { return pathName; };

const G4String G4UIcommandTree::GetTitle (  )  const [inline]

Definition at line 100 of file G4UIcommandTree.hh.

References G4UIcommand::GetTitle().

Referenced by CreateHTML(), and ListCurrent().

00101       { 
00102             if(guidance==NULL)
00103             { return G4String("...Title not available..."); }
00104         else
00105             { return guidance->GetTitle(); }
00106       };

G4UIcommandTree* G4UIcommandTree::GetTree ( const char *  comNameC  )  [inline]

Definition at line 88 of file G4UIcommandTree.hh.

References GetPathName().

00089       { 
00090         G4String comName = comNameC;
00091         for( size_t i=0; i < tree.size(); i++)
00092         {
00093           if( comName == tree[i]->GetPathName() )
00094           { return tree[i]; }
00095         }
00096         return NULL;
00097       };

G4UIcommandTree* G4UIcommandTree::GetTree ( G4int  i  )  [inline]

Definition at line 86 of file G4UIcommandTree.hh.

Referenced by CompleteCommandPath(), G4VBasicShell::FindDirectory(), and G4VBasicShell::TerminalHelp().

00087       { return tree[i-1]; };

G4int G4UIcommandTree::GetTreeEntry (  )  const [inline]

Definition at line 82 of file G4UIcommandTree.hh.

Referenced by CompleteCommandPath(), RemoveCommand(), and G4VBasicShell::TerminalHelp().

00083       { return tree.size(); };

void G4UIcommandTree::List (  )  const

Definition at line 371 of file G4UIcommandTree.cc.

References ListCurrent().

Referenced by G4UImanager::ListCommands().

00372 {
00373   ListCurrent();
00374   G4int n_commandEntry = command.size();
00375   for( G4int i_thCommand = 0; i_thCommand < n_commandEntry; i_thCommand++ )
00376   {
00377     command[i_thCommand]->List();
00378   }
00379   G4int n_treeEntry = tree.size();
00380   for( G4int i_thTree = 0; i_thTree < n_treeEntry; i_thTree++ )
00381   {
00382     tree[i_thTree]->List();
00383   }
00384 }

void G4UIcommandTree::ListCurrent (  )  const

Definition at line 328 of file G4UIcommandTree.cc.

References G4cout, G4endl, GetPathName(), GetTitle(), and G4UIcommand::List().

Referenced by List(), and G4VBasicShell::ListDirectory().

00329 {
00330   G4cout << "Command directory path : " << pathName << G4endl;
00331   if( guidance != NULL ) guidance->List();
00332   G4cout << " Sub-directories : " << G4endl;
00333   G4int n_treeEntry = tree.size();
00334   for( G4int i_thTree = 0; i_thTree < n_treeEntry; i_thTree++ )
00335   {
00336     G4cout << "   " << tree[i_thTree]->GetPathName() 
00337          << "   " << tree[i_thTree]->GetTitle() << G4endl;
00338   }
00339   G4cout << " Commands : " << G4endl;
00340   G4int n_commandEntry = command.size();
00341   for( G4int i_thCommand = 0; i_thCommand < n_commandEntry; i_thCommand++ )
00342   {
00343     G4cout << "   " << command[i_thCommand]->GetCommandName() 
00344          << " * " << command[i_thCommand]->GetTitle() << G4endl;
00345   }
00346 }

void G4UIcommandTree::ListCurrentWithNum (  )  const

Definition at line 348 of file G4UIcommandTree.cc.

References G4cout, G4endl, and G4UIcommand::List().

Referenced by G4VBasicShell::TerminalHelp().

00349 {
00350   G4cout << "Command directory path : " << pathName << G4endl;
00351   if( guidance != NULL ) guidance->List();
00352   G4int i = 0;
00353   G4cout << " Sub-directories : " << G4endl;
00354   G4int n_treeEntry = tree.size();
00355   for( G4int i_thTree = 0; i_thTree < n_treeEntry; i_thTree++ )
00356   {
00357     i++;
00358     G4cout << " " << i << ") " << tree[i_thTree]->GetPathName() 
00359          << "   " << tree[i_thTree]->GetTitle() << G4endl;
00360   }
00361   G4cout << " Commands : " << G4endl;
00362   G4int n_commandEntry = command.size();
00363   for( G4int i_thCommand = 0; i_thCommand < n_commandEntry; i_thCommand++ )
00364   {
00365     i++;
00366     G4cout << " " << i << ") " << command[i_thCommand]->GetCommandName() 
00367          << " * " << command[i_thCommand]->GetTitle() << G4endl;
00368   }
00369 }

G4int G4UIcommandTree::operator!= ( const G4UIcommandTree &  right  )  const

Definition at line 58 of file G4UIcommandTree.cc.

References GetPathName().

00059 {
00060   return ( pathName != right.GetPathName() );
00061 }

G4int G4UIcommandTree::operator== ( const G4UIcommandTree &  right  )  const

Definition at line 53 of file G4UIcommandTree.cc.

References GetPathName().

00054 {
00055   return ( pathName == right.GetPathName() );
00056 }

void G4UIcommandTree::RemoveCommand ( G4UIcommand *  aCommand  ) 

Definition at line 107 of file G4UIcommandTree.cc.

References G4String::append(), G4String::first(), G4UIcommand::GetCommandPath(), GetPathName(), GetTreeEntry(), G4String::isNull(), and G4String::remove().

Referenced by G4UImanager::RemoveCommand().

00108 {
00109   G4String commandPath = aCommand->GetCommandPath();
00110   G4String remainingPath = commandPath;
00111   remainingPath.remove(0,pathName.length());
00112   if( remainingPath.isNull() )
00113   {
00114     guidance = NULL;
00115   }
00116   else
00117   {
00118     G4int i = remainingPath.first('/');
00119     if( i == G4int(std::string::npos) )
00120     {
00121       // Find command
00122       G4int n_commandEntry = command.size();
00123       for( G4int i_thCommand = 0; i_thCommand < n_commandEntry; i_thCommand++ )
00124       {
00125         if( remainingPath == command[i_thCommand]->GetCommandName() )
00126         { 
00127           command.erase(command.begin()+i_thCommand);
00128           break;
00129         }
00130       }
00131     }
00132     else
00133     {
00134       // Find path
00135       G4String nextPath = pathName;
00136       nextPath.append(remainingPath(0,i+1));
00137       G4int n_treeEntry = tree.size();
00138       for( G4int i_thTree = 0; i_thTree < n_treeEntry; i_thTree++ )
00139       {
00140         if( nextPath == tree[i_thTree]->GetPathName() )
00141         { 
00142           tree[i_thTree]->RemoveCommand( aCommand );
00143           G4int n_commandRemain = tree[i_thTree]->GetCommandEntry();
00144         G4int n_treeRemain = tree[i_thTree]-> GetTreeEntry();
00145           if(n_commandRemain == 0 && n_treeRemain == 0)
00146           {
00147             G4UIcommandTree * emptyTree = tree[i_thTree];
00148             tree.erase(tree.begin()+i_thTree);
00149             delete emptyTree;
00150           }
00151           break;
00152         }
00153       }
00154     }
00155   }
00156 }


The documentation for this class was generated from the following files:
Generated on Mon May 27 17:53:36 2013 for Geant4 by  doxygen 1.4.7