![]() |
![]() |
00001 // -*- C++ -*- 00002 // 00003 // Package: Core 00004 // Class : FWTypeToRepresentations 00005 // 00006 // Implementation: 00007 // <Notes on implementation> 00008 // 00009 // Original Author: Chris Jones 00010 // Created: Tue Nov 11 14:09:01 EST 2008 00011 // $Id: FWTypeToRepresentations.cc,v 1.2 2009/01/23 21:35:44 amraktad Exp $ 00012 // 00013 00014 // system include files 00015 00016 // user include files 00017 #include "Fireworks/Core/interface/FWTypeToRepresentations.h" 00018 #include "Fireworks/Core/interface/FWRepresentationCheckerBase.h" 00019 00020 00021 // 00022 // constants, enums and typedefs 00023 // 00024 typedef std::map<std::string, std::vector<FWRepresentationInfo> > TypeToReps; 00025 00026 // 00027 // static data member definitions 00028 // 00029 00030 // 00031 // constructors and destructor 00032 // 00033 FWTypeToRepresentations::FWTypeToRepresentations() 00034 { 00035 } 00036 00037 // FWTypeToRepresentations::FWTypeToRepresentations(const FWTypeToRepresentations& rhs) 00038 // { 00039 // // do actual copying here; 00040 // } 00041 00042 FWTypeToRepresentations::~FWTypeToRepresentations() 00043 { 00044 } 00045 00046 // 00047 // assignment operators 00048 // 00049 // const FWTypeToRepresentations& FWTypeToRepresentations::operator=(const FWTypeToRepresentations& rhs) 00050 // { 00051 // //An exception safe implementation is 00052 // FWTypeToRepresentations temp(rhs); 00053 // swap(rhs); 00054 // 00055 // return *this; 00056 // } 00057 00058 // 00059 // member functions 00060 // 00061 void 00062 FWTypeToRepresentations::add( boost::shared_ptr<FWRepresentationCheckerBase> iChecker) 00063 { 00064 m_checkers.push_back(iChecker); 00065 if(m_typeToReps.size()) { 00066 //see if this works with types we already know about 00067 for(TypeToReps::iterator it = m_typeToReps.begin(), itEnd = m_typeToReps.end(); 00068 it != itEnd; 00069 ++it) { 00070 FWRepresentationInfo info = iChecker->infoFor(it->first); 00071 if(info.isValid()) { 00072 //NOTE TO SELF: should probably sort by proximity 00073 it->second.push_back(info); 00074 } 00075 } 00076 } 00077 } 00078 void 00079 FWTypeToRepresentations::insert( const FWTypeToRepresentations& iOther) 00080 { 00081 m_typeToReps.clear(); 00082 for(std::vector<boost::shared_ptr<FWRepresentationCheckerBase> >::const_iterator it =iOther.m_checkers.begin(), 00083 itEnd = iOther.m_checkers.end(); 00084 it != itEnd; 00085 ++it) { 00086 m_checkers.push_back(*it); 00087 } 00088 } 00089 00090 // 00091 // const member functions 00092 // 00093 const std::vector<FWRepresentationInfo>& 00094 FWTypeToRepresentations::representationsForType(const std::string& iTypeName) const 00095 { 00096 TypeToReps::const_iterator itFound = m_typeToReps.find(iTypeName); 00097 if(itFound == m_typeToReps.end()) { 00098 std::vector<FWRepresentationInfo> reps; 00099 //check all reps 00100 for(std::vector<boost::shared_ptr<FWRepresentationCheckerBase> >::const_iterator it = m_checkers.begin(), 00101 itEnd = m_checkers.end(); 00102 it != itEnd; 00103 ++it) { 00104 FWRepresentationInfo info = (*it)->infoFor(iTypeName); 00105 if(info.isValid()) { 00106 reps.push_back(info); 00107 } 00108 } 00109 m_typeToReps.insert(std::make_pair(iTypeName,reps)); 00110 itFound = m_typeToReps.find(iTypeName); 00111 } 00112 00113 return itFound->second; 00114 } 00115 00116 // 00117 // static member functions 00118 //