From 796f1b412cfb203d7529477322b1e8912209ca32 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Sun, 27 Sep 2009 04:18:56 +0000 Subject: [PATCH] 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 --- src/apps/debugger/dwarf/DwarfUtils.h | 31 ++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/apps/debugger/dwarf/DwarfUtils.h b/src/apps/debugger/dwarf/DwarfUtils.h index e0da2323fe..092aa75643 100644 --- a/src/apps/debugger/dwarf/DwarfUtils.h +++ b/src/apps/debugger/dwarf/DwarfUtils.h @@ -28,7 +28,38 @@ public: const char*& _directory, const char*& _file, int32& _line, int32& _column); + + template + static EntryType* GetDIEByPredicate(EntryType* entry, + const Predicate& predicate); }; +template +/*static*/ EntryType* +DwarfUtils::GetDIEByPredicate(EntryType* entry, const Predicate& predicate) +{ + if (predicate(entry)) + return entry; + + // try the abstract origin + if (EntryType* abstractOrigin = dynamic_cast( + entry->AbstractOrigin())) { + entry = abstractOrigin; + if (predicate(entry)) + return entry; + } + + // try the specification + if (EntryType* specification = dynamic_cast( + entry->Specification())) { + entry = specification; + if (predicate(entry)) + return entry; + } + + return NULL; +} + + #endif // DWARF_UTILS_H