| 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 | // $Id: G4ModelColourMap.hh,v 1.2 2006/06/29 21:30:22 gunter Exp $
|
|---|
| 27 | // GEANT4 tag $Name: geant4-09-04-beta-01 $
|
|---|
| 28 | //
|
|---|
| 29 | // Generic variable->G4Colour map, where "variable" is the template
|
|---|
| 30 | // parameter.
|
|---|
| 31 | //
|
|---|
| 32 | // Jane Tinslay March 2006
|
|---|
| 33 |
|
|---|
| 34 | #ifndef G4MODELCOLOURMAP_HH
|
|---|
| 35 | #define G4MODELCOLOURMAP_HH
|
|---|
| 36 |
|
|---|
| 37 | #include "G4Colour.hh"
|
|---|
| 38 | #include "G4String.hh"
|
|---|
| 39 | #include <map>
|
|---|
| 40 |
|
|---|
| 41 | template <typename T>
|
|---|
| 42 | class G4ModelColourMap {
|
|---|
| 43 |
|
|---|
| 44 | public: // With description
|
|---|
| 45 |
|
|---|
| 46 | G4ModelColourMap();
|
|---|
| 47 |
|
|---|
| 48 | virtual ~G4ModelColourMap();
|
|---|
| 49 |
|
|---|
| 50 | // Configuration functions
|
|---|
| 51 | void Set(const T&, const G4Colour&);
|
|---|
| 52 | void Set(const T&, const G4String&);
|
|---|
| 53 | G4Colour& operator[](const T& quantity);
|
|---|
| 54 |
|
|---|
| 55 | // Access functions
|
|---|
| 56 | bool GetColour(const T&, G4Colour&) const;
|
|---|
| 57 | void Print(std::ostream& ostr) const;
|
|---|
| 58 |
|
|---|
| 59 | private:
|
|---|
| 60 |
|
|---|
| 61 | // Data member
|
|---|
| 62 | std::map<T, G4Colour> fMap;
|
|---|
| 63 |
|
|---|
| 64 | };
|
|---|
| 65 |
|
|---|
| 66 | template <typename T>
|
|---|
| 67 | G4Colour&
|
|---|
| 68 | G4ModelColourMap<T>::operator[](const T& quantity) {return fMap[quantity];}
|
|---|
| 69 |
|
|---|
| 70 | template <typename T>
|
|---|
| 71 | G4ModelColourMap<T>::G4ModelColourMap() {}
|
|---|
| 72 |
|
|---|
| 73 | template <typename T>
|
|---|
| 74 | G4ModelColourMap<T>::~G4ModelColourMap() {}
|
|---|
| 75 |
|
|---|
| 76 | template <typename T>
|
|---|
| 77 | void
|
|---|
| 78 | G4ModelColourMap<T>::Set(const T& quantity, const G4String& colour)
|
|---|
| 79 | {
|
|---|
| 80 | G4Colour myColour;
|
|---|
| 81 |
|
|---|
| 82 | // Will not setup the map if colour key does not exist
|
|---|
| 83 | if (!G4Colour::GetColour(colour, myColour)) {
|
|---|
| 84 | std::ostringstream o;
|
|---|
| 85 | o << "G4Colour with key "<<colour<<" does not exist ";
|
|---|
| 86 | G4Exception
|
|---|
| 87 | ("G4ColourMap::Set(Charge charge, const G4String& colour)",
|
|---|
| 88 | "NonExistentColour", JustWarning, o.str().c_str());
|
|---|
| 89 | return;
|
|---|
| 90 | }
|
|---|
| 91 |
|
|---|
| 92 |
|
|---|
| 93 | // Will not modify myColour if colour key does not exist
|
|---|
| 94 | Set(quantity, myColour);
|
|---|
| 95 | }
|
|---|
| 96 |
|
|---|
| 97 | template <typename T>
|
|---|
| 98 | void
|
|---|
| 99 | G4ModelColourMap<T>::Set(const T& quantity, const G4Colour& colour)
|
|---|
| 100 | {
|
|---|
| 101 | fMap[quantity] = colour;
|
|---|
| 102 | }
|
|---|
| 103 |
|
|---|
| 104 | template <typename T>
|
|---|
| 105 | bool
|
|---|
| 106 | G4ModelColourMap<T>::GetColour(const T& quantity, G4Colour& colour) const
|
|---|
| 107 | {
|
|---|
| 108 | typename std::map<T, G4Colour>::const_iterator iter = fMap.find(quantity);
|
|---|
| 109 |
|
|---|
| 110 | if (iter != fMap.end()) {
|
|---|
| 111 | colour = iter->second;
|
|---|
| 112 | return true;
|
|---|
| 113 | }
|
|---|
| 114 |
|
|---|
| 115 | return false;
|
|---|
| 116 | }
|
|---|
| 117 |
|
|---|
| 118 | template <typename T>
|
|---|
| 119 | void
|
|---|
| 120 | G4ModelColourMap<T>::Print(std::ostream& ostr) const
|
|---|
| 121 | {
|
|---|
| 122 | typename std::map<T, G4Colour>::const_iterator iter = fMap.begin();
|
|---|
| 123 |
|
|---|
| 124 | while (iter != fMap.end()) {
|
|---|
| 125 | ostr<< iter->first <<" : "<< iter->second <<G4endl;
|
|---|
| 126 | iter++;
|
|---|
| 127 | }
|
|---|
| 128 | }
|
|---|
| 129 | #endif
|
|---|