Geant4-11
G4UIaliasList.cc
Go to the documentation of this file.
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// G4UIaliasList
27//
28// Author: M.Asai, 1 October 2001
29// --------------------------------------------------------------------
30
31#include "G4UIaliasList.hh"
32#include "G4ios.hh"
33
34// --------------------------------------------------------------------
36
37// --------------------------------------------------------------------
39{
40 G4int n_treeEntry = alias.size();
41 for(G4int i = 0; i < n_treeEntry; ++i)
42 {
43 delete alias[i];
44 delete value[i];
45 }
46}
47
48// --------------------------------------------------------------------
50{
51 return (this == &right);
52}
53
54// --------------------------------------------------------------------
56{
57 return (this != &right);
58}
59
60// --------------------------------------------------------------------
61void G4UIaliasList::AddNewAlias(const char* aliasName, const char* aliasValue)
62{
63 if(FindAlias(aliasName))
64 {
65 G4cerr << "Alias <" << aliasName << "> already exists. Command ignored."
66 << G4endl;
67 return;
68 }
69 G4String* newAlias = new G4String(aliasName);
70 alias.push_back(newAlias);
71 G4String* newValue = new G4String(aliasValue);
72 value.push_back(newValue);
73}
74
75// --------------------------------------------------------------------
76void G4UIaliasList::RemoveAlias(const char* aliasName)
77{
78 G4int i = FindAliasID(aliasName);
79 if(i < 0)
80 {
81 G4cerr << "Alias <" << aliasName << "> does not exist. Command ignored."
82 << G4endl;
83 return;
84 }
85 alias.erase(alias.begin() + i);
86 value.erase(value.begin() + i);
87}
88
89// --------------------------------------------------------------------
90void G4UIaliasList::ChangeAlias(const char* aliasName, const char* aliasValue)
91{
92 G4int i = FindAliasID(aliasName);
93 if(i < 0)
94 {
95 AddNewAlias(aliasName, aliasValue);
96 return;
97 }
98 *(value[i]) = aliasValue;
99}
100
101// --------------------------------------------------------------------
102G4String* G4UIaliasList::FindAlias(const char* aliasName)
103{
104 G4int i = FindAliasID(aliasName);
105 if(i < 0)
106 {
107 return 0;
108 }
109 return value[i];
110}
111
112// --------------------------------------------------------------------
113G4int G4UIaliasList::FindAliasID(const char* aliasName)
114{
115 G4int i_entry = alias.size();
116 for(G4int i = 0; i < i_entry; ++i)
117 {
118 if(*(alias[i]) == aliasName)
119 return i;
120 }
121 return -1;
122}
123
124// --------------------------------------------------------------------
126{
127 G4int i_entry = alias.size();
128 for(G4int i1 = 0; i1 < i_entry - 1; ++i1)
129 for(G4int 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 for(G4int i = 0; i < i_entry; ++i)
143 {
144 G4cout << " " << *(alias[i]) << " : " << *(value[i]) << G4endl;
145 }
146}
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
G4GLOB_DLL std::ostream G4cerr
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
G4bool operator==(const G4UIaliasList &right) const
std::vector< G4String * > alias
G4String * FindAlias(const char *aliasName)
void AddNewAlias(const char *aliasName, const char *aliasValue)
void ChangeAlias(const char *aliasName, const char *aliasValue)
void RemoveAlias(const char *aliasName)
G4bool operator!=(const G4UIaliasList &right) const
G4int FindAliasID(const char *aliasName)
std::vector< G4String * > value