Commit 80b30461 authored by Mathias Goldau's avatar Mathias Goldau
Browse files

[FIX #151] Now the copy constructor should work for WLoaderFibers

parent b7b1d8d6
......@@ -42,8 +42,8 @@
WLoaderFibers::WLoaderFibers( std::string fname, boost::shared_ptr< WDataHandler > dataHandler ) throw( WDHIOFailure )
: WLoader( fname, dataHandler )
{
m_ifs = new std::ifstream( fname.c_str(), std::ifstream::in | std::ifstream::binary );
if( !( *m_ifs ) || m_ifs->bad() )
m_ifs = boost::shared_ptr< std::ifstream >( new std::ifstream( fname.c_str(), std::ifstream::in | std::ifstream::binary ) );
if( !m_ifs || m_ifs->bad() )
{
throw WDHIOFailure( "Load broken file '" + m_fileName + "'" );
}
......@@ -51,11 +51,10 @@ WLoaderFibers::WLoaderFibers( std::string fname, boost::shared_ptr< WDataHandler
WLoaderFibers::~WLoaderFibers() throw()
{
if( m_ifs )
if( m_ifs && m_ifs->is_open() )
{
m_ifs->close();
}
delete( m_ifs );
}
void WLoaderFibers::operator()() throw()
......@@ -77,7 +76,7 @@ void WLoaderFibers::operator()() throw()
// TODO(math): we should print the file name also, since knowing that
// the file was malformated, doesn't give you the hint that there
// could be thousands of them
std::cerr << "Error :: DataHandler :: Abort loading VTK file due to: " << e.what() << std::endl;
std::cerr << "Error :: DataHandler :: Abort loading Fib-VTK file due to: " << e.what() << std::endl;
}
assert( !data->empty() && "loaded empty vector of fibers" );
shared_ptr< WDataSetFibers > fibers = shared_ptr< WDataSetFibers >( new WDataSetFibers( data ) );
......
......@@ -98,7 +98,7 @@ protected:
/**
* Pointer to the input file stream reader.
*/
std::ifstream *m_ifs;
boost::shared_ptr< std::ifstream > m_ifs;
private:
};
......
......@@ -252,6 +252,18 @@ public:
TS_ASSERT_EQUALS( expected, actual->back() );
}
/**
* When e.g. the CopyConstructor is invoked, all internals (including)
* all pointers will be destructed and deleted.
*/
void testDestructor( void )
{
WLoaderFibers loader( "fixtures/Fibers/valid_small_example.fib", m_dataHandler );
std::vector< WLoaderFibers > loaders;
loaders.push_back( loader ); // Copy constructor invoked
loaders.clear(); // second destruction
}
private:
/**
* Dummy DataHandler instance
......
......@@ -36,6 +36,7 @@
#include "WModule.h"
#include "../modules/data/WDataModule.hpp"
#include "../modules/navigationSlices/WNavigationSliceModule.h"
#include "../modules/fiberTest/WFiberTestModule.h"
#include "../common/WException.h"
#include "../graphicsEngine/WGraphicsEngine.h"
......@@ -183,7 +184,9 @@ void WKernel::loadModules()
WLogger::getLogger()->addLogMessage( "*** Loading Modules: ", "Kernel", LL_DEBUG );
m_modules.clear();
boost::shared_ptr< WModule > m = boost::shared_ptr< WModule >( new WNavigationSliceModule() );
using boost::shared_ptr;
shared_ptr< WModule > m = shared_ptr< WModule >( new WNavigationSliceModule() );
// shared_ptr< WModule > m = shared_ptr< WModule >( new WFiberTestModule() );
WLogger::getLogger()->addLogMessage( "Loading module: " + m->getName(), "Kernel", LL_DEBUG );
m_modules.push_back( m );
......
......@@ -27,6 +27,9 @@
#include <osg/Geode>
#include "WFiberTestModule.h"
#include "../../common/WLogger.h"
#include "../../dataHandler/WDataHandler.h"
#include "../../dataHandler/WLoaderManager.h"
WFiberTestModule::WFiberTestModule()
: WModule()
......@@ -49,4 +52,10 @@ const std::string WFiberTestModule::getDescription() const
void WFiberTestModule::threadMain()
{
using boost::shared_ptr;
std::string fname = "dataHandler/io/fixtures/Fibers/valid_small_example.fib";
WLogger::getLogger()->addLogMessage( "Test loading of file: " + fname, "Kernel", LL_DEBUG );
shared_ptr< WDataHandler > dataHandler = shared_ptr< WDataHandler >( new WDataHandler() );
WLoaderManager testLoaderManager;
testLoaderManager.load( fname, dataHandler );
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment