File indexing completed on 2025-01-18 09:59:24
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034 #ifndef G4VISLISTMANAGER_HH
0035 #define G4VISLISTMANAGER_HH
0036
0037 #include "G4String.hh"
0038 #include <map>
0039 #include <ostream>
0040
0041 template <typename T>
0042 class G4VisListManager {
0043
0044 public:
0045
0046 G4VisListManager();
0047
0048 virtual ~G4VisListManager();
0049
0050
0051
0052 void Register(T* ptr);
0053
0054 void SetCurrent(const G4String& name);
0055
0056
0057 const T* Current() const {return fpCurrent;}
0058 const std::map<G4String, T*>& Map() const;
0059
0060
0061 void Print(std::ostream& ostr, const G4String& name="") const;
0062
0063 private:
0064
0065
0066 std::map<G4String, T*> fMap;
0067 T* fpCurrent;
0068
0069 };
0070
0071 template <typename T>
0072 G4VisListManager<T>::G4VisListManager()
0073 :fpCurrent(0)
0074 {}
0075
0076 template <typename T>
0077 G4VisListManager<T>::~G4VisListManager()
0078 {
0079 typename std::map<G4String, T*>::iterator iter = fMap.begin();
0080
0081 while (iter != fMap.end()) {
0082 delete iter->second;
0083 iter++;
0084 }
0085 }
0086
0087 template <typename T>
0088 void
0089 G4VisListManager<T>::Register(T* ptr)
0090 {
0091 assert (0 != ptr);
0092
0093
0094 fMap[ptr->Name()] = ptr;
0095 fpCurrent = ptr;
0096 }
0097
0098 template <typename T>
0099 void
0100 G4VisListManager<T>::SetCurrent(const G4String& name)
0101 {
0102 typename std::map<G4String, T*>::const_iterator iter = fMap.find(name);
0103
0104 if (iter != fMap.end()) fpCurrent = fMap[name];
0105 else {
0106 G4ExceptionDescription ed;
0107 ed << "Key \"" << name << "\" has not been registered";
0108 G4Exception
0109 ("G4VisListManager<T>::SetCurrent(T* ptr) ",
0110 "visman0102", JustWarning, ed, "Non-existent name");
0111 }
0112 }
0113
0114 template <typename T>
0115 void
0116 G4VisListManager<T>::Print(std::ostream& ostr, const G4String& name) const
0117 {
0118 if (0 == fMap.size()) {
0119 G4cout<<" None"<<std::endl;
0120 return;
0121 }
0122
0123 ostr<<" Current: "<<fpCurrent->Name()<<std::endl;
0124
0125 if (!name.empty()) {
0126
0127 typename std::map<G4String, T*>::const_iterator iter = fMap.find(name);
0128
0129 if (iter != fMap.end()) {
0130 iter->second->Print(ostr);
0131 }
0132 else {
0133 ostr<<name<<" not found "<<std::endl;
0134 }
0135 }
0136 else {
0137 typename std::map<G4String, T*>::const_iterator iter = fMap.begin();
0138 while (iter != fMap.end()) {
0139 iter->second->Print(ostr);
0140 ostr<<std::endl;
0141 iter++;
0142 }
0143 }
0144 }
0145
0146 template <typename T>
0147 const std::map<G4String, T*>&
0148 G4VisListManager<T>::Map() const
0149 {
0150 return fMap;
0151 }
0152
0153 #endif