G4ModelColourMap.hh

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 // $Id$
00027 //
00028 // Generic variable->G4Colour map, where "variable" is the template
00029 // parameter.
00030 //
00031 // Jane Tinslay March 2006
00032 
00033 #ifndef G4MODELCOLOURMAP_HH
00034 #define G4MODELCOLOURMAP_HH
00035 
00036 #include "G4Colour.hh"
00037 #include "G4String.hh"
00038 #include <map>
00039 
00040 template <typename T>
00041 class G4ModelColourMap {
00042 
00043 public: // With description
00044 
00045   G4ModelColourMap();
00046 
00047   virtual ~G4ModelColourMap();
00048 
00049   // Configuration functions
00050   void Set(const T&, const G4Colour&);
00051   void Set(const T&, const G4String&);
00052   G4Colour& operator[](const T& quantity);
00053 
00054   // Access functions
00055   bool GetColour(const T&, G4Colour&) const;
00056   void Print(std::ostream& ostr) const;
00057 
00058 private:
00059 
00060   // Data member
00061   std::map<T, G4Colour> fMap;
00062 
00063 };
00064 
00065 template <typename T>
00066 G4Colour& 
00067 G4ModelColourMap<T>::operator[](const T& quantity) {return fMap[quantity];}
00068 
00069 template <typename T>
00070 G4ModelColourMap<T>::G4ModelColourMap() {}
00071 
00072 template <typename T>
00073 G4ModelColourMap<T>::~G4ModelColourMap() {}
00074 
00075 template <typename T>
00076 void
00077 G4ModelColourMap<T>::Set(const T& quantity, const G4String& colour) 
00078 {
00079   G4Colour myColour;
00080   
00081   // Will not setup the map if colour key does not exist
00082   if (!G4Colour::GetColour(colour, myColour)) {
00083     G4ExceptionDescription ed;
00084     ed << "G4Colour with key "<<colour<<" does not exist ";
00085     G4Exception
00086       ("G4ColourMap::Set(Charge charge, const G4String& colour)",
00087        "modeling0108", JustWarning, ed);
00088     return;
00089   }
00090   
00091   
00092   // Will not modify myColour if colour key does not exist
00093   Set(quantity, myColour);
00094 }
00095 
00096 template <typename T>
00097 void
00098 G4ModelColourMap<T>::Set(const T& quantity, const G4Colour& colour) 
00099 {
00100   fMap[quantity] = colour;
00101 }   
00102 
00103 template <typename T>
00104 bool
00105 G4ModelColourMap<T>::GetColour(const T& quantity, G4Colour& colour) const
00106 {
00107   typename std::map<T, G4Colour>::const_iterator iter = fMap.find(quantity);
00108 
00109   if (iter != fMap.end()) {
00110     colour = iter->second;
00111     return true;
00112   }
00113   
00114   return false;
00115 }
00116 
00117 template <typename T>
00118 void
00119 G4ModelColourMap<T>::Print(std::ostream& ostr) const
00120 {
00121   typename std::map<T, G4Colour>::const_iterator iter = fMap.begin();
00122   
00123   while (iter != fMap.end()) {
00124     ostr<< iter->first <<" : "<< iter->second <<G4endl;
00125     iter++;
00126   }
00127 }
00128 #endif

Generated on Mon May 27 17:48:52 2013 for Geant4 by  doxygen 1.4.7