Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/intercoms/src/G4UIcommandTree.cc

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /intercoms/src/G4UIcommandTree.cc (Version 11.3.0) and /intercoms/src/G4UIcommandTree.cc (Version 9.4.p3)


                                                   >>   1 //
  1 // *******************************************      2 // ********************************************************************
  2 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  3 // *                                                4 // *                                                                  *
  4 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  5 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  6 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  7 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  8 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
  9 // *                                               10 // *                                                                  *
 10 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 11 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 12 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 13 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 14 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 15 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 16 // *                                               17 // *                                                                  *
 17 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 18 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 19 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 20 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 21 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 22 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 23 // *******************************************     24 // ********************************************************************
 24 //                                                 25 //
 25 // G4UIcommandTree                             << 
 26 //                                                 26 //
 27 // Author: Makoto Asai (SLAC), 1998            <<  27 // $Id: G4UIcommandTree.cc,v 1.16 2009-11-06 06:16:07 kmura Exp $
 28 // Midified: Makoto Asai (SLAC), 2021          <<  28 // GEANT4 tag $Name: not supported by cvs2svn $
 29 //   Improve output HTML file layout and add o <<  29 //
 30 //   command/directory names in alphabetic ord << 
 31 // ------------------------------------------- << 
 32                                                    30 
 33 #include "G4UIcommandTree.hh"                      31 #include "G4UIcommandTree.hh"
 34                                                << 
 35 #include "G4StateManager.hh"                       32 #include "G4StateManager.hh"
 36 #include "G4UIdirectory.hh"                    <<  33 #include <fstream>
 37 #include "G4UImanager.hh"                      << 
 38 #include "G4ios.hh"                                34 #include "G4ios.hh"
 39                                                    35 
 40 #include <fstream>                             <<  36 G4UIcommandTree::G4UIcommandTree()
                                                   >>  37 :guidance(NULL)
                                                   >>  38 { }
 41                                                    39 
 42 // ------------------------------------------- <<  40 G4UIcommandTree::G4UIcommandTree(const char * thePathName)
 43 G4UIcommandTree::G4UIcommandTree(const char* t <<  41 :guidance(NULL)
 44 {                                                  42 {
 45   pathName = thePathName;                          43   pathName = thePathName;
 46 }                                                  44 }
 47                                                    45 
 48 // ------------------------------------------- << 
 49 G4UIcommandTree::~G4UIcommandTree()                46 G4UIcommandTree::~G4UIcommandTree()
 50 {                                                  47 {
 51   for (auto& i : tree) {                       <<  48   G4int i;
 52     delete i;                                  <<  49   G4int n_treeEntry = tree.size();
 53   }                                            <<  50   for( i=0; i < n_treeEntry; i++ )
                                                   >>  51   { delete tree[i]; }
 54 }                                                  52 }
 55                                                    53 
 56 // ------------------------------------------- <<  54 G4int G4UIcommandTree::operator==(const G4UIcommandTree &right) const
 57 G4bool G4UIcommandTree::operator==(const G4UIc << 
 58 {                                                  55 {
 59   return (pathName == right.GetPathName());    <<  56   return ( pathName == right.GetPathName() );
 60 }                                                  57 }
 61                                                    58 
 62 // ------------------------------------------- <<  59 G4int G4UIcommandTree::operator!=(const G4UIcommandTree &right) const
 63 G4bool G4UIcommandTree::operator!=(const G4UIc << 
 64 {                                                  60 {
 65   return (pathName != right.GetPathName());    <<  61   return ( pathName != right.GetPathName() );
 66 }                                                  62 }
 67                                                    63 
 68 // ------------------------------------------- <<  64 void G4UIcommandTree::AddNewCommand(G4UIcommand *newCommand)
 69 void G4UIcommandTree::AddNewCommand(G4UIcomman << 
 70 {                                                  65 {
 71   G4String commandPath = newCommand->GetComman     66   G4String commandPath = newCommand->GetCommandPath();
 72   G4String remainingPath = commandPath;            67   G4String remainingPath = commandPath;
 73   remainingPath.erase(0, pathName.length());   <<  68   remainingPath.remove(0,pathName.length());
 74   if (remainingPath.empty()) {                 <<  69   if( remainingPath.isNull() )
 75     if (guidance == nullptr) {                 <<  70   {
 76       guidance = newCommand;                   <<  71     guidance = newCommand;
 77       if (!(newCommand->ToBeBroadcasted())) {  << 
 78         broadcastCommands = false;             << 
 79       }                                        << 
 80       if (workerThreadOnly) {                  << 
 81         newCommand->SetWorkerThreadOnly();     << 
 82       }                                        << 
 83     }                                          << 
 84     return;                                        72     return;
 85   }                                                73   }
 86                                                <<  74   G4int i = remainingPath.first('/');
 87   if (guidance != nullptr) {                   <<  75   if( i == G4int(std::string::npos) )
 88     auto* dir = static_cast<G4UIdirectory*>(gu <<  76   {
 89     ifSort = dir->IfSort();                    <<  77     // Find command
 90   }                                            <<  78     G4int n_commandEntry = command.size();
 91   std::size_t i = remainingPath.find('/');     <<  79     for( G4int i_thCommand = 0; i_thCommand < n_commandEntry; i_thCommand++ )
 92   if (i == std::string::npos) {                <<  80     {
 93     // Adding a new command to this directory  <<  81       if( remainingPath == command[i_thCommand]->GetCommandName() )
 94     std::size_t n_commandEntry = command.size( <<  82       { return; }
 95     for (std::size_t i_thCommand = 0; i_thComm << 
 96       if (remainingPath == command[i_thCommand << 
 97         // a command of same name has already  << 
 98         if (G4UImanager::GetUIpointer()->GetVe << 
 99           G4ExceptionDescription ed;           << 
100           ed << "Command <" << commandPath <<  << 
101           G4Exception("G4UIcommandTree::AddNew << 
102                       // FatalException,       << 
103                       JustWarning, ed);        << 
104         }                                      << 
105         return;                                << 
106       }                                        << 
107     }                                          << 
108     if (!broadcastCommands) {                  << 
109       newCommand->SetToBeBroadcasted(false);   << 
110     }                                          << 
111     if (workerThreadOnly) {                    << 
112       newCommand->SetWorkerThreadOnly();       << 
113     }                                          << 
114     if (ifSort) {                              << 
115       auto j = command.cbegin();               << 
116       for (; j != command.cend(); ++j) {       << 
117         if (newCommand->GetCommandPath() < (*j << 
118           break;                               << 
119         }                                      << 
120       }                                        << 
121       command.insert(j, newCommand);           << 
122     }                                          << 
123     else {                                     << 
124       command.push_back(newCommand);           << 
125     }                                              83     }
                                                   >>  84     command.push_back( newCommand );
126     return;                                        85     return;
127   }                                                86   }
128                                                <<  87   else
129   // Adding a new command to a sub-directory   <<  88   {
130   G4String nextPath = pathName;                <<  89     // Find path
131   nextPath.append(remainingPath.substr(0, i +  <<  90     G4String nextPath = pathName;
132   std::size_t n_treeEntry = tree.size();       <<  91     nextPath.append(remainingPath(0,i+1));
133   for (std::size_t i_thTree = 0; i_thTree < n_ <<  92     G4int n_treeEntry = tree.size();
134     if (nextPath == tree[i_thTree]->GetPathNam <<  93     for( G4int i_thTree = 0; i_thTree < n_treeEntry; i_thTree++ )
135       if (!broadcastCommands) {                <<  94     {
136         newCommand->SetToBeBroadcasted(false); <<  95       if( nextPath == tree[i_thTree]->GetPathName() )
137       }                                        <<  96       { 
138       tree[i_thTree]->AddNewCommand(newCommand <<  97   tree[i_thTree]->AddNewCommand( newCommand );
139       return;                                  <<  98   return; 
140     }                                          << 
141   }                                            << 
142   // Creating a new sub-directory              << 
143   auto* newTree = new G4UIcommandTree(nextPath << 
144   if (ifSort) {                                << 
145     auto j = tree.cbegin();                    << 
146     for (; j != tree.cend(); ++j) {            << 
147       if (newTree->GetPathName() < (*j)->GetPa << 
148         break;                                 << 
149       }                                            99       }
150     }                                             100     }
151     tree.insert(j, newTree);                   << 101     G4UIcommandTree * newTree = new G4UIcommandTree( nextPath );
152   }                                            << 102     tree.push_back( newTree );
153   else {                                       << 103     newTree->AddNewCommand( newCommand );
154     tree.push_back(newTree);                   << 104     return;
155   }                                            << 
156   if (!broadcastCommands) {                    << 
157     newCommand->SetToBeBroadcasted(false);     << 
158   }                                               105   }
159   // In case a new sub-directry is created wit << 
160   // (most-likely this is the case), inherit t << 
161   newCommand->SetDefaultSortFlag(ifSort);      << 
162   newTree->AddNewCommand(newCommand, workerThr << 
163   return;                                      << 
164 }                                                 106 }
165                                                   107 
166 // ------------------------------------------- << 108 void G4UIcommandTree::RemoveCommand(G4UIcommand *aCommand)
167 void G4UIcommandTree::RemoveCommand(G4UIcomman << 
168 {                                                 109 {
169   if (workerThreadOnly && !(aCommand->IsWorker << 
170     return;                                    << 
171   }                                            << 
172   G4String commandPath = aCommand->GetCommandP    110   G4String commandPath = aCommand->GetCommandPath();
173   commandPath.erase(0, pathName.length());     << 111   G4String remainingPath = commandPath;
174   if (commandPath.empty()) {                   << 112   remainingPath.remove(0,pathName.length());
175     guidance = nullptr;                        << 113   if( remainingPath.isNull() )
176   }                                            << 114   {
177   else {                                       << 115     guidance = NULL;
178     std::size_t i = commandPath.find('/');     << 116   }
179     if (i == std::string::npos) {              << 117   else
                                                   >> 118   {
                                                   >> 119     G4int i = remainingPath.first('/');
                                                   >> 120     if( i == G4int(std::string::npos) )
                                                   >> 121     {
180       // Find command                             122       // Find command
181       std::size_t n_commandEntry = command.siz << 123       G4int n_commandEntry = command.size();
182       for (std::size_t i_thCommand = 0; i_thCo << 124       for( G4int i_thCommand = 0; i_thCommand < n_commandEntry; i_thCommand++ )
183         if (commandPath == command[i_thCommand << 125       {
184           command.erase(command.begin() + i_th << 126         if( remainingPath == command[i_thCommand]->GetCommandName() )
                                                   >> 127         { 
                                                   >> 128           command.erase(command.begin()+i_thCommand);
185           break;                                  129           break;
186         }                                         130         }
187       }                                           131       }
188     }                                             132     }
189     else {                                     << 133     else
                                                   >> 134     {
190       // Find path                                135       // Find path
191       G4String nextPath = pathName;               136       G4String nextPath = pathName;
192       nextPath.append(commandPath.substr(0, i  << 137       nextPath.append(remainingPath(0,i+1));
193       std::size_t n_treeEntry = tree.size();   << 138       G4int n_treeEntry = tree.size();
194       for (std::size_t i_thTree = 0; i_thTree  << 139       for( G4int i_thTree = 0; i_thTree < n_treeEntry; i_thTree++ )
195         if (nextPath == tree[i_thTree]->GetPat << 140       {
196           tree[i_thTree]->RemoveCommand(aComma << 141         if( nextPath == tree[i_thTree]->GetPathName() )
197           G4int n_commandRemain = tree[i_thTre << 142         { 
198           G4int n_treeRemain = tree[i_thTree]- << 143         tree[i_thTree]->RemoveCommand( aCommand );
199           if (n_commandRemain == 0 && n_treeRe << 144         G4int n_commandRemain = tree[i_thTree]->GetCommandEntry();
200             G4UIcommandTree* emptyTree = tree[ << 145         G4int n_treeRemain = tree[i_thTree]-> GetTreeEntry();
201             tree.erase(tree.begin() + i_thTree << 146         if(n_commandRemain == 0 && n_treeRemain == 0)
202             delete emptyTree;                  << 147         {
203           }                                    << 148           G4UIcommandTree * emptyTree = tree[i_thTree];
204           break;                               << 149           tree.erase(tree.begin()+i_thTree);
                                                   >> 150           delete emptyTree;
                                                   >> 151         }
                                                   >> 152         break;
205         }                                         153         }
206       }                                           154       }
207     }                                             155     }
208   }                                               156   }
209 }                                                 157 }
210                                                   158 
211 // ------------------------------------------- << 159 // L. Garnier 01.28.08 This function has not a good name. In fact, it try
212 G4UIcommand* G4UIcommandTree::FindPath(const c << 160 // to match a command name, not a path. It should be rename as FindCommandName
213 {                                              << 
214   // This function tries to match a command na << 
215                                                   161 
                                                   >> 162 G4UIcommand * G4UIcommandTree::FindPath(const char* commandPath)
                                                   >> 163 {
216   G4String remainingPath = commandPath;           164   G4String remainingPath = commandPath;
217   if (remainingPath.find(pathName) == std::str << 165   if( remainingPath.index( pathName ) == std::string::npos )
218     return nullptr;                            << 166   { return NULL; }
219   }                                            << 167   remainingPath.remove(0,pathName.length());
220   remainingPath.erase(0, pathName.length());   << 168   G4int i = remainingPath.first('/');
221   std::size_t i = remainingPath.find('/');     << 169   if( i == G4int(std::string::npos) )
222   if (i == std::string::npos) {                << 170   {
223     // Find command                               171     // Find command
224     std::size_t n_commandEntry = command.size( << 172     G4int n_commandEntry = command.size();
225     for (std::size_t i_thCommand = 0; i_thComm << 173     for( G4int i_thCommand = 0; i_thCommand < n_commandEntry; i_thCommand++ )
226       if (remainingPath == command[i_thCommand << 174     {
227         return command[i_thCommand];           << 175       if( remainingPath == command[i_thCommand]->GetCommandName() )
228       }                                        << 176       { return command[i_thCommand]; }
229     }                                             177     }
230   }                                               178   }
231   else {                                       << 179   else
                                                   >> 180   {
232     // Find path                                  181     // Find path
233     G4String nextPath = pathName;                 182     G4String nextPath = pathName;
234     nextPath.append(remainingPath.substr(0, i  << 183     nextPath.append(remainingPath(0,i+1));
235     std::size_t n_treeEntry = tree.size();     << 184     G4int n_treeEntry = tree.size();
236     for (std::size_t i_thTree = 0; i_thTree <  << 185     for( G4int i_thTree = 0; i_thTree < n_treeEntry; i_thTree++ )
237       if (nextPath == tree[i_thTree]->GetPathN << 186     {
238         return tree[i_thTree]->FindPath(comman << 187       if( nextPath == tree[i_thTree]->GetPathName() )
239       }                                        << 188       { return tree[i_thTree]->FindPath( commandPath ); }
240     }                                             189     }
241   }                                               190   }
242   return nullptr;                              << 191   return NULL;
243 }                                                 192 }
244                                                   193 
245 // ------------------------------------------- << 
246 G4UIcommandTree* G4UIcommandTree::FindCommandT << 
247 {                                              << 
248   // Try to match a command or a path with the << 
249   // @commandPath : command or path to match   << 
250   // @return the commandTree found or nullptr  << 
251                                                   194 
                                                   >> 195 /**
                                                   >> 196  * Try to match a command or a path with the one given.
                                                   >> 197  * @commandPath : command or path to match
                                                   >> 198  * @return the commandTree found or NULL if not
                                                   >> 199  */
                                                   >> 200 G4UIcommandTree * G4UIcommandTree::FindCommandTree(const char* commandPath)
                                                   >> 201 {
252   G4String remainingPath = commandPath;           202   G4String remainingPath = commandPath;
253   if (remainingPath.find(pathName) == std::str << 203   if( remainingPath.index( pathName ) == std::string::npos )
254     return nullptr;                            << 204   { return NULL; }
255   }                                            << 205   remainingPath.remove(0,pathName.length());
256   remainingPath.erase(0, pathName.length());   << 206   G4int i = remainingPath.first('/');
257   std::size_t i = remainingPath.find('/');     << 207   if( i != G4int(std::string::npos) )
258   if (i != std::string::npos) {                << 208   {
259     // Find path                                  209     // Find path
260     G4String nextPath = pathName;                 210     G4String nextPath = pathName;
261     nextPath.append(remainingPath.substr(0, i  << 211     nextPath.append(remainingPath(0,i+1));
262     std::size_t n_treeEntry = tree.size();     << 212     G4int n_treeEntry = tree.size();
263     for (std::size_t i_thTree = 0; i_thTree <  << 213     for( G4int i_thTree = 0; i_thTree < n_treeEntry; i_thTree++ )
                                                   >> 214     {
264       if (tree[i_thTree]->GetPathName() == com    215       if (tree[i_thTree]->GetPathName() == commandPath) {
265         return tree[i_thTree];                    216         return tree[i_thTree];
266       }                                           217       }
267       if (nextPath == tree[i_thTree]->GetPathN << 218       else if( nextPath == tree[i_thTree]->GetPathName() ) {
268         return tree[i_thTree]->FindCommandTree << 219         return tree[i_thTree]->FindCommandTree( commandPath );
269       }                                           220       }
270     }                                             221     }
271   }                                            << 222   } else {
272   else {                                       << 
273     return this;                                  223     return this;
274   }                                               224   }
275   return nullptr;                              << 225   return NULL;
276 }                                                 226 }
277                                                   227 
278 // ------------------------------------------- << 228 G4String G4UIcommandTree::CompleteCommandPath(const G4String aCommandPath)
279 G4String G4UIcommandTree::CompleteCommandPath( << 
280 {                                                 229 {
281   G4String pName = aCommandPath;               << 230   G4String pathName = aCommandPath;
282   G4String remainingPath = aCommandPath;          231   G4String remainingPath = aCommandPath;
283   G4String empty = "";                            232   G4String empty = "";
284   G4String matchingPath = empty;                  233   G4String matchingPath = empty;
285                                                   234 
286   // find the tree                                235   // find the tree
287   auto jpre = pName.rfind('/');                << 236   G4int jpre= pathName.last('/');
288   if (jpre != G4String::npos) {                << 237   if(jpre != G4int(G4String::npos)) pathName.remove(jpre+1);
289     pName.erase(jpre + 1);                     << 238   G4UIcommandTree* aTree = FindCommandTree(pathName);
290   }                                            << 
291   G4UIcommandTree* aTree = FindCommandTree(pNa << 
292                                                   239 
293   if (aTree == nullptr) {                      << 240   if (!aTree) {
294     return empty;                              << 
295   }                                            << 
296                                                << 
297   if (pName.find(pName) == std::string::npos)  << 
298     return empty;                                 241     return empty;
299   }                                               242   }
                                                   >> 243   
                                                   >> 244   if( pathName.index( pathName ) == std::string::npos ) return empty;
300                                                   245 
301   std::vector<G4String> paths;                    246   std::vector<G4String> paths;
302                                                   247 
303   // list matched directories/commands            248   // list matched directories/commands
304   G4String strtmp;                                249   G4String strtmp;
305   G4int nMatch = 0;                            << 250   G4int nMatch= 0;
306                                                << 
307   G4int Ndir = aTree->GetTreeEntry();          << 
308   G4int Ncmd = aTree->GetCommandEntry();       << 
309                                                   251 
                                                   >> 252   int Ndir= aTree-> GetTreeEntry();
                                                   >> 253   int Ncmd= aTree-> GetCommandEntry();
                                                   >> 254   
310   // directory ...                                255   // directory ...
311   for (G4int idir = 1; idir <= Ndir; ++idir) { << 256   for(G4int idir=1; idir<=Ndir; idir++) {
312     const G4String& fpdir = aTree->GetTree(idi << 257     G4String fpdir= aTree-> GetTree(idir)-> GetPathName();
313     // matching test                              258     // matching test
314     if (fpdir.find(remainingPath, 0) == 0) {   << 259     if( fpdir.index(remainingPath, 0) == 0) {
315       if (nMatch == 0) {                       << 260       if(nMatch==0) {
316         matchingPath = fpdir;                     261         matchingPath = fpdir;
                                                   >> 262       } else {
                                                   >> 263         matchingPath = GetFirstMatchedString(fpdir,matchingPath);
317       }                                           264       }
318       else {                                   << 265       nMatch++;
319         matchingPath = GetFirstMatchedString(f << 
320       }                                        << 
321       ++nMatch;                                << 
322       paths.push_back(fpdir);                     266       paths.push_back(fpdir);
323     }                                             267     }
324   }                                               268   }
325                                                << 269   
326   if (paths.size() >= 2) {                     << 270   if (paths.size()>=2) {
327     G4cout << "Matching directories :" << G4en << 271     G4cout << "Matching directories :" << G4endl; 
328     for (const auto& path : paths) {           << 272     for( unsigned int i_thCommand = 0; i_thCommand < paths.size(); i_thCommand++ ) {
329       G4cout << path << G4endl;                << 273       G4cout << paths[i_thCommand] << G4endl; 
330     }                                             274     }
331   }                                               275   }
332                                                << 276   
333   // command ...                                  277   // command ...
334   std::vector<G4String> commands;                 278   std::vector<G4String> commands;
335                                                   279 
336   for (G4int icmd = 1; icmd <= Ncmd; ++icmd) { << 280   for(G4int icmd=1; icmd<=Ncmd; icmd++){
337     G4String fpcmd = aTree->GetPathName() + aT << 281     G4String fpcmd= aTree-> GetPathName() +
                                                   >> 282                     aTree-> GetCommand(icmd) -> GetCommandName();
338     // matching test                              283     // matching test
339     if (fpcmd.find(remainingPath, 0) == 0) {   << 284     if( fpcmd.index(remainingPath, 0) ==0) {
340       if (nMatch == 0) {                       << 285       if(nMatch==0) {
341         matchingPath = fpcmd + " ";            << 286         matchingPath= fpcmd + " ";
342       }                                        << 287       } else {
343       else {                                   << 288         strtmp= fpcmd + " ";
344         strtmp = fpcmd + " ";                  << 289         matchingPath= GetFirstMatchedString(matchingPath, strtmp);
345         matchingPath = GetFirstMatchedString(m << 
346       }                                           290       }
347       nMatch++;                                   291       nMatch++;
348       commands.emplace_back(fpcmd + " ");      << 292       commands.push_back(fpcmd+" ");
349     }                                             293     }
350   }                                               294   }
351                                                   295 
352   if (commands.size() >= 2) {                  << 296   if (commands.size()>=2) {
353     G4cout << "Matching commands :" << G4endl; << 297     G4cout << "Matching commands :" << G4endl; 
354     for (const auto& matched : commands) {     << 298     for( unsigned int i_thCommand = 0; i_thCommand < commands.size(); i_thCommand++ ) {
355       G4cout << matched << G4endl;             << 299       G4cout << commands[i_thCommand] << G4endl; 
356     }                                             300     }
357   }                                               301   }
358                                                   302 
359   return matchingPath;                            303   return matchingPath;
360 }                                                 304 }
361                                                   305 
362 // ------------------------------------------- << 306 
363 G4String G4UIcommandTree::GetFirstMatchedStrin << 307 ////////////////////////////////////////////////////////////////////
                                                   >> 308 G4String G4UIcommandTree::GetFirstMatchedString(const G4String& str1, 
                                                   >> 309            const G4String& str2) const
                                                   >> 310 ////////////////////////////////////////////////////////////////////
364 {                                                 311 {
365   std::size_t nlen1 = str1.length();           << 312   int nlen1= str1.length();
366   std::size_t nlen2 = str2.length();           << 313   int nlen2= str2.length();
367                                                   314 
368   std::size_t nmin = nlen1 < nlen2 ? nlen1 : n << 315   int nmin = nlen1<nlen2 ? nlen1 : nlen2;
369                                                   316 
370   G4String strMatched;                            317   G4String strMatched;
371   for (G4int i = 0; i < (G4int)nmin; ++i) {    << 318   for(size_t i=0; G4int(i)<nmin; i++){
372     if (str1[i] == str2[i]) {                  << 319     if(str1[i]==str2[i]) {
373       strMatched += str1[i];                   << 320       strMatched+= str1[i];
374     }                                          << 321     } else {
375     else {                                     << 
376       break;                                      322       break;
377     }                                             323     }
378   }                                               324   }
379                                                   325 
380   return strMatched;                              326   return strMatched;
381 }                                                 327 }
382                                                   328 
383 // ------------------------------------------- << 329 void G4UIcommandTree::ListCurrent()
384 void G4UIcommandTree::ListCurrent() const      << 
385 {                                                 330 {
386   G4cout << "Command directory path : " << pat    331   G4cout << "Command directory path : " << pathName << G4endl;
387   if (guidance != nullptr) {                   << 332   if( guidance != NULL ) guidance->List();
388     guidance->List();                          << 
389   }                                            << 
390   G4cout << " Sub-directories : " << G4endl;      333   G4cout << " Sub-directories : " << G4endl;
391   std::size_t n_treeEntry = tree.size();       << 334   G4int n_treeEntry = tree.size();
392   for (std::size_t i_thTree = 0; i_thTree < n_ << 335   for( G4int i_thTree = 0; i_thTree < n_treeEntry; i_thTree++ )
393     G4cout << "   " << tree[i_thTree]->GetPath << 336   {
394     if ((tree[i_thTree]->GetGuidance() != null << 337     G4cout << "   " << tree[i_thTree]->GetPathName() 
395         && tree[i_thTree]->GetGuidance()->IsWo << 338    << "   " << tree[i_thTree]->GetTitle() << G4endl;
396     {                                          << 
397       G4cout << " @ ";                         << 
398     }                                          << 
399     else {                                     << 
400       G4cout << "   ";                         << 
401     }                                          << 
402     G4cout << tree[i_thTree]->GetTitle() << G4 << 
403   }                                               339   }
404   G4cout << " Commands : " << G4endl;             340   G4cout << " Commands : " << G4endl;
405   std::size_t n_commandEntry = command.size(); << 341   G4int n_commandEntry = command.size();
406   for (std::size_t i_thCommand = 0; i_thComman << 342   for( G4int i_thCommand = 0; i_thCommand < n_commandEntry; i_thCommand++ )
407     G4cout << "   " << command[i_thCommand]->G << 343   {
408     if (command[i_thCommand]->IsWorkerThreadOn << 344     G4cout << "   " << command[i_thCommand]->GetCommandName() 
409       G4cout << " @ ";                         << 345    << " * " << command[i_thCommand]->GetTitle() << G4endl;
410     }                                          << 
411     else {                                     << 
412       G4cout << " * ";                         << 
413     }                                          << 
414     G4cout << command[i_thCommand]->GetTitle() << 
415   }                                               346   }
416 }                                                 347 }
417                                                   348 
418 // ------------------------------------------- << 349 void G4UIcommandTree::ListCurrentWithNum()
419 void G4UIcommandTree::ListCurrentWithNum() con << 
420 {                                                 350 {
421   G4cout << "Command directory path : " << pat    351   G4cout << "Command directory path : " << pathName << G4endl;
422   if (guidance != nullptr) {                   << 352   if( guidance != NULL ) guidance->List();
423     guidance->List();                          << 
424   }                                            << 
425   G4int i = 0;                                    353   G4int i = 0;
426   G4cout << " Sub-directories : " << G4endl;      354   G4cout << " Sub-directories : " << G4endl;
427   std::size_t n_treeEntry = tree.size();       << 355   G4int n_treeEntry = tree.size();
428   for (std::size_t i_thTree = 0; i_thTree < n_ << 356   for( G4int i_thTree = 0; i_thTree < n_treeEntry; i_thTree++ )
429     ++i;                                       << 357   {
430     G4cout << " " << i << ") " << tree[i_thTre << 358     i++;
431            << tree[i_thTree]->GetTitle() << G4 << 359     G4cout << " " << i << ") " << tree[i_thTree]->GetPathName() 
                                                   >> 360    << "   " << tree[i_thTree]->GetTitle() << G4endl;
432   }                                               361   }
433   G4cout << " Commands : " << G4endl;             362   G4cout << " Commands : " << G4endl;
434   std::size_t n_commandEntry = command.size(); << 363   G4int n_commandEntry = command.size();
435   for (std::size_t i_thCommand = 0; i_thComman << 364   for( G4int i_thCommand = 0; i_thCommand < n_commandEntry; i_thCommand++ )
436     ++i;                                       << 365   {
437     G4cout << " " << i << ") " << command[i_th << 366     i++;
438            << command[i_thCommand]->GetTitle() << 367     G4cout << " " << i << ") " << command[i_thCommand]->GetCommandName() 
                                                   >> 368    << " * " << command[i_thCommand]->GetTitle() << G4endl;
439   }                                               369   }
440 }                                                 370 }
441                                                   371 
442 // ------------------------------------------- << 372 void G4UIcommandTree::List()
443 void G4UIcommandTree::List() const             << 
444 {                                                 373 {
445   ListCurrent();                                  374   ListCurrent();
446   std::size_t n_commandEntry = command.size(); << 375   G4int n_commandEntry = command.size();
447   for (std::size_t i_thCommand = 0; i_thComman << 376   for( G4int i_thCommand = 0; i_thCommand < n_commandEntry; i_thCommand++ )
                                                   >> 377   {
448     command[i_thCommand]->List();                 378     command[i_thCommand]->List();
449   }                                               379   }
450   std::size_t n_treeEntry = tree.size();       << 380   G4int n_treeEntry = tree.size();
451   for (std::size_t i_thTree = 0; i_thTree < n_ << 381   for( G4int i_thTree = 0; i_thTree < n_treeEntry; i_thTree++ )
                                                   >> 382   {
452     tree[i_thTree]->List();                       383     tree[i_thTree]->List();
453   }                                               384   }
454 }                                                 385 }
455                                                   386 
456 // ------------------------------------------- << 
457 G4String G4UIcommandTree::CreateFileName(const    387 G4String G4UIcommandTree::CreateFileName(const char* pName)
458 {                                                 388 {
459   G4String fn = pName;                            389   G4String fn = pName;
460   std::size_t idxs;                            << 390   G4int idxs;
461   while ((idxs = fn.find('/')) != std::string: << 391   while((idxs=fn.index("/"))!=G4int(std::string::npos))
462     fn[(G4int)idxs] = '_';                     << 392   { fn(idxs) = '_'; }
463   }                                            << 
464   fn += ".html";                                  393   fn += ".html";
465   return fn;                                      394   return fn;
466 }                                                 395 }
467                                                   396 
468 // ------------------------------------------- << 
469 G4String G4UIcommandTree::ModStr(const char* s    397 G4String G4UIcommandTree::ModStr(const char* strS)
470 {                                                 398 {
471   G4String sx;                                    399   G4String sx;
472   G4String str = strS;                            400   G4String str = strS;
473   for (G4int i = 0; i < G4int(str.length()); + << 401   for(G4int i=0;i<G4int(str.length());i++)
474     char c = str[i];                           << 402   {
475     switch (c) {                               << 403     char c = str(i);
476       case '<':                                << 404     switch(c)
477         sx += "&lt;";                          << 405     {
478         break;                                 << 406     case '<':
479       case '>':                                << 407       sx += "&lt;"; break;
480         sx += "&gt;";                          << 408     case '>':
481         break;                                 << 409       sx += "&gt;"; break;
482       case '&':                                << 410     case '&':
483         sx += "&amp;";                         << 411       sx += "&amp;"; break;
484         break;                                 << 412     default:
485       default:                                 << 413       sx += c;
486         sx += c;                               << 
487     }                                             414     }
488   }                                               415   }
489   return sx;                                      416   return sx;
490 }                                                 417 }
491                                                   418 
492 // ------------------------------------------- << 419 void G4UIcommandTree::CreateHTML()
493 void G4UIcommandTree::CreateHTML(const G4Strin << 
494 {                                                 420 {
495   G4String ofileName = CreateFileName(pathName    421   G4String ofileName = CreateFileName(pathName);
496   std::ofstream oF(ofileName, std::ios::out);     422   std::ofstream oF(ofileName, std::ios::out);
497                                                   423 
498   oF << "<html><head><title>Commands in " << M    424   oF << "<html><head><title>Commands in " << ModStr(pathName) << "</title></head>" << G4endl;
499   oF << "<style> \                             << 425   oF << "<body bgcolor=\"#ffffff\"><h2>" << ModStr(pathName) << "</h2><p>" << G4endl;
500     table,table td,table th { \                << 426 
501        border:1px solid #eee \                 << 427   if( guidance != NULL ) 
502     } \                                        << 428   {
503     table td,table th { \                      << 429     for(G4int i=0;i<guidance->GetGuidanceEntries();i++)
504       padding:5px 20px; \                      << 430     { oF << ModStr(guidance->GetGuidanceLine(i)) << "<br>" << G4endl; }
505       line-height:1.3; \                       << 431   }
506       text-align:inherit \                     << 432 
507     } \                                        << 433   oF << "<p><hr><p>" << G4endl;
508     a { \                                      << 434   
509       color:#17a81a; \                         << 435   oF << "<h2>Sub-directories : </h2><dl>" << G4endl;
510       text-decoration:none; \                  << 436   for( G4int i_thTree = 0; i_thTree < G4int(tree.size()); i_thTree++ )
511       transition-duration:0.3s \               << 437   {
512     } \                                        << 438     oF << "<p><br><p><dt><a href=\"" << CreateFileName(tree[i_thTree]->GetPathName())
513       a:hover { \                              << 439        << "\">" << ModStr(tree[i_thTree]->GetPathName()) << "</a>" << G4endl;
514       color:#17a81a \                          << 440     oF << "<p><dd>" << ModStr(tree[i_thTree]->GetTitle()) << G4endl;
515     } \                                        << 441     tree[i_thTree]->CreateHTML();
516     table { \                                  << 442   }
517       border-collapse:collapse; \              << 443 
518       border-spacing:0; \                      << 444   oF << "</dl><p><hr><p>" << G4endl;
519       margin-bottom:5px; \                     << 445   
520     } \                                        << 446   oF << "<h2>Commands : </h2><dl>" << G4endl;
521     h1 { \                                     << 447   for( G4int i_thCommand = 0; i_thCommand < G4int(command.size()); i_thCommand++ )
522       font-size:2.25em; \                      << 448   {
523       font-weight:300; \                       << 449     G4UIcommand* cmd = command[i_thCommand];
524       letter-spacing:-1px; \                   << 450     oF << "<p><br><p><dt><b>" << ModStr(cmd->GetCommandName());
525       line-height:1.15em; \                    << 451     if(cmd->GetParameterEntries()>0)
526       margin-bottom:0.5em; \                   << 452     {
527       word-wrap:break-word \                   << 453       for(G4int i_thParam=0;i_thParam<cmd->GetParameterEntries();i_thParam++)
528     } \                                        << 454       { oF << " [<i>" << ModStr(cmd->GetParameter(i_thParam)->GetParameterName()) << "</i>]"; }
529     h2 { \                                     << 455     }
530       font-size:1.5em; \                       << 456     oF << "</b>" << G4endl;
531       font-weight:300; \                       << 457     oF << "<p><dd>" << G4endl;
532       letter-spacing:-1px; \                   << 458     for(G4int i=0;i<cmd->GetGuidanceEntries();i++)
533       line-height:1.15em; \                    << 459     { oF << ModStr(cmd->GetGuidanceLine(i)) << "<br>" << G4endl; }
534       margin-bottom:0.5em; \                   << 460     if(!(cmd->GetRange()).isNull())
535       word-wrap:break-word \                   << 461     { oF << "<p><dd>Range : " << ModStr(cmd->GetRange()) << G4endl; }
536     } \                                        << 462     std::vector<G4ApplicationState>* availabelStateList = cmd->GetStateList();
537     h3 { \                                     << 463     if(availabelStateList->size()==6)
538       color:#26282a; \                         << 464     { oF << "<p><dd>Available at all Geant4 states." << G4endl; }
539       font-weight:300; \                       << 465     else
540       font-size:1.3em; \                       << 466     {
541       padding:15px 0 15px 0; \                 << 467       oF << "<p><dd>Available Geant4 state(s) : ";
542       border-bottom:2px #eee solid; \          << 468       for(G4int ias=0;ias<G4int(availabelStateList->size());ias++)
543       word-wrap:break-word \                   << 469       { oF << G4StateManager::GetStateManager()->GetStateString((*availabelStateList)[ias]) << " " << G4endl; }
544     } \                                        << 470     }
545     .sidebar { \                               << 471     if(cmd->GetParameterEntries()>0)
546       display:block; \                         << 472     {
547       position:relative; \                     << 473       oF << "<p><dd>Parameters<table border=1>" << G4endl;
548       position:sticky; \                       << 474       for(G4int i_thParam=0;i_thParam<cmd->GetParameterEntries();i_thParam++)
549       float:left; \                            << 475       {
550       -webkit-box-sizing:border-box; \         << 476         G4UIparameter* prm = cmd->GetParameter(i_thParam);
551       -moz-box-sizing:border-box; \            << 477         oF << "<tr><td>" << ModStr(prm->GetParameterName()) << G4endl;
552       -ms-box-sizing:border-box; \             << 478         oF << "<td>type " << prm->GetParameterType() << G4endl;
553       box-sizing:border-box; \                 << 479         oF << "<td>";
554       width:20%; \                             << 480         if(prm->IsOmittable())
555       padding-right:20px \                     << 481         { 
556     } \                                        << 482           oF << "Omittable : ";
557     .context { \                               << 483           if(prm->GetCurrentAsDefault())
558     width:80%; \                               << 484           { oF << "current value is used as the default value." << G4endl; }
559     display:inline-block; \                    << 485           else
560     background-color:#fff; \                   << 486           { oF << "default value = " << prm->GetDefaultValue() << G4endl; }
561     padding: 25px 35px 20px 30px; \            << 
562     -webkit-box-sizing:border-box; \           << 
563     -moz-box-sizing:border-box; \              << 
564     -ms-box-sizing:border-box; \               << 
565     box-sizing:border-box \                    << 
566   } \                                          << 
567     </style>"                                  << 
568      << G4endl;                                << 
569   oF << "<body bgcolor=\"#ffffff\">" << G4endl << 
570                                                << 
571   // Left Panel                                << 
572   if (createHTMLTreeLevel == 0) {              << 
573     oF << "<div class=\"sidebar\">" << sideBar << 
574   }                                            << 
575   // Right Panel                               << 
576   oF << "<div class=\"context\">";             << 
577   oF << "<h1>" << ModStr(pathName) << "</h1>"  << 
578                                                << 
579   if (guidance != nullptr) {                   << 
580     for (G4int i = 0; i < (G4int)guidance->Get << 
581       oF << ModStr(guidance->GetGuidanceLine(i << 
582     }                                          << 
583   }                                            << 
584   if (!tree.empty()) {                         << 
585     G4String menu = "";                        << 
586     G4String newSideBar = "";                  << 
587     menu += "<h2>Sub-directories </h2><table>" << 
588     newSideBar += "<h2><a href=\"" + ofileName << 
589     // Build menu short version                << 
590     for (auto& i_thTree : tree) {              << 
591       newSideBar += "<tr><td><a href=\"" + Cre << 
592                     + ModStr(i_thTree->GetPath << 
593     }                                          << 
594     // Build menu                              << 
595     for (auto& i_thTree : tree) {              << 
596       menu += "<tr><td><a href=\"" + CreateFil << 
597               + ModStr(i_thTree->GetPathName() << 
598       menu += "</td><td>" + ModStr(i_thTree->G << 
599     }                                          << 
600     menu += "</table>";                        << 
601     newSideBar += "</table>";                  << 
602     for (auto& i_thTree : tree) {              << 
603       createHTMLTreeLevel++;                   << 
604       i_thTree->CreateHTML(newSideBar);        << 
605       createHTMLTreeLevel--;                   << 
606     }                                          << 
607     oF << menu << G4endl;                      << 
608   }                                            << 
609                                                << 
610   if (!command.empty()) {                      << 
611     oF << "<h2>Commands </h2>" << G4endl;      << 
612                                                << 
613     // resume                                  << 
614     oF << "<table>" << G4endl;                 << 
615     for (std::size_t i_thCommand = 0; i_thComm << 
616       G4UIcommand* cmd = command[i_thCommand]; << 
617       oF << "<tr><td><a href=\"#c" << i_thComm << 
618       oF << "</a></td></tr>" << G4endl;        << 
619     }                                          << 
620     oF << "</table>" << G4endl;                << 
621     for (std::size_t i_thCommand = 0; i_thComm << 
622       G4UIcommand* cmd = command[i_thCommand]; << 
623       oF << "<h3 id=\"c" << i_thCommand << "\" << 
624       if (cmd->GetParameterEntries() > 0) {    << 
625         for (G4int i_thParam = 0; i_thParam <  << 
626           oF << " [<i>" << ModStr(cmd->GetPara << 
627         }                                      << 
628       }                                        << 
629       oF << "</h3>" << G4endl;                 << 
630       oF << "<p>" << G4endl;                   << 
631       for (G4int i = 0; i < (G4int)cmd->GetGui << 
632         oF << ModStr(cmd->GetGuidanceLine(i))  << 
633       }                                        << 
634       if (!(cmd->GetRange()).empty()) {        << 
635         oF << "<p>Range : " << ModStr(cmd->Get << 
636       }                                        << 
637       std::vector<G4ApplicationState>* availab << 
638       if (availabelStateList->size() == 6) {   << 
639         oF << "<p>Available at all Geant4 stat << 
640       }                                        << 
641       else {                                   << 
642         oF << "<p>Available Geant4 state(s) :  << 
643         for (auto& ias : *availabelStateList)  << 
644           oF << G4StateManager::GetStateManage << 
645         }                                      << 
646       }                                        << 
647       if (cmd->GetParameterEntries() > 0) {    << 
648         oF << "<p>Parameters<table border=1>"  << 
649         for (G4int i_thParam = 0; i_thParam <  << 
650           G4UIparameter* prm = cmd->GetParamet << 
651           oF << "<tr><td>" << ModStr(prm->GetP << 
652           oF << "<td>type " << prm->GetParamet << 
653           oF << "<td>";                        << 
654           if (prm->IsOmittable()) {            << 
655             oF << "Omittable : ";              << 
656             if (prm->GetCurrentAsDefault()) {  << 
657               oF << "current value is used as  << 
658             }                                  << 
659             else {                             << 
660               oF << "default value = " << prm- << 
661             }                                  << 
662           }                                    << 
663           oF << "<td>";                        << 
664           if (!(prm->GetParameterRange()).empt << 
665             oF << "Parameter range : " << ModS << 
666           }                                    << 
667           else if (!(prm->GetParameterCandidat << 
668             oF << "Parameter candidates : " << << 
669           }                                    << 
670         }                                         487         }
671         oF << "</table>" << G4endl;            << 488         oF << "<td>";
                                                   >> 489         if(!(prm->GetParameterRange()).isNull())
                                                   >> 490         { oF << "Parameter range : " << ModStr(prm->GetParameterRange()) << G4endl; }
                                                   >> 491         else if(!(prm->GetParameterCandidates()).isNull())
                                                   >> 492         { oF << "Parameter candidates : " << ModStr(prm->GetParameterCandidates()) << G4endl; }
672       }                                           493       }
                                                   >> 494       oF << "</table>" << G4endl;
673     }                                             495     }
                                                   >> 496 
674   }                                               497   }
675   oF << "</div></body></html>" << G4endl;      << 498   
                                                   >> 499   oF << "</dl></body></html>" << G4endl;
676   oF.close();                                     500   oF.close();
677 }                                                 501 }
678                                                   502 
679 // ------------------------------------------- << 
680 G4UIcommandTree* G4UIcommandTree::GetTree(cons << 
681 {                                              << 
682   G4String comName = comNameC;                 << 
683   for (auto& i : tree) {                       << 
684     if (comName == i->GetPathName()) {         << 
685       return i;                                << 
686     }                                          << 
687   }                                            << 
688   return nullptr;                              << 
689 }                                              << 
690                                                   503