MCPcopy Create free account
hub / github.com/Geant4/geant4 / CompleteCommandPath

Method CompleteCommandPath

source/intercoms/src/G4UIcommandTree.cc:279–360  ·  view source on GitHub ↗

--------------------------------------------------------------------

Source from the content-addressed store, hash-verified

277
278// --------------------------------------------------------------------
279G4String G4UIcommandTree::CompleteCommandPath(const G4String& aCommandPath)
280{
281 G4String pName = aCommandPath;
282 G4String remainingPath = aCommandPath;
283 G4String empty = "";
284 G4String matchingPath = empty;
285
286 // find the tree
287 auto jpre = pName.rfind('/');
288 if (jpre != G4String::npos) {
289 pName.erase(jpre + 1);
290 }
291 G4UIcommandTree* aTree = FindCommandTree(pName);
292
293 if (aTree == nullptr) {
294 return empty;
295 }
296
297 if (pName.find(pName) == std::string::npos) {
298 return empty;
299 }
300
301 std::vector<G4String> paths;
302
303 // list matched directories/commands
304 G4String strtmp;
305 G4int nMatch = 0;
306
307 G4int Ndir = aTree->GetTreeEntry();
308 G4int Ncmd = aTree->GetCommandEntry();
309
310 // directory ...
311 for (G4int idir = 1; idir <= Ndir; ++idir) {
312 const G4String& fpdir = aTree->GetTree(idir)->GetPathName();
313 // matching test
314 if (fpdir.find(remainingPath, 0) == 0) {
315 if (nMatch == 0) {
316 matchingPath = fpdir;
317 }
318 else {
319 matchingPath = GetFirstMatchedString(fpdir, matchingPath);
320 }
321 ++nMatch;
322 paths.push_back(fpdir);
323 }
324 }
325
326 if (paths.size() >= 2) {
327 G4cout << "Matching directories :" << G4endl;
328 for (const auto& path : paths) {
329 G4cout << path << G4endl;
330 }
331 }
332
333 // command ...
334 std::vector<G4String> commands;
335
336 for (G4int icmd = 1; icmd <= Ncmd; ++icmd) {

Callers 1

FindMatchingPathMethod · 0.80

Calls 8

GetTreeEntryMethod · 0.80
GetCommandEntryMethod · 0.80
emplace_backMethod · 0.80
findMethod · 0.45
GetTreeMethod · 0.45
push_backMethod · 0.45
sizeMethod · 0.45
GetCommandMethod · 0.45

Tested by

no test coverage detected