[821] | 1 | // |
---|
| 2 | // ******************************************************************** |
---|
| 3 | // * License and Disclaimer * |
---|
| 4 | // * * |
---|
| 5 | // * The Geant4 software is copyright of the Copyright Holders of * |
---|
| 6 | // * the Geant4 Collaboration. It is provided under the terms and * |
---|
| 7 | // * conditions of the Geant4 Software License, included in the file * |
---|
| 8 | // * LICENSE and available at http://cern.ch/geant4/license . These * |
---|
| 9 | // * include a list of copyright holders. * |
---|
| 10 | // * * |
---|
| 11 | // * Neither the authors of this software system, nor their employing * |
---|
| 12 | // * institutes,nor the agencies providing financial support for this * |
---|
| 13 | // * work make any representation or warranty, express or implied, * |
---|
| 14 | // * regarding this software system or assume any liability for its * |
---|
| 15 | // * use. Please see the license in the file LICENSE and URL above * |
---|
| 16 | // * for the full disclaimer and the limitation of liability. * |
---|
| 17 | // * * |
---|
| 18 | // * This code implementation is the result of the scientific and * |
---|
| 19 | // * technical work of the GEANT4 collaboration. * |
---|
| 20 | // * By using, copying, modifying or distributing the software (or * |
---|
| 21 | // * any work based on the software) you agree to acknowledge its * |
---|
| 22 | // * use in resulting scientific publications, and indicate your * |
---|
| 23 | // * acceptance of all terms of the Geant4 Software license. * |
---|
| 24 | // ******************************************************************** |
---|
| 25 | // |
---|
| 26 | // |
---|
| 27 | // $Id: G4UIaliasList.cc,v 1.6 2006/06/29 19:08:33 gunter Exp $ |
---|
[850] | 28 | // GEANT4 tag $Name: HEAD $ |
---|
[821] | 29 | // |
---|
| 30 | |
---|
| 31 | #include "G4UIaliasList.hh" |
---|
| 32 | #include "G4ios.hh" |
---|
| 33 | |
---|
| 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 | |
---|
| 56 | void G4UIaliasList::AddNewAlias(const char* aliasName, const char* aliasValue) |
---|
| 57 | { |
---|
| 58 | if(FindAlias(aliasName)) |
---|
| 59 | { |
---|
| 60 | G4cerr << "Alias <" << aliasName << "> already exist. Command ignored." |
---|
| 61 | << G4endl; |
---|
| 62 | return; |
---|
| 63 | } |
---|
| 64 | G4String* newAlias = new G4String(aliasName); |
---|
| 65 | alias.push_back(newAlias); |
---|
| 66 | G4String* newValue = new G4String(aliasValue); |
---|
| 67 | value.push_back(newValue); |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | void G4UIaliasList::RemoveAlias(const char* aliasName) |
---|
| 71 | { |
---|
| 72 | G4int i = FindAliasID(aliasName); |
---|
| 73 | if(i<0) |
---|
| 74 | { |
---|
| 75 | G4cerr << "Alias <" << aliasName << "> does not exist. Command ignored." |
---|
| 76 | << G4endl; |
---|
| 77 | return; |
---|
| 78 | } |
---|
| 79 | alias.erase(alias.begin()+i); |
---|
| 80 | value.erase(value.begin()+i); |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | void G4UIaliasList::ChangeAlias(const char* aliasName, const char* aliasValue) |
---|
| 84 | { |
---|
| 85 | G4int i = FindAliasID(aliasName); |
---|
| 86 | if(i<0) |
---|
| 87 | { |
---|
| 88 | AddNewAlias(aliasName,aliasValue); |
---|
| 89 | return; |
---|
| 90 | } |
---|
| 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]; |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | G4int G4UIaliasList::FindAliasID(const char* aliasName) |
---|
| 103 | { |
---|
| 104 | G4int i_entry = alias.size(); |
---|
| 105 | for(G4int i=0;i<i_entry;i++) |
---|
| 106 | { if(*(alias[i])==aliasName) return i; } |
---|
| 107 | return -1; |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | void G4UIaliasList::List() |
---|
| 111 | { |
---|
| 112 | G4int i_entry = alias.size(); |
---|
| 113 | for(G4int i1=0;i1<i_entry-1;i1++) |
---|
| 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 | } |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | for(G4int i=0;i<i_entry;i++) |
---|
| 128 | { G4cout << " " << *(alias[i]) << " : " << *(value[i]) << G4endl; } |
---|
| 129 | } |
---|
| 130 | |
---|