Commit 35c02ea3 authored by Mathias Goldau's avatar Mathias Goldau
Browse files

[FIX #152] now the m_ifs is kept open now, until the readLines() method is called

parent df46b96f
......@@ -42,7 +42,8 @@
WLoaderFibers::WLoaderFibers( std::string fname, boost::shared_ptr< WDataHandler > dataHandler ) throw( WDHIOFailure )
: WLoader( fname, dataHandler )
{
m_ifs = boost::shared_ptr< std::ifstream >( new std::ifstream( fname.c_str(), std::ifstream::in | std::ifstream::binary ) );
m_ifs = boost::shared_ptr< std::ifstream >( new std::ifstream() );
m_ifs->open( m_fileName.c_str(), std::ifstream::in | std::ifstream::binary );
if( !m_ifs || m_ifs->bad() )
{
throw WDHIOFailure( "Load broken file '" + m_fileName + "'" );
......@@ -51,10 +52,6 @@ WLoaderFibers::WLoaderFibers( std::string fname, boost::shared_ptr< WDataHandler
WLoaderFibers::~WLoaderFibers() throw()
{
if( m_ifs && m_ifs->is_open() )
{
m_ifs->close();
}
}
void WLoaderFibers::operator()() throw()
......@@ -83,6 +80,7 @@ void WLoaderFibers::operator()() throw()
fibers->setFileName( m_fileName );
commitDataSet( fibers );
assert( !m_ifs->is_open() );
}
void WLoaderFibers::readHeader() throw( WDHIOFailure, WDHException )
......@@ -237,5 +235,6 @@ boost::shared_ptr< std::vector< wmath::WFiber > > WLoaderFibers::readLines()
std::getline( *m_ifs, line );
assert( std::string( "" ) == line );
m_ifs->close(); // we can't close it in the destructor since then the copy constructor won't work
return result;
}
......@@ -53,8 +53,7 @@ public:
/**
* Constructs and makes a new VTK loader for separate thread start.
*/
WLoaderFibers( std::string fname, boost::shared_ptr< WDataHandler >
dataHandler ) throw( WDHIOFailure );
WLoaderFibers( std::string fname, boost::shared_ptr< WDataHandler > dataHandler ) throw( WDHIOFailure );
/**
* Destroys this instance and closes the file.
......
......@@ -258,12 +258,28 @@ public:
*/
void testDestructor( void )
{
WLoaderFibers loader( "fixtures/Fibers/valid_small_example.fib", m_dataHandler );
std::vector< WLoaderFibers > loaders;
loaders.push_back( loader ); // Copy constructor invoked
{
WLoaderFibers loader( "fixtures/Fibers/valid_small_example.fib", m_dataHandler );
loaders.push_back( loader );
// destructor invoked
}
TS_ASSERT( loaders[0].m_ifs->is_open() );
loaders.clear(); // second destruction
}
/**
* The () operator normaly starts the thread, so we check here if every thing
* terminates quite well.
*/
void testBracesOperatorTerminatesWell( void )
{
TS_ASSERT_EQUALS( m_dataHandler->getNumberOfSubjects(), 0 );
WLoaderFibers loader( "fixtures/Fibers/valid_small_example.fib", m_dataHandler );
loader();
TS_ASSERT_EQUALS( m_dataHandler->getNumberOfSubjects(), 1 );
}
private:
/**
* Dummy DataHandler instance
......
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