19 #ifdef HAVE_TEUCHOS_BOOST 
   35 #define SHOW_RUN_TIME_ERROR_VIRTUAL_BASE_CLASS 
   36 #define SHOW_RUN_TIME_ERROR_VIRTUAL_BASE_CLASS_PRINT 
   43 int main( 
int argc, 
char* argv[] ) {
 
   47   using Teuchos::deallocFunctorDelete;
 
   48   using Teuchos::deallocFunctorHandleDelete;
 
   51   using Teuchos::rcpFromRef;
 
   52   using Teuchos::inOutArg;
 
   54   using Teuchos::rcp_implicit_cast;
 
   55   using Teuchos::rcp_const_cast;
 
   56   using Teuchos::rcp_static_cast;
 
   57   using Teuchos::rcp_dynamic_cast;
 
   58   using Teuchos::set_extra_data;
 
   59   using Teuchos::get_extra_data;
 
   60   using Teuchos::get_nonconst_extra_data;
 
   61   using Teuchos::get_optional_extra_data;
 
   62   using Teuchos::get_optional_nonconst_extra_data;
 
   63   using Teuchos::get_dealloc;
 
   64   using Teuchos::get_nonconst_dealloc;
 
   65   using Teuchos::get_optional_dealloc;
 
   66   using Teuchos::get_optional_nonconst_dealloc;
 
   67   using Teuchos::rcpWithEmbeddedObj;
 
   68   using Teuchos::rcpWithEmbeddedObjPreDestroy;
 
   69   using Teuchos::rcpWithEmbeddedObjPostDestroy;
 
   70   using Teuchos::getEmbeddedObj;
 
   71   using Teuchos::getNonconstEmbeddedObj;
 
   76   bool createCircRefs = 
false; 
 
   82   std::ostream &out = ( procRank == 0 ? std::cout : blackhole );
 
   87     CommandLineProcessor clp(
false); 
 
   88     clp.setOption( 
"create-circ-refs", 
"no-create-circ-refs", &createCircRefs,
 
   89       "Set if output is printed or not." );
 
   90     CommandLineProcessor::EParseCommandLineReturn parse_return = clp.parse(argc,argv);
 
   91     if( parse_return != CommandLineProcessor::PARSE_SUCCESSFUL ) {
 
   92       out << 
"\nEnd Result: TEST FAILED" << std::endl;
 
   96     blackhole << 
"\nThis should not print anywhere.\n";
 
  100     out << 
"\nTesting basic RCP functionality ...\n";
 
  104     RCP<A> a_ptr1 = 
rcp(
new C);
 
  105     out << 
"\na_ptr1 = " << a_ptr1 << 
"\n";
 
  122     RCP<D> d_ptr1 = 
rcp(
new E);
 
  144 #ifdef SHOW_RUN_TIME_ERROR_1 
  147       const RCP<A> a_ptr2 = a_ptr1.get();
 
  154 #ifdef SHOW_COMPILE_TIME_ERRORS 
  221 #ifdef SHOW_COMPILE_TIME_ERRORS 
  226 #ifndef _INTEL // Intel compiler does not seem to be doing dynamic cast correctly? 
  227 #ifdef TEUCHOS_DEBUG // operator->() only throws std::exception when TEUCHOS_DEBUG is defined 
  237       catch( 
const std::logic_error &excpt )
 
  248       catch( 
const std::bad_cast &excpt )
 
  254       delete d_ptr1.release().get(); 
 
  256 #ifdef SHOW_RUN_TIME_ERROR_2 
  260 #ifdef SHOW_MEMORY_LEAK_1 
  273     a_ptr1 = 
rcp(
new B1); 
 
  274     a_ptr1 = 
rcp(
new B2); 
 
  287 #ifndef SHOW_RUN_TIME_ERROR_3 
  294 #ifndef SHOW_RUN_TIME_ERROR_4 
  299 #ifdef SHOW_RUN_TIME_ERROR_VIRTUAL_BASE_CLASS 
  303 #ifdef SHOW_RUN_TIME_ERROR_VIRTUAL_BASE_CLASS_PRINT 
  304     const void *c_ptr5_base = 
dynamic_cast<void*
>(c_ptr5);
 
  305     out << 
"\nSize of C = " << 
sizeof(
C) << std::endl;
 
  306     out << 
"Base address of object of type C = " << 
dynamic_cast<void*
>(c_ptr5) << std::endl;
 
  307     out << 
"Offset to address of object of type C = " << ((
long int)c_ptr5 - (
long int)c_ptr5_base) << std::endl;
 
  308     out << 
"Offset of B1 object in object of type C = " << ((
long int)static_cast<B1*>(c_ptr5) - (
long int)c_ptr5_base) << std::endl;
 
  309     out << 
"Offset of B2 object in object of type C = " << ((
long int)static_cast<B2*>(c_ptr5) - (
long int)c_ptr5_base) << std::endl;
 
  310     out << 
"Offset of A object in object of type C = " << ((
long int)static_cast<A*>(c_ptr5) - (
long int)c_ptr5_base) << std::endl;
 
  311 #endif // SHOW_RUN_TIME_ERROR_VIRTUAL_BASE_CLASS_PRINT 
  313     a_ptr1 = 
rcp(a_rptr5); 
 
  315 #endif // SHOW_RUN_TIME_ERROR_VIRTUAL_BASE_CLASS 
  319     get_dealloc<DeallocDelete<C> >(a_ptr1);
 
  320     get_nonconst_dealloc<DeallocDelete<C> >(a_ptr1);
 
  345       const int intRtn1 = getEmbeddedObj<C,int>(a_ptr);
 
  347       getNonconstEmbeddedObj<C,int>(a_ptr) = -4;
 
  348       const int intRtn2 = getEmbeddedObj<C,int>(a_ptr);
 
  354       const int intRtn1 = getEmbeddedObj<C,int>(a_ptr);
 
  356       getNonconstEmbeddedObj<C,int>(a_ptr) = -4;
 
  357       const int intRtn2 = getEmbeddedObj<C,int>(a_ptr);
 
  363       const int intRtn1 = getEmbeddedObj<C,int>(a_ptr);
 
  365       getNonconstEmbeddedObj<C,int>(a_ptr) = -4;
 
  366       const int intRtn2 = getEmbeddedObj<C,int>(a_ptr);
 
  394     if (createCircRefs) {
 
  395       out << 
"\nCreate a circular reference that will cause a memory leak! ...\n";
 
  396 #  if !defined(HAVE_TEUCHOS_DEBUG_RCP_NODE_TRACING) 
  398       Teuchos::RCPNodeTracer::setTracingActiveRCPNodes(
true);
 
  400       RCP<A> a = 
rcp(
new A());
 
  401       RCP<C> c2 = 
rcp(
new C());
 
  406 #endif // TEUCHOS_DEBUG 
  408 #ifndef TEUCHOS_DEBUG 
  410     out << 
"\nTesting using RCP to wrap an undefined opaque object (no TNT) ...\n";
 
  412       RCP<UndefinedType> op_ptr =
 
  424 #endif // not TEUCHOS_DEBUG 
  426     out << 
"\nTesting using RCP to wrap an undefined opaque object (with TNT) ...\n";
 
  436 #ifdef HAVE_TEUCHOS_BOOST 
  438     out << 
"\nTesting basic RCP compatibility with boost::shared_ptr ...\n";
 
  440     boost::shared_ptr<A> a_sptr1(
new C());
 
  441     RCP<A> a_rsptr1 = 
rcp(a_sptr1);
 
  448     RCP<A> a_rsptr2 = 
rcp(a_sptr2);
 
  454     out << 
"\nCompatibility with boost::shared_ptr passed ...\n";
 
  456 #endif // HAVE_TEUCHOS_BOOST 
  458     out << 
"\nAll tests for RCP seem to check out!\n";
 
  466     if (createCircRefs) {
 
  467       out << 
"\nPrinting the active nodes just to see them!\n";
 
  469 #if defined(TEUCHOS_DEBUG) && !defined(HAVE_TEUCHOS_DEBUG_RCP_NODE_TRACING) 
  477     out << 
"\nEnd Result: TEST PASSED" << std::endl;
 
  479   return ( success ? 0 : 1 );
 
RCP< T > rcp(const boost::shared_ptr< T > &sptr)
Conversion function that takes in a boost::shared_ptr object and spits out a Teuchos::RCP object...
void destroyOpaque(Opaque_handle *opaque)
void set_extra_data(const T1 &extra_data, const std::string &name, const Ptr< ArrayRCP< T2 > > &p, EPrePostDestruction destroy_when=POST_DESTROY, bool force_unique=true)
Set extra data associated with a ArrayRCP object. 
static int getRank()
The rank of the calling process in MPI_COMM_WORLD. 
Ptr< T > inOutArg(T &arg)
create a non-persisting (required or optional) input/output argument for a function call...
RCP< T2 > rcp_static_cast(const RCP< T1 > &p1)
Static cast of underlying RCP type from T1* to T2*. 
boost::shared_ptr< T > shared_pointer(const RCP< T > &rcp)
Conversion function that takes in a Teuchos::RCP object and spits out a boost::shared_ptr object...
T1 & get_extra_data(ArrayRCP< T2 > &p, const std::string &name)
Get a non-const reference to extra data associated with a ArrayRCP object. 
Ptr< T1 > get_optional_nonconst_extra_data(RCP< T2 > &p, const std::string &name)
Get a pointer to non-const extra data (if it exists) associated with a RCP object. 
RCP< T2 > rcp_dynamic_cast(const RCP< T1 > &p1, bool throw_on_fail=false)
Dynamic cast of underlying RCP type from T1* to T2*. 
bool is_null(const std::shared_ptr< T > &p)
Returns true if p.get()==NULL. 
basic_ostream<> subclass that does nothing but discard output. 
Dealloc_T * get_optional_nonconst_dealloc(const ArrayRCP< T > &p)
Return a pointer to the underlying const deallocator object if it exists. 
const T & getConst(T &t)
Return a constant reference to an object given a non-const reference. 
const int getOpaqueValue_return
Initialize, finalize, and query the global MPI session. 
void destroyOpaque2(Opaque2_handle *opaque)
bool is_null(const ArrayRCP< T > &p)
Returns true if p.get()==NULL. 
RCP< T > rcpWithEmbeddedObj(T *p, const Embedded &embedded, bool owns_mem=true)
Create an RCP with and also put in an embedded object. 
const int getOpaque2Value_return
Policy class for deallocator that uses delete to delete a pointer which is used by RCP...
T1 * get_optional_extra_data(ArrayRCP< T2 > &p, const std::string &name)
Get a pointer to non-const extra data (if it exists) associated with a ArrayRCP object. 
void deallocHandleA(A **handle)
RCP< T > rcpWithEmbeddedObjPostDestroy(T *p, const Embedded &embedded, bool owns_mem=true)
Create an RCP with and also put in an embedded object. 
RCP< T > rcpWithEmbeddedObjPreDestroy(T *p, const Embedded &embedded, bool owns_mem=true)
Create an RCP with and also put in an embedded object. 
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated. 
int getOpaqueValue(Opaque_handle opaque)
#define TEUCHOS_STANDARD_CATCH_STATEMENTS(VERBOSE, ERR_STREAM, SUCCESS_FLAG)
Simple macro that catches and reports standard exceptions and other exceptions. 
RCP< T > rcpWithDeallocUndef(T *p, Dealloc_T dealloc, bool owns_mem=true)
Initialize from a raw pointer with a deallocation policy for an undefined type. 
Opaque2_handle createOpaque2()
const Dealloc_T * get_optional_dealloc(const ArrayRCP< T > &p)
Return a pointer to the underlying non-const deallocator object if it exists. 
std::string Teuchos_Version()
int main(int argc, char *argv[])
A MPI utilities class, providing methods for initializing, finalizing, and querying the global MPI se...
Basic command line parser for input from (argc,argv[]) 
int getOpaque2Value(Opaque2_handle opaque)
Opaque_handle createOpaque()
Smart reference counting pointer class for automatic garbage collection. 
#define TEUCHOS_ASSERT_EQUALITY(val1, val2)
This macro is checks that to numbers are equal and if not then throws an exception with a good error ...
RCP< T2 > rcp_const_cast(const RCP< T1 > &p1)
Constant cast of underlying RCP type from T1* to T2*. 
RCP< T > rcpWithDealloc(T *p, Dealloc_T dealloc, bool owns_mem=true)
Initialize from a raw pointer with a deallocation policy. 
static int numActiveRCPNodes()
Print the number of active RCPNode objects currently being tracked. 
Reference-counted pointer class and non-member templated function implementations. 
Class that helps parse command line input arguments from (argc,argv[]) and set options. 
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
This macro is designed to be a short version of TEUCHOS_TEST_FOR_EXCEPTION() that is easier to call...
static void printActiveRCPNodes(std::ostream &out)
Print the list of currently active RCP nodes.