From 638022c07f5fac6b7be38269fe2b08fca636eb62 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sat, 6 Jun 2009 04:02:08 +0200 Subject: [PATCH] WIP: add run-time type check API to Placement --- src/proc/mobject/placement.hpp | 13 ++++++++++++- .../proc/mobject/placement-hierarchy-test.cpp | 8 ++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/proc/mobject/placement.hpp b/src/proc/mobject/placement.hpp index f494d4815..282cc89c4 100644 --- a/src/proc/mobject/placement.hpp +++ b/src/proc/mobject/placement.hpp @@ -137,7 +137,18 @@ namespace mobject { { ENSURE (*this); return _SmartPtr::operator-> (); - } + } + + /** run time diagnostics: is the pointee + * of this placement compatible to the given type? + */ + template + bool + isCompatible () const + { + return 0 != dynamic_cast (get()); + } + operator string() const ; size_t use_count() const { return _SmartPtr::use_count(); } diff --git a/tests/components/proc/mobject/placement-hierarchy-test.cpp b/tests/components/proc/mobject/placement-hierarchy-test.cpp index d6fd03cab..6ca72b590 100644 --- a/tests/components/proc/mobject/placement-hierarchy-test.cpp +++ b/tests/components/proc/mobject/placement-hierarchy-test.cpp @@ -156,6 +156,14 @@ namespace test { // { // ASSERT (lumiera_error () == error::LUMIERA_ERROR_ASSERTION); // } + + // runtime type diagnostics based on pointee RTTI + ASSERT ( pSub2.isCompatible()); + ASSERT ( pSub2.isCompatible()); + ASSERT ( pSub2.isCompatible()); + ASSERT (!pSub2.isCompatible()); + ASSERT (!pSub2.isCompatible()); + ASSERT (!pSub2.isCompatible()); } };