Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:58:40

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 //
0027 // Generic variable->G4Colour map, where "variable" is the template
0028 // parameter.
0029 //
0030 // Jane Tinslay March 2006
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: // With description
0043 
0044   G4ModelColourMap();
0045 
0046   virtual ~G4ModelColourMap();
0047 
0048   // Configuration functions
0049   void Set(const T&, const G4Colour&);
0050   void Set(const T&, const G4String&);
0051   G4Colour& operator[](const T& quantity);
0052 
0053   // Access functions
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   // Data member
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   // Will not setup the map if colour key does not exist
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   // Will not modify myColour if colour key does not exist
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