Teuchos Package Browser (Single Doxygen Collection) Version of the Day
RCP_ForwardDeclUnitTests.cpp
Go to the documentation of this file.
00001 /*
00002 // @HEADER
00003 // ***********************************************************************
00004 //
00005 //                    Teuchos: Common Tools Package
00006 //                 Copyright (2004) Sandia Corporation
00007 //
00008 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00009 // license for use of this work by or on behalf of the U.S. Government.
00010 //
00011 // This library is free software; you can redistribute it and/or modify
00012 // it under the terms of the GNU Lesser General Public License as
00013 // published by the Free Software Foundation; either version 2.1 of the
00014 // License, or (at your option) any later version.
00015 //
00016 // This library is distributed in the hope that it will be useful, but
00017 // WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019 // Lesser General Public License for more details.
00020 //
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License along with this library; if not, write to the Free Software
00023 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00024 // USA
00025 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
00026 //
00027 // ***********************************************************************
00028 // @HEADER
00029 */
00030 
00031 #include "Teuchos_RCP.hpp"
00032 #include "Teuchos_UnitTestHarness.hpp"
00033 
00034 
00035 /*
00036  * This test checks that you can use non-owning Teuchos::RCP with pointers to
00037  * types that are only forward declared and not defined.
00038  */
00039 
00040 namespace DummyNS {class UndefinedType;}
00041 
00042 namespace Teuchos {
00043 TEUCHOS_TYPE_NAME_TRAITS_BUILTIN_TYPE_SPECIALIZATION(DummyNS::UndefinedType);
00044 } // namespace Teuchos
00045 
00046 
00047 namespace {
00048 
00049 
00050 using Teuchos::rcp;
00051 using Teuchos::rcpFromRef;
00052 using Teuchos::rcpFromUndefRef;
00053 using Teuchos::RCP;
00054 
00055 using DummyNS::UndefinedType;
00056 
00057 
00058 TEUCHOS_UNIT_TEST( RCP, ForwardDeclaredUndefined )
00059 {
00060   // This test ensures that you can declare a null RCP object to an undefined
00061   // type without trouble.
00062   RCP<UndefinedType> ut_rcp;
00063 }
00064 
00065 
00066 TEUCHOS_UNIT_TEST( RCP, ForwardDeclaredUndefined_rcp )
00067 {
00068   // This test ensures that you can set a pointer to an undefined type without
00069   // trouble.  Note that this has to be a non-owning RCP otherwise there will
00070   // be issues with the destructor call.
00071   UndefinedType *ut_ptr = 0;
00072   RCP<UndefinedType> ut_rcp =
00073 #if defined(HAS_TEUCHOS_GET_BASE_OBJ_VOID_PTR) 
00074     rcpFromUndefRef(*ut_ptr)
00075   // In this case, you have to use rcpFromUndefRef(...) in this case instead
00076   // of rcpFromRef() because the latter requires the object to be defined in
00077   // order to call dynamic_cast<const void*>(...) in order to get the base
00078   // object address needed for RCPNode tracing.
00079 #else
00080     rcpFromRef(*ut_ptr)
00081     // In this case, you can use rcpFromRef(...) because the object's baseq
00082     // address will not be looked up using dynamic_cast and no deallocator
00083     // needing to know the object's will be compiled.
00084 #endif
00085     ;
00086 }
00087 
00088 
00089 } // namespace
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines