G4UIaliasList.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id$
00028 //
00029 
00030 #include "G4UIaliasList.hh"
00031 #include "G4ios.hh"
00032 
00033 G4UIaliasList::G4UIaliasList()
00034 { }
00035 
00036 G4UIaliasList::~G4UIaliasList()
00037 {
00038   G4int i;
00039   G4int n_treeEntry = alias.size();
00040   for( i=0; i < n_treeEntry; i++ )
00041   { delete alias[i]; 
00042     delete value[i]; }
00043 }
00044 
00045 G4int G4UIaliasList::operator==(const G4UIaliasList &right) const
00046 {
00047   return ( this == &right );
00048 }
00049 
00050 G4int G4UIaliasList::operator!=(const G4UIaliasList &right) const
00051 {
00052   return ( this != &right );
00053 }
00054 
00055 void G4UIaliasList::AddNewAlias(const char* aliasName, const char* aliasValue)
00056 {
00057   if(FindAlias(aliasName))
00058   {
00059     G4cerr << "Alias <" << aliasName << "> already exist. Command ignored."
00060            << G4endl;
00061     return;
00062   }
00063   G4String* newAlias = new G4String(aliasName);
00064   alias.push_back(newAlias);
00065   G4String* newValue = new G4String(aliasValue);
00066   value.push_back(newValue);
00067 }
00068 
00069 void G4UIaliasList::RemoveAlias(const char* aliasName)
00070 {
00071   G4int i = FindAliasID(aliasName);
00072   if(i<0)
00073   {
00074     G4cerr << "Alias <" << aliasName << "> does not exist. Command ignored."
00075            << G4endl;
00076     return;
00077   }
00078   alias.erase(alias.begin()+i);
00079   value.erase(value.begin()+i);
00080 }
00081 
00082 void G4UIaliasList::ChangeAlias(const char* aliasName, const char* aliasValue)
00083 {
00084   G4int i = FindAliasID(aliasName);
00085   if(i<0)
00086   {
00087     AddNewAlias(aliasName,aliasValue);
00088     return;
00089   }
00090   *(value[i]) = aliasValue;
00091 }
00092 
00093 G4String* G4UIaliasList::FindAlias(const char* aliasName)
00094 {
00095   G4int i = FindAliasID(aliasName);
00096   if(i<0)
00097   { return 0; }
00098   return value[i];
00099 }
00100 
00101 G4int G4UIaliasList::FindAliasID(const char* aliasName)
00102 {
00103   G4int i_entry = alias.size();
00104   for(G4int i=0;i<i_entry;i++)
00105   { if(*(alias[i])==aliasName) return i; }
00106   return -1;
00107 }
00108 
00109 void G4UIaliasList::List() 
00110 {
00111   G4int i_entry = alias.size();
00112   for(G4int i1=0;i1<i_entry-1;i1++)
00113   for(G4int i2=i1+1;i2<i_entry;i2++)
00114   {
00115     if(*(alias[i1])>*(alias[i2]))
00116     {
00117       G4String* tmp = alias[i1];
00118       alias[i1] = alias[i2];
00119       alias[i2] = tmp;
00120       tmp = value[i1];
00121       value[i1] = value[i2];
00122       value[i2] = tmp;
00123     }
00124   }
00125 
00126   for(G4int i=0;i<i_entry;i++)
00127   { G4cout << "  " << *(alias[i]) << " : " << *(value[i]) << G4endl; }
00128 }
00129 

Generated on Mon May 27 17:50:05 2013 for Geant4 by  doxygen 1.4.7