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

Method SolveAlias

source/intercoms/src/G4UImanager.cc:404–451  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

402
403// --------------------------------------------------------------------
404G4String G4UImanager::SolveAlias(const char* aCmd)
405{
406 G4String aCommand = aCmd;
407 std::size_t ia = aCommand.find('{');
408 std::size_t iz = aCommand.find('#');
409 while ((ia != std::string::npos) && ((iz == std::string::npos) || (ia < iz))) {
410 G4int ibx = -1;
411 while (ibx < 0) {
412 std::size_t ib = aCommand.find('}');
413 if (ib == std::string::npos) {
414 G4cerr << aCommand << G4endl;
415 for (std::size_t i = 0; i < ia; ++i) {
416 G4cerr << " ";
417 }
418 G4cerr << "^" << G4endl;
419 G4cerr << "Unmatched alias parenthesis -- command ignored" << G4endl;
420 G4String nullStr;
421 return nullStr;
422 }
423 G4String ps = aCommand.substr(ia + 1, aCommand.length() - (ia + 1));
424 std::size_t ic = ps.find('{');
425 std::size_t id = ps.find('}');
426 if (ic != std::string::npos && ic < id) {
427 ia += ic + 1;
428 }
429 else {
430 ibx = (G4int)ib;
431 }
432 }
433 //--- Here ia represents the position of innermost "{"
434 //--- and ibx represents corresponding "}"
435 G4String subs;
436 if (ia > 0) {
437 subs = aCommand.substr(0, ia);
438 }
439 G4String alis = aCommand.substr(ia + 1, ibx - ia - 1);
440 G4String rems = aCommand.substr(ibx + 1, aCommand.length() - ibx);
441 const G4String* alVal = aliasList->FindAlias(alis);
442 if (alVal == nullptr) {
443 G4cerr << "Alias <" << alis << "> not found -- command ignored" << G4endl;
444 G4String nullStr;
445 return nullStr;
446 }
447 aCommand = subs + (*alVal) + rems;
448 ia = aCommand.find('{');
449 }
450 return aCommand;
451}
452
453// --------------------------------------------------------------------
454G4int G4UImanager::ApplyCommand(const G4String& aCmd)

Callers 3

ExecuteCommandMethod · 0.80
SetNewValueMethod · 0.80
ExecCommandMethod · 0.80

Calls 4

substrMethod · 0.80
FindAliasMethod · 0.80
findMethod · 0.45
lengthMethod · 0.45

Tested by

no test coverage detected