Added GetDIEByPredicate() template method simplifying the task of check an

entry, its abstract origin and specification for something.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33312 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold
2009-09-27 04:18:56 +00:00
parent 569ac88d9c
commit 796f1b412c
+31
View File
@@ -28,7 +28,38 @@ public:
const char*& _directory,
const char*& _file,
int32& _line, int32& _column);
template<typename EntryType, typename Predicate>
static EntryType* GetDIEByPredicate(EntryType* entry,
const Predicate& predicate);
};
template<typename EntryType, typename Predicate>
/*static*/ EntryType*
DwarfUtils::GetDIEByPredicate(EntryType* entry, const Predicate& predicate)
{
if (predicate(entry))
return entry;
// try the abstract origin
if (EntryType* abstractOrigin = dynamic_cast<EntryType*>(
entry->AbstractOrigin())) {
entry = abstractOrigin;
if (predicate(entry))
return entry;
}
// try the specification
if (EntryType* specification = dynamic_cast<EntryType*>(
entry->Specification())) {
entry = specification;
if (predicate(entry))
return entry;
}
return NULL;
}
#endif // DWARF_UTILS_H