RCP_ForwardDeclUnitTests.cpp

Go to the documentation of this file.
00001 #include "Teuchos_RCP.hpp"
00002 #include "Teuchos_UnitTestHarness.hpp"
00003 
00004 
00005 /*
00006  * This test checks that you can use non-owning Teuchos::RCP with pointers to
00007  * types that are only forward declared and not defined.
00008  */
00009 
00010 namespace DummyNS {class UndefinedType;}
00011 
00012 namespace Teuchos {
00013 TEUCHOS_TYPE_NAME_TRAITS_BUILTIN_TYPE_SPECIALIZATION(DummyNS::UndefinedType);
00014 } // namespace Teuchos
00015 
00016 
00017 namespace {
00018 
00019 
00020 using Teuchos::rcp;
00021 using Teuchos::rcpFromRef;
00022 using Teuchos::rcpFromUndefRef;
00023 using Teuchos::RCP;
00024 
00025 using DummyNS::UndefinedType;
00026 
00027 
00028 TEUCHOS_UNIT_TEST( RCP, ForwardDeclaredUndefined )
00029 {
00030   // This test ensures that you can declare a null RCP object to an undefined
00031   // type without trouble.
00032   RCP<UndefinedType> ut_rcp;
00033 }
00034 
00035 
00036 TEUCHOS_UNIT_TEST( RCP, ForwardDeclaredUndefined_rcp )
00037 {
00038   // This test ensures that you can set a pointer to an undefined type without
00039   // trouble.  Note that this has to be a non-owning RCP otherwise there will
00040   // be issues with the destructor call.
00041   UndefinedType *ut_ptr = 0;
00042   RCP<UndefinedType> ut_rcp =
00043 #if defined(HAS_TEUCHOS_GET_BASE_OBJ_VOID_PTR) 
00044     rcpFromUndefRef(*ut_ptr)
00045   // In this case, you have to use rcpFromUndefRef(...) in this case instead
00046   // of rcpFromRef() because the latter requires the object to be defined in
00047   // order to call dynamic_cast<const void*>(...) in order to get the base
00048   // object address needed for RCPNode tracing.
00049 #else
00050     rcpFromRef(*ut_ptr)
00051     // In this case, you can use rcpFromRef(...) because the object's baseq
00052     // address will not be looked up using dynamic_cast and no deallocator
00053     // needing to know the object's will be compiled.
00054 #endif
00055     ;
00056 }
00057 
00058 
00059 } // namespace
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Wed Apr 13 09:57:28 2011 for Teuchos Package Browser (Single Doxygen Collection) by  doxygen 1.6.3