Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:27:20

0001 // -*- C++ -*-
0002 //
0003 // Package:     Core
0004 // Class  :     FWTypeToRepresentations
0005 //
0006 // Implementation:
0007 //     <Notes on implementation>
0008 //
0009 // Original Author:  Chris Jones
0010 //         Created:  Tue Nov 11 14:09:01 EST 2008
0011 //
0012 
0013 // system include files
0014 
0015 // user include files
0016 #include "Fireworks/Core/interface/FWTypeToRepresentations.h"
0017 #include "Fireworks/Core/interface/FWRepresentationCheckerBase.h"
0018 
0019 //
0020 // constants, enums and typedefs
0021 //
0022 typedef std::map<std::string, std::vector<FWRepresentationInfo> > TypeToReps;
0023 
0024 //
0025 // static data member definitions
0026 //
0027 
0028 //
0029 // constructors and destructor
0030 //
0031 FWTypeToRepresentations::FWTypeToRepresentations() {}
0032 
0033 // FWTypeToRepresentations::FWTypeToRepresentations(const FWTypeToRepresentations& rhs)
0034 // {
0035 //    // do actual copying here;
0036 // }
0037 
0038 FWTypeToRepresentations::~FWTypeToRepresentations() {}
0039 
0040 //
0041 // assignment operators
0042 //
0043 // const FWTypeToRepresentations& FWTypeToRepresentations::operator=(const FWTypeToRepresentations& rhs)
0044 // {
0045 //   //An exception safe implementation is
0046 //   FWTypeToRepresentations temp(rhs);
0047 //   swap(rhs);
0048 //
0049 //   return *this;
0050 // }
0051 
0052 //
0053 // member functions
0054 //
0055 void FWTypeToRepresentations::add(std::shared_ptr<FWRepresentationCheckerBase> iChecker) {
0056   m_checkers.push_back(iChecker);
0057   if (!m_typeToReps.empty()) {
0058     //see if this works with types we already know about
0059     for (TypeToReps::iterator it = m_typeToReps.begin(), itEnd = m_typeToReps.end(); it != itEnd; ++it) {
0060       FWRepresentationInfo info = iChecker->infoFor(it->first);
0061       if (info.isValid()) {
0062         //NOTE TO SELF: should probably sort by proximity
0063         it->second.push_back(info);
0064       }
0065     }
0066   }
0067 }
0068 void FWTypeToRepresentations::insert(const FWTypeToRepresentations& iOther) {
0069   m_typeToReps.clear();
0070   for (std::vector<std::shared_ptr<FWRepresentationCheckerBase> >::const_iterator it = iOther.m_checkers.begin(),
0071                                                                                   itEnd = iOther.m_checkers.end();
0072        it != itEnd;
0073        ++it) {
0074     m_checkers.push_back(*it);
0075   }
0076 }
0077 
0078 //
0079 // const member functions
0080 //
0081 const std::vector<FWRepresentationInfo>& FWTypeToRepresentations::representationsForType(
0082     const std::string& iTypeName) const {
0083   TypeToReps::const_iterator itFound = m_typeToReps.find(iTypeName);
0084   if (itFound == m_typeToReps.end()) {
0085     std::vector<FWRepresentationInfo> reps;
0086     //check all reps
0087     for (std::vector<std::shared_ptr<FWRepresentationCheckerBase> >::const_iterator it = m_checkers.begin(),
0088                                                                                     itEnd = m_checkers.end();
0089          it != itEnd;
0090          ++it) {
0091       FWRepresentationInfo info = (*it)->infoFor(iTypeName);
0092       if (info.isValid())
0093         reps.push_back(info);
0094     }
0095 
0096     m_typeToReps.insert(std::make_pair(iTypeName, reps));
0097     itFound = m_typeToReps.find(iTypeName);
0098   }
0099 
0100   return itFound->second;
0101 }
0102 
0103 //
0104 // static member functions
0105 //