Skip to content
Snippets Groups Projects
Commit f2cd5e39 authored by Martin Nolte's avatar Martin Nolte
Browse files

added test showing what polyallocator shall be able to do

[[Imported from SVN: r5956]]
parent cd5833b9
Branches
Tags
No related merge requests found
......@@ -16,6 +16,7 @@ sllisttest
tuplestest
settest
fmatrixtest
polyallocator
poolallocatortest
*.gcda
*.gcno
......
......@@ -22,6 +22,7 @@ TESTPROGS = \
mpicollcomm \
mpiguard \
nullptr-test \
polyallocator \
poolallocatortest \
settest \
shared_ptrtest \
......@@ -101,6 +102,8 @@ fvectortest_SOURCES = fvectortest.cc
fmatrixtest_SOURCES = fmatrixtest.cc
polyallocator_SOURCES = polyallocator.cc
poolallocatortest_SOURCES = poolallocatortest.cc
settest_SOURCES=settest.cc
......
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#include <config.h>
#include <iostream>
#include <dune/common/polyallocator.hh>
struct A
{
virtual ~A () {}
virtual void test ( int i ) = 0;
};
struct B
: public A
{
B( int i ) : k( i ) {}
void test ( int i )
{
std::cout << "B( " << k << " ).test( " << i << " )" << std::endl;
}
int k;
};
struct C
: public A
{
void test ( int i )
{
std::cout << "C.test( " << i << " )" << std::endl;
}
};
A *create ( int argc, char **argv, Dune::PolyAllocator &allocator )
{
if( argc > 1 )
{
B *b = allocator.allocate< B >();
allocator.construct( b, B( atoi( argv[ 1 ] ) ) );
return b;
}
else
{
C *c = allocator.allocate< C >();
allocator.construct( c, C() );
return c;
}
}
int main ( int argc, char **argv )
{
Dune::PolyAllocator allocator;
A *a = create( argc, argv, allocator );
a->test( 2 );
allocator.destroy( a );
allocator.deallocate( a );
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment