CMS 3D CMS Logo

FWTypeToRepresentations.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Core
4 // Class : FWTypeToRepresentations
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author: Chris Jones
10 // Created: Tue Nov 11 14:09:01 EST 2008
11 //
12 
13 // system include files
14 
15 // user include files
18 
19 
20 //
21 // constants, enums and typedefs
22 //
23 typedef std::map<std::string, std::vector<FWRepresentationInfo> > TypeToReps;
24 
25 //
26 // static data member definitions
27 //
28 
29 //
30 // constructors and destructor
31 //
33 {
34 }
35 
36 // FWTypeToRepresentations::FWTypeToRepresentations(const FWTypeToRepresentations& rhs)
37 // {
38 // // do actual copying here;
39 // }
40 
42 {
43 }
44 
45 //
46 // assignment operators
47 //
48 // const FWTypeToRepresentations& FWTypeToRepresentations::operator=(const FWTypeToRepresentations& rhs)
49 // {
50 // //An exception safe implementation is
51 // FWTypeToRepresentations temp(rhs);
52 // swap(rhs);
53 //
54 // return *this;
55 // }
56 
57 //
58 // member functions
59 //
60 void
61 FWTypeToRepresentations::add( std::shared_ptr<FWRepresentationCheckerBase> iChecker)
62 {
63  m_checkers.push_back(iChecker);
64  if(!m_typeToReps.empty()) {
65  //see if this works with types we already know about
66  for(TypeToReps::iterator it = m_typeToReps.begin(), itEnd = m_typeToReps.end();
67  it != itEnd;
68  ++it) {
69  FWRepresentationInfo info = iChecker->infoFor(it->first);
70  if(info.isValid()) {
71  //NOTE TO SELF: should probably sort by proximity
72  it->second.push_back(info);
73  }
74  }
75  }
76 }
77 void
79 {
80  m_typeToReps.clear();
81  for(std::vector<std::shared_ptr<FWRepresentationCheckerBase> >::const_iterator it =iOther.m_checkers.begin(),
82  itEnd = iOther.m_checkers.end();
83  it != itEnd;
84  ++it) {
85  m_checkers.push_back(*it);
86  }
87 }
88 
89 //
90 // const member functions
91 //
92 const std::vector<FWRepresentationInfo>&
94 {
95  TypeToReps::const_iterator itFound = m_typeToReps.find(iTypeName);
96  if(itFound == m_typeToReps.end()) {
97  std::vector<FWRepresentationInfo> reps;
98  //check all reps
99  for(std::vector<std::shared_ptr<FWRepresentationCheckerBase> >::const_iterator it = m_checkers.begin(),
100  itEnd = m_checkers.end();
101  it != itEnd;
102  ++it) {
103 
104  FWRepresentationInfo info = (*it)->infoFor(iTypeName);
105  if(info.isValid())
106  reps.push_back(info);
107  }
108 
109  m_typeToReps.insert(std::make_pair(iTypeName,reps));
110  itFound = m_typeToReps.find(iTypeName);
111  }
112 
113  return itFound->second;
114 }
115 
116 //
117 // static member functions
118 //
std::vector< std::shared_ptr< FWRepresentationCheckerBase > > m_checkers
static const TGPicture * info(bool iBackgroundIsBlack)
const std::vector< FWRepresentationInfo > & representationsForType(const std::string &iTypeName) const
void insert(const FWTypeToRepresentations &)
void add(std::shared_ptr< FWRepresentationCheckerBase > iChecker)
std::map< std::string, std::vector< FWRepresentationInfo > > TypeToReps
std::map< std::string, std::vector< FWRepresentationInfo > > m_typeToReps