ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4UIaliasList.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4UIaliasList.cc
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 //
28 
29 #include "G4UIaliasList.hh"
30 #include "G4ios.hh"
31 
33 { }
34 
36 {
37  G4int i;
38  G4int n_treeEntry = alias.size();
39  for( i=0; i < n_treeEntry; i++ )
40  { delete alias[i];
41  delete value[i]; }
42 }
43 
45 {
46  return ( this == &right );
47 }
48 
50 {
51  return ( this != &right );
52 }
53 
54 void G4UIaliasList::AddNewAlias(const char* aliasName, const char* aliasValue)
55 {
56  if(FindAlias(aliasName))
57  {
58  G4cerr << "Alias <" << aliasName << "> already exist. Command ignored."
59  << G4endl;
60  return;
61  }
62  G4String* newAlias = new G4String(aliasName);
63  alias.push_back(newAlias);
64  G4String* newValue = new G4String(aliasValue);
65  value.push_back(newValue);
66 }
67 
68 void G4UIaliasList::RemoveAlias(const char* aliasName)
69 {
70  G4int i = FindAliasID(aliasName);
71  if(i<0)
72  {
73  G4cerr << "Alias <" << aliasName << "> does not exist. Command ignored."
74  << G4endl;
75  return;
76  }
77  alias.erase(alias.begin()+i);
78  value.erase(value.begin()+i);
79 }
80 
81 void G4UIaliasList::ChangeAlias(const char* aliasName, const char* aliasValue)
82 {
83  G4int i = FindAliasID(aliasName);
84  if(i<0)
85  {
86  AddNewAlias(aliasName,aliasValue);
87  return;
88  }
89  *(value[i]) = aliasValue;
90 }
91 
92 G4String* G4UIaliasList::FindAlias(const char* aliasName)
93 {
94  G4int i = FindAliasID(aliasName);
95  if(i<0)
96  { return 0; }
97  return value[i];
98 }
99 
100 G4int G4UIaliasList::FindAliasID(const char* aliasName)
101 {
102  G4int i_entry = alias.size();
103  for(G4int i=0;i<i_entry;i++)
104  { if(*(alias[i])==aliasName) return i; }
105  return -1;
106 }
107 
109 {
110  G4int i_entry = alias.size();
111  for(G4int i1=0;i1<i_entry-1;i1++)
112  for(G4int i2=i1+1;i2<i_entry;i2++)
113  {
114  if(*(alias[i1])>*(alias[i2]))
115  {
116  G4String* tmp = alias[i1];
117  alias[i1] = alias[i2];
118  alias[i2] = tmp;
119  tmp = value[i1];
120  value[i1] = value[i2];
121  value[i2] = tmp;
122  }
123  }
124 
125  for(G4int i=0;i<i_entry;i++)
126  { G4cout << " " << *(alias[i]) << " : " << *(value[i]) << G4endl; }
127 }
128