File indexing completed on 2024-04-06 12:11:42
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #include <iostream>
0015 #include "TClass.h"
0016 #include "FWCore/Reflection/interface/BaseWithDict.h"
0017
0018
0019 #include "Fireworks/Core/interface/FWSimpleRepresentationChecker.h"
0020
0021 #include "Fireworks/Core/interface/FWRepresentationInfo.h"
0022
0023 #include "Fireworks/Core/interface/FWItemAccessorFactory.h"
0024 #include "Fireworks/Core/interface/FWItemAccessorBase.h"
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037 FWSimpleRepresentationChecker::FWSimpleRepresentationChecker(const std::string& iTypeName,
0038 const std::string& iPurpose,
0039 unsigned int iBitPackedViews,
0040 bool iRepresentsSubPart,
0041 bool iRequiresFF)
0042 : FWRepresentationCheckerBase(iPurpose, iBitPackedViews, iRepresentsSubPart, iRequiresFF),
0043 m_typeidName(iTypeName) {}
0044
0045
0046
0047
0048
0049
0050 FWSimpleRepresentationChecker::~FWSimpleRepresentationChecker() {}
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071 bool FWSimpleRepresentationChecker::inheritsFrom(const edm::TypeWithDict& iChild,
0072 const std::string& iParentTypeName,
0073 unsigned int& distance) {
0074 if (iChild.getClass()) {
0075 if (iChild.getClass()->GetTypeInfo() == nullptr) {
0076 return false;
0077 }
0078 }
0079
0080 if (iChild.typeInfo().name() == iParentTypeName) {
0081 return true;
0082 }
0083 edm::TypeBases bases(iChild);
0084 if (bases.size() == 0) {
0085 return false;
0086 }
0087 ++distance;
0088 for (auto const& base : bases) {
0089 if (inheritsFrom(edm::BaseWithDict(base).typeOf(), iParentTypeName, distance)) {
0090 return true;
0091 }
0092 }
0093 --distance;
0094 return false;
0095 }
0096
0097 FWRepresentationInfo FWSimpleRepresentationChecker::infoFor(const std::string& iTypeName) const {
0098 unsigned int distance = 1;
0099
0100 FWItemAccessorFactory factory;
0101
0102 TClass* clss = TClass::GetClass(iTypeName.c_str());
0103
0104 if (nullptr == clss || nullptr == clss->GetTypeInfo()) {
0105 return FWRepresentationInfo();
0106 }
0107 std::shared_ptr<FWItemAccessorBase> accessor = factory.accessorFor(clss);
0108
0109 const TClass* modelClass = accessor->modelType();
0110
0111
0112 if (nullptr == modelClass || nullptr == modelClass->GetTypeInfo()) {
0113
0114
0115 return FWRepresentationInfo();
0116 }
0117 edm::TypeWithDict modelType(*(modelClass->GetTypeInfo()));
0118
0119
0120 if (inheritsFrom(modelType, m_typeidName, distance)) {
0121 return FWRepresentationInfo(purpose(), distance, bitPackedViews(), representsSubPart(), requiresFF());
0122 }
0123 return FWRepresentationInfo();
0124 }
0125
0126
0127
0128