Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // G4UIaliasList << 27 // 26 // 28 // Author: M.Asai, 1 October 2001 << 27 // $Id: G4UIaliasList.cc,v 1.6 2006/06/29 19:08:33 gunter Exp $ 29 // ------------------------------------------- << 28 // GEANT4 tag $Name: geant4-09-01-patch-03 $ >> 29 // 30 30 31 #include "G4UIaliasList.hh" 31 #include "G4UIaliasList.hh" 32 << 33 #include "G4ios.hh" 32 #include "G4ios.hh" 34 33 35 // ------------------------------------------- << 34 G4UIaliasList::G4UIaliasList() >> 35 { } >> 36 >> 37 G4UIaliasList::~G4UIaliasList() >> 38 { >> 39 G4int i; >> 40 G4int n_treeEntry = alias.size(); >> 41 for( i=0; i < n_treeEntry; i++ ) >> 42 { delete alias[i]; >> 43 delete value[i]; } >> 44 } >> 45 >> 46 G4int G4UIaliasList::operator==(const G4UIaliasList &right) const >> 47 { >> 48 return ( this == &right ); >> 49 } >> 50 >> 51 G4int G4UIaliasList::operator!=(const G4UIaliasList &right) const >> 52 { >> 53 return ( this != &right ); >> 54 } >> 55 36 void G4UIaliasList::AddNewAlias(const char* al 56 void G4UIaliasList::AddNewAlias(const char* aliasName, const char* aliasValue) 37 { 57 { 38 if (FindAlias(aliasName) != nullptr) { << 58 if(FindAlias(aliasName)) 39 G4cerr << "Alias <" << aliasName << "> alr << 59 { >> 60 G4cerr << "Alias <" << aliasName << "> already exist. Command ignored." >> 61 << G4endl; 40 return; 62 return; 41 } 63 } 42 aliases.emplace(aliasName, aliasValue); << 64 G4String* newAlias = new G4String(aliasName); >> 65 alias.push_back(newAlias); >> 66 G4String* newValue = new G4String(aliasValue); >> 67 value.push_back(newValue); 43 } 68 } 44 69 45 // ------------------------------------------- << 46 void G4UIaliasList::RemoveAlias(const char* al 70 void G4UIaliasList::RemoveAlias(const char* aliasName) 47 { 71 { 48 if (FindAlias(aliasName) == nullptr) { << 72 G4int i = FindAliasID(aliasName); 49 G4cerr << "Alias <" << aliasName << "> doe << 73 if(i<0) >> 74 { >> 75 G4cerr << "Alias <" << aliasName << "> does not exist. Command ignored." >> 76 << G4endl; 50 return; 77 return; 51 } 78 } 52 aliases.erase(aliasName); << 79 alias.erase(alias.begin()+i); >> 80 value.erase(value.begin()+i); 53 } 81 } 54 82 55 // ------------------------------------------- << 56 void G4UIaliasList::ChangeAlias(const char* al 83 void G4UIaliasList::ChangeAlias(const char* aliasName, const char* aliasValue) 57 { 84 { 58 if (FindAlias(aliasName) == nullptr) { << 85 G4int i = FindAliasID(aliasName); 59 AddNewAlias(aliasName, aliasValue); << 86 if(i<0) >> 87 { >> 88 AddNewAlias(aliasName,aliasValue); 60 return; 89 return; 61 } 90 } 62 aliases[aliasName] = aliasValue; << 91 *(value[i]) = aliasValue; >> 92 } >> 93 >> 94 G4String* G4UIaliasList::FindAlias(const char* aliasName) >> 95 { >> 96 G4int i = FindAliasID(aliasName); >> 97 if(i<0) >> 98 { return 0; } >> 99 return value[i]; 63 } 100 } 64 101 65 // ------------------------------------------- << 102 G4int G4UIaliasList::FindAliasID(const char* aliasName) 66 const G4String* G4UIaliasList::FindAlias(const << 67 { 103 { 68 auto it = aliases.find(aliasName); << 104 G4int i_entry = alias.size(); 69 return (it == aliases.end()) ? nullptr : &(i << 105 for(G4int i=0;i<i_entry;i++) >> 106 { if(*(alias[i])==aliasName) return i; } >> 107 return -1; 70 } 108 } 71 109 72 // ------------------------------------------- << 110 void G4UIaliasList::List() 73 void G4UIaliasList::List() const << 74 { 111 { 75 // Aliases are already sorted by std::less<G << 112 G4int i_entry = alias.size(); 76 for (const auto& [a, v] : aliases) { << 113 for(G4int i1=0;i1<i_entry-1;i1++) 77 G4cout << " " << a << " : " << v << G4end << 114 for(G4int i2=i1+1;i2<i_entry;i2++) >> 115 { >> 116 if(*(alias[i1])>*(alias[i2])) >> 117 { >> 118 G4String* tmp = alias[i1]; >> 119 alias[i1] = alias[i2]; >> 120 alias[i2] = tmp; >> 121 tmp = value[i1]; >> 122 value[i1] = value[i2]; >> 123 value[i2] = tmp; >> 124 } 78 } 125 } >> 126 >> 127 for(G4int i=0;i<i_entry;i++) >> 128 { G4cout << " " << *(alias[i]) << " : " << *(value[i]) << G4endl; } 79 } 129 } >> 130 80 131