Skip to content

Commit

Permalink
Merge pull request #7002 from wmtan/HidePropertyMask
Browse files Browse the repository at this point in the history
Don't expose TypeWithDict property mask
  • Loading branch information
ktf committed Dec 23, 2014
2 parents 0ebcc08 + f5b7b64 commit f8a1282
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 29 deletions.
2 changes: 1 addition & 1 deletion CommonTools/Utils/src/MethodInvoker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ invoke(const edm::ObjectWithDict& o, edm::ObjectWithDict& retstore) const
// strip cv & ref flags
// FIXME: This is only true if the propery passed to the constructor
// overrides the const and reference flags.
retType = edm::TypeWithDict(retType, 0L);
retType = retType.stripConstRef();
}
ret = edm::ObjectWithDict(retType, *static_cast<void**>(addr));
//std::cout << "Now type is " << retType.qualifiedName() << std::endl;
Expand Down
2 changes: 1 addition & 1 deletion CommonTools/Utils/src/findMethod.cc
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ findMethod(const edm::TypeWithDict& t, /*class=in*/
type = theType;
}
// strip const, volatile, c++ ref, ..
type = edm::TypeWithDict(type, 0L);
type = type.stripConstRef();;
// Create our return value.
pair<edm::FunctionWithDict, bool> mem;
//FIXME: We must initialize mem.first!
Expand Down
22 changes: 15 additions & 7 deletions FWCore/Utilities/interface/TypeWithDict.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ class TypeDataMembers;
class TypeFunctionMembers;

class TypeWithDict {
friend class BaseWithDict;
friend class FunctionWithDict;
friend class MemberWithDict;
friend class TypeBases;
friend class TypeDataMembers;
friend class TypeFunctionMembers;
Expand All @@ -51,18 +54,23 @@ class TypeWithDict {
TDataType* dataType_;
long property_;
public:
static TypeWithDict byName(std::string const& name, long property = 0L);
static TypeWithDict byName(std::string const& name);
private:
static TypeWithDict byName(std::string const& name, long property);
public:
TypeWithDict();
TypeWithDict& operator=(TypeWithDict const&);
TypeWithDict(TypeWithDict const&);
// This copy constructor is for clearing const and reference.
explicit TypeWithDict(TypeWithDict const&, long property);
explicit TypeWithDict(std::type_info const&, long property = 0L);
explicit TypeWithDict(std::type_info const&);
explicit TypeWithDict(TMethodArg* arg);
private:
explicit TypeWithDict(std::type_info const&, long property);
explicit TypeWithDict(TClass* type, long property = 0L);
explicit TypeWithDict(TEnum* type, std::string const& name, long property = 0L);
explicit TypeWithDict(TMethodArg* arg, long property = 0L);
explicit TypeWithDict(TType* type, long property = 0L);
explicit TypeWithDict(TMethodArg* arg, long property);
explicit TypeWithDict(TType* type, long property);
public:
TypeWithDict& operator=(TypeWithDict const&);
TypeWithDict& stripConstRef();
explicit operator bool() const;
std::type_info const& typeInfo() const;
TClass* getClass() const;
Expand Down
56 changes: 36 additions & 20 deletions FWCore/Utilities/src/TypeWithDict.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,14 @@ namespace edm {
}

TypeWithDict
TypeWithDict::byName(std::string const& name, long property /*= 0L*/) {
TypeWithDict::byName(std::string const& name) {
// This is a public static function.
return TypeWithDict::byName(name, 0L);
}

TypeWithDict
TypeWithDict::byName(std::string const& name, long property) {
// This is a private static function.
// Note: The property flag should include kIsConstant and
// kIsReference if needed since a typeid() expression
// ignores those properties, so we must store them
Expand All @@ -64,10 +71,14 @@ namespace edm {
static std::string const constSuffix(" const");
static size_t const constPrefixSize(constPrefix.size());
static size_t const constSuffixSize(constSuffix.size());

// Handle references
if(name.back() == '&') {
property |= kIsReference;
return byName(name.substr(0, name.size() - 1), property);
}

// Handle const qualifier
if(name.size() > constSuffixSize && name.back() != '*') {
if(name.substr(0, constPrefixSize) == constPrefix) {
property |= kIsConstant;
Expand All @@ -78,19 +89,30 @@ namespace edm {
return byName(name.substr(0, name.size() - constSuffixSize), property);
}
}

TypeMap::const_iterator it = typeMap.find(name);
if (it != typeMap.end()) {
return TypeWithDict(it->second, property);
if(property == 0L) {
return it->second;
}
TypeWithDict twd = it->second;
twd.property_ = property;
return twd;
}

// Handle classes
TClass* theClass = TClass::GetClass(name.c_str());
if (theClass != nullptr && theClass->GetTypeInfo() != nullptr) {
return TypeWithDict(theClass, property);
}

// Handle enums
TEnum* theEnum = TEnum::GetEnum(name.c_str(), TEnum::kAutoload);
if(theEnum) {
return TypeWithDict(theEnum, name, property);
}

// Handle built-ins
TDataType* theDataType = gROOT->GetType(name.c_str());
if(theDataType) {
switch(theDataType->GetType()) {
Expand Down Expand Up @@ -163,22 +185,10 @@ namespace edm {
property_(rhs.property_) {
}

TypeWithDict::TypeWithDict(TypeWithDict const& type, long prop) :
ti_(type.ti_),
type_(type.type_),
class_(type.class_),
enum_(type.enum_),
dataType_(type.dataType_),
property_(type.property_) {
// Unconditionally modifies const and reference
// properties, and only those properties.
TypeWithDict&
TypeWithDict::stripConstRef() {
property_ &= ~((long) kIsConstant | (long) kIsReference);
if (prop & kIsConstant) {
property_ |= kIsConstant;
}
if (prop & kIsReference) {
property_ |= kIsReference;
}
return *this;
}

TypeWithDict&
Expand All @@ -194,6 +204,9 @@ namespace edm {
return *this;
}

TypeWithDict::TypeWithDict(std::type_info const& ti) : TypeWithDict(ti, 0L) {
}

TypeWithDict::TypeWithDict(std::type_info const& ti, long property /*= 0L*/) :
ti_(&ti),
type_(nullptr),
Expand Down Expand Up @@ -245,7 +258,10 @@ namespace edm {
property_(property) {
}

TypeWithDict::TypeWithDict(TMethodArg* arg, long property /*= 0L*/) :
TypeWithDict::TypeWithDict(TMethodArg* arg) : TypeWithDict(arg, 0L) {
}

TypeWithDict::TypeWithDict(TMethodArg* arg, long property) :
TypeWithDict(byName(arg->GetTypeName(), arg->Property() | property)) {
}

Expand Down Expand Up @@ -278,7 +294,7 @@ namespace edm {
dataType_ = TDataType::GetDataType(TDataType::GetType(*ti_));
// if(dataType_ != nullptr) {
// std::cerr << "DEBUG BY TTYPE FUNDAMENTAL: " << name() << std::endl;
//}
// }
if (!gInterpreter->Type_IsFundamental(ttype) &&
!gInterpreter->Type_IsArray(ttype) &&
!gInterpreter->Type_IsPointer(ttype) &&
Expand All @@ -288,7 +304,7 @@ namespace edm {
// if(class_ != nullptr) {
// std::cerr << "DEBUG BY TTYPE CLASS: " << name() << std::endl;
// return;
// }
// }
}
if (gInterpreter->Type_IsEnum(ttype)) {
enum_ = TEnum::GetEnum(*ti_, TEnum::kAutoload);
Expand Down

0 comments on commit f8a1282

Please sign in to comment.