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 26 // G4UIaliasList 27 // 27 // 28 // Author: M.Asai, 1 October 2001 28 // Author: M.Asai, 1 October 2001 29 // ------------------------------------------- 29 // -------------------------------------------------------------------- 30 30 31 #include "G4UIaliasList.hh" 31 #include "G4UIaliasList.hh" 32 << 33 #include "G4ios.hh" 32 #include "G4ios.hh" 34 33 35 // ------------------------------------------- 34 // -------------------------------------------------------------------- >> 35 G4UIaliasList::~G4UIaliasList() >> 36 { >> 37 std::size_t n_treeEntry = alias.size(); >> 38 for(std::size_t i = 0; i < n_treeEntry; ++i) >> 39 { >> 40 delete alias[i]; >> 41 delete value[i]; >> 42 } >> 43 } >> 44 >> 45 // -------------------------------------------------------------------- >> 46 G4bool G4UIaliasList::operator==(const G4UIaliasList& right) const >> 47 { >> 48 return (this == &right); >> 49 } >> 50 >> 51 // -------------------------------------------------------------------- >> 52 G4bool G4UIaliasList::operator!=(const G4UIaliasList& right) const >> 53 { >> 54 return (this != &right); >> 55 } >> 56 >> 57 // -------------------------------------------------------------------- 36 void G4UIaliasList::AddNewAlias(const char* al 58 void G4UIaliasList::AddNewAlias(const char* aliasName, const char* aliasValue) 37 { 59 { 38 if (FindAlias(aliasName) != nullptr) { << 60 if(FindAlias(aliasName) != nullptr) 39 G4cerr << "Alias <" << aliasName << "> alr << 61 { >> 62 G4cerr << "Alias <" << aliasName << "> already exists. Command ignored." >> 63 << G4endl; 40 return; 64 return; 41 } 65 } 42 aliases.emplace(aliasName, aliasValue); << 66 G4String* newAlias = new G4String(aliasName); >> 67 alias.push_back(newAlias); >> 68 G4String* newValue = new G4String(aliasValue); >> 69 value.push_back(newValue); 43 } 70 } 44 71 45 // ------------------------------------------- 72 // -------------------------------------------------------------------- 46 void G4UIaliasList::RemoveAlias(const char* al 73 void G4UIaliasList::RemoveAlias(const char* aliasName) 47 { 74 { 48 if (FindAlias(aliasName) == nullptr) { << 75 G4int i = FindAliasID(aliasName); 49 G4cerr << "Alias <" << aliasName << "> doe << 76 if(i < 0) >> 77 { >> 78 G4cerr << "Alias <" << aliasName << "> does not exist. Command ignored." >> 79 << G4endl; 50 return; 80 return; 51 } 81 } 52 aliases.erase(aliasName); << 82 alias.erase(alias.begin() + i); >> 83 value.erase(value.begin() + i); 53 } 84 } 54 85 55 // ------------------------------------------- 86 // -------------------------------------------------------------------- 56 void G4UIaliasList::ChangeAlias(const char* al 87 void G4UIaliasList::ChangeAlias(const char* aliasName, const char* aliasValue) 57 { 88 { 58 if (FindAlias(aliasName) == nullptr) { << 89 G4int i = FindAliasID(aliasName); >> 90 if(i < 0) >> 91 { 59 AddNewAlias(aliasName, aliasValue); 92 AddNewAlias(aliasName, aliasValue); 60 return; 93 return; 61 } 94 } 62 aliases[aliasName] = aliasValue; << 95 *(value[i]) = aliasValue; 63 } 96 } 64 97 65 // ------------------------------------------- 98 // -------------------------------------------------------------------- 66 const G4String* G4UIaliasList::FindAlias(const << 99 G4String* G4UIaliasList::FindAlias(const char* aliasName) 67 { 100 { 68 auto it = aliases.find(aliasName); << 101 G4int i = FindAliasID(aliasName); 69 return (it == aliases.end()) ? nullptr : &(i << 102 if(i < 0) >> 103 { >> 104 return nullptr; >> 105 } >> 106 return value[i]; 70 } 107 } 71 108 72 // ------------------------------------------- 109 // -------------------------------------------------------------------- 73 void G4UIaliasList::List() const << 110 G4int G4UIaliasList::FindAliasID(const char* aliasName) 74 { 111 { 75 // Aliases are already sorted by std::less<G << 112 std::size_t i_entry = alias.size(); 76 for (const auto& [a, v] : aliases) { << 113 for(std::size_t i = 0; i < i_entry; ++i) 77 G4cout << " " << a << " : " << v << G4end << 114 { >> 115 if(*(alias[i]) == aliasName) >> 116 { >> 117 return (G4int)i; >> 118 } >> 119 } >> 120 return -1; >> 121 } >> 122 >> 123 // -------------------------------------------------------------------- >> 124 void G4UIaliasList::List() >> 125 { >> 126 std::size_t i_entry = alias.size(); >> 127 for(std::size_t i1 = 0; i1 < i_entry - 1; ++i1) >> 128 { >> 129 for(std::size_t i2 = i1 + 1; i2 < i_entry; ++i2) >> 130 { >> 131 if(*(alias[i1]) > *(alias[i2])) >> 132 { >> 133 G4String* tmp = alias[i1]; >> 134 alias[i1] = alias[i2]; >> 135 alias[i2] = tmp; >> 136 tmp = value[i1]; >> 137 value[i1] = value[i2]; >> 138 value[i2] = tmp; >> 139 } >> 140 } >> 141 } >> 142 >> 143 for(std::size_t i = 0; i < i_entry; ++i) >> 144 { >> 145 G4cout << " " << *(alias[i]) << " : " << *(value[i]) << G4endl; 78 } 146 } 79 } 147 } 80 148