File indexing completed on 2025-01-18 09:58:40
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 #ifndef G4MODELCOLOURMAP_HH
0033 #define G4MODELCOLOURMAP_HH
0034
0035 #include "G4Colour.hh"
0036 #include "G4String.hh"
0037 #include <map>
0038
0039 template <typename T>
0040 class G4ModelColourMap {
0041
0042 public:
0043
0044 G4ModelColourMap();
0045
0046 virtual ~G4ModelColourMap();
0047
0048
0049 void Set(const T&, const G4Colour&);
0050 void Set(const T&, const G4String&);
0051 G4Colour& operator[](const T& quantity);
0052
0053
0054 const std::map<T, G4Colour>& GetBasicMap() const;
0055 bool GetColour(const T&, G4Colour&) const;
0056 void Print(std::ostream& ostr) const;
0057
0058 private:
0059
0060
0061 std::map<T, G4Colour> fMap;
0062
0063 };
0064
0065 template <typename T>
0066 G4Colour&
0067 G4ModelColourMap<T>::operator[](const T& quantity) {return fMap[quantity];}
0068
0069 template <typename T>
0070 G4ModelColourMap<T>::G4ModelColourMap() {}
0071
0072 template <typename T>
0073 G4ModelColourMap<T>::~G4ModelColourMap() {}
0074
0075 template <typename T>
0076 void
0077 G4ModelColourMap<T>::Set(const T& quantity, const G4String& colour)
0078 {
0079 G4Colour myColour;
0080
0081
0082 if (!G4Colour::GetColour(colour, myColour)) {
0083 G4ExceptionDescription ed;
0084 ed << "G4Colour with key "<<colour<<" does not exist ";
0085 G4Exception
0086 ("G4ColourMap::Set(Charge charge, const G4String& colour)",
0087 "modeling0108", JustWarning, ed);
0088 return;
0089 }
0090
0091
0092
0093 Set(quantity, myColour);
0094 }
0095
0096 template <typename T>
0097 void
0098 G4ModelColourMap<T>::Set(const T& quantity, const G4Colour& colour)
0099 {
0100 fMap[quantity] = colour;
0101 }
0102
0103 template <typename T>
0104 const std::map<T, G4Colour>& G4ModelColourMap<T>::GetBasicMap() const
0105 { return fMap; }
0106
0107 template <typename T>
0108 bool
0109 G4ModelColourMap<T>::GetColour(const T& quantity, G4Colour& colour) const
0110 {
0111 typename std::map<T, G4Colour>::const_iterator iter = fMap.find(quantity);
0112
0113 if (iter != fMap.end()) {
0114 colour = iter->second;
0115 return true;
0116 }
0117
0118 return false;
0119 }
0120
0121 template <typename T>
0122 void
0123 G4ModelColourMap<T>::Print(std::ostream& ostr) const
0124 {
0125 typename std::map<T, G4Colour>::const_iterator iter = fMap.begin();
0126
0127 while (iter != fMap.end()) {
0128 ostr<< iter->first <<" : "<< iter->second <<G4endl;
0129 iter++;
0130 }
0131 }
0132 #endif