00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef G4VISLISTMANAGER_HH
00036 #define G4VISLISTMANAGER_HH
00037
00038 #include "G4String.hh"
00039 #include <map>
00040 #include <ostream>
00041
00042 template <typename T>
00043 class G4VisListManager {
00044
00045 public:
00046
00047 G4VisListManager();
00048
00049 virtual ~G4VisListManager();
00050
00051
00052
00053 void Register(T* ptr);
00054
00055 void SetCurrent(const G4String& name);
00056
00057
00058 const T* Current() const {return fpCurrent;}
00059 const std::map<G4String, T*>& Map() const;
00060
00061
00062 void Print(std::ostream& ostr, const G4String& name="") const;
00063
00064 private:
00065
00066
00067 std::map<G4String, T*> fMap;
00068 T* fpCurrent;
00069
00070 };
00071
00072 template <typename T>
00073 G4VisListManager<T>::G4VisListManager()
00074 :fpCurrent(0)
00075 {}
00076
00077 template <typename T>
00078 G4VisListManager<T>::~G4VisListManager()
00079 {
00080 typename std::map<G4String, T*>::iterator iter = fMap.begin();
00081
00082 while (iter != fMap.end()) {
00083 delete iter->second;
00084 iter++;
00085 }
00086 }
00087
00088 template <typename T>
00089 void
00090 G4VisListManager<T>::Register(T* ptr)
00091 {
00092 assert (0 != ptr);
00093
00094
00095 fMap[ptr->Name()] = ptr;
00096 fpCurrent = ptr;
00097 }
00098
00099 template <typename T>
00100 void
00101 G4VisListManager<T>::SetCurrent(const G4String& name)
00102 {
00103 typename std::map<G4String, T*>::const_iterator iter = fMap.find(name);
00104
00105 if (iter != fMap.end()) fpCurrent = fMap[name];
00106 else {
00107 G4ExceptionDescription ed;
00108 ed << "Key \"" << name << "\" has not been registered";
00109 G4Exception
00110 ("G4VisListManager<T>::SetCurrent(T* ptr) ",
00111 "visman0102", JustWarning, ed, "Non-existent name");
00112 }
00113 }
00114
00115 template <typename T>
00116 void
00117 G4VisListManager<T>::Print(std::ostream& ostr, const G4String& name) const
00118 {
00119 if (0 == fMap.size()) {
00120 G4cout<<" None"<<std::endl;
00121 return;
00122 }
00123
00124 ostr<<" Current: "<<fpCurrent->Name()<<std::endl;
00125
00126 if (!name.isNull()) {
00127
00128 typename std::map<G4String, T*>::const_iterator iter = fMap.find(name);
00129
00130 if (iter != fMap.end()) {
00131 iter->second->Print(ostr);
00132 }
00133 else {
00134 ostr<<name<<" not found "<<std::endl;
00135 }
00136 }
00137 else {
00138 typename std::map<G4String, T*>::const_iterator iter = fMap.begin();
00139 while (iter != fMap.end()) {
00140 iter->second->Print(ostr);
00141 ostr<<std::endl;
00142 iter++;
00143 }
00144 }
00145 }
00146
00147 template <typename T>
00148 const std::map<G4String, T*>&
00149 G4VisListManager<T>::Map() const
00150 {
00151 return fMap;
00152 }
00153
00154 #endif