source: trunk/source/visualization/modeling/include/G4ModelColourMap.hh @ 1337

Last change on this file since 1337 was 1337, checked in by garnier, 14 years ago

tag geant4.9.4 beta 1 + modifs locales

File size: 3.9 KB
Line 
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
41template <typename T>
42class G4ModelColourMap {
43
44public: // 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
59private:
60
61  // Data member
62  std::map<T, G4Colour> fMap;
63
64};
65
66template <typename T>
67G4Colour& 
68G4ModelColourMap<T>::operator[](const T& quantity) {return fMap[quantity];}
69
70template <typename T>
71G4ModelColourMap<T>::G4ModelColourMap() {}
72
73template <typename T>
74G4ModelColourMap<T>::~G4ModelColourMap() {}
75
76template <typename T>
77void
78G4ModelColourMap<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
97template <typename T>
98void
99G4ModelColourMap<T>::Set(const T& quantity, const G4Colour& colour) 
100{
101  fMap[quantity] = colour;
102}   
103
104template <typename T>
105bool
106G4ModelColourMap<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
118template <typename T>
119void
120G4ModelColourMap<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
Note: See TracBrowser for help on using the repository browser.