Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 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// --------------------------------------------------------------------
46G4bool G4UIaliasList::operator==(const G4UIaliasList& right) const
47{
48 return (this == &right);
49}
50
51// --------------------------------------------------------------------
52G4bool G4UIaliasList::operator!=(const G4UIaliasList& right) const
53{
54 return (this != &right);
55}
56
57// --------------------------------------------------------------------
58void G4UIaliasList::AddNewAlias(const char* aliasName, const char* aliasValue)
59{
60 if(FindAlias(aliasName) != nullptr)
61 {
62 G4cerr << "Alias <" << aliasName << "> already exists. Command ignored."
63 << G4endl;
64 return;
65 }
66 G4String* newAlias = new G4String(aliasName);
67 alias.push_back(newAlias);
68 G4String* newValue = new G4String(aliasValue);
69 value.push_back(newValue);
70}
71
72// --------------------------------------------------------------------
73void G4UIaliasList::RemoveAlias(const char* aliasName)
74{
75 G4int i = FindAliasID(aliasName);
76 if(i < 0)
77 {
78 G4cerr << "Alias <" << aliasName << "> does not exist. Command ignored."
79 << G4endl;
80 return;
81 }
82 alias.erase(alias.begin() + i);
83 value.erase(value.begin() + i);
84}
85
86// --------------------------------------------------------------------
87void G4UIaliasList::ChangeAlias(const char* aliasName, const char* aliasValue)
88{
89 G4int i = FindAliasID(aliasName);
90 if(i < 0)
91 {
92 AddNewAlias(aliasName, aliasValue);
93 return;
94 }
95 *(value[i]) = aliasValue;
96}
97
98// --------------------------------------------------------------------
99G4String* G4UIaliasList::FindAlias(const char* aliasName)
100{
101 G4int i = FindAliasID(aliasName);
102 if(i < 0)
103 {
104 return nullptr;
105 }
106 return value[i];
107}
108
109// --------------------------------------------------------------------
110G4int G4UIaliasList::FindAliasID(const char* aliasName)
111{
112 std::size_t i_entry = alias.size();
113 for(std::size_t i = 0; i < i_entry; ++i)
114 {
115 if(*(alias[i]) == aliasName)
116 {
117 return (G4int)i;
118 }
119 }
120 return -1;
121}
122
123// --------------------------------------------------------------------
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;
146 }
147}
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
G4String * FindAlias(const char *aliasName)
void ChangeAlias(const char *aliasName, const char *aliasValue)
void RemoveAlias(const char *aliasName)