Loading src/TNL/File.h +2 −2 Original line number Diff line number Diff line Loading @@ -64,14 +64,14 @@ class File * \param fileName String which indicates name of the file user wants to open. * \param mode Indicates what user needs to do with opened file. */ bool open( const String& fileName, void open( const String& fileName, Mode mode = static_cast< Mode >( static_cast< int >( Mode::In ) | static_cast< int >( Mode::Out ) ) ); /** * \brief Attempts to close given file and returns \e true when the file is * successfully closed. Otherwise returns \e false. */ bool close(); void close(); /** * \brief Returns name of given file. Loading src/TNL/File.hpp +2 −4 Original line number Diff line number Diff line Loading @@ -28,7 +28,7 @@ inline File::Mode operator|( File::Mode m1, File::Mode m2 ); inline bool operator&( File::Mode m1, File::Mode m2 ); inline bool File::open( const String& fileName, Mode mode ) inline void File::open( const String& fileName, Mode mode ) { // enable exceptions file.exceptions( std::fstream::failbit | std::fstream::badbit | std::fstream::eofbit ); Loading @@ -51,10 +51,9 @@ inline bool File::open( const String& fileName, Mode mode ) } this->fileName = fileName; return true; } inline bool File::close() inline void File::close() { if( file.is_open() ) { Loading @@ -69,7 +68,6 @@ inline bool File::close() } // reset file name fileName = ""; return true; } template< typename Type, typename Device > Loading src/TNL/Meshes/DistributedMeshes/DistributedGridIO_MeshFunction.h +3 −15 Original line number Diff line number Diff line Loading @@ -65,11 +65,7 @@ class DistributedGridIO< newMesh->setOrigin(origin+TNL::Containers::Scale(spaceSteps,localBegin)); File meshFile; if( ! meshFile.open( fileName+String("-mesh-")+distrGrid->printProcessCoords()+String(".tnl"),File::Mode::Out ) ) { std::cerr << "Failed to open mesh file for writing." << std::endl; return false; } meshFile.open( fileName+String("-mesh-")+distrGrid->printProcessCoords()+String(".tnl"),File::Mode::Out ); newMesh->save( meshFile ); meshFile.close(); Loading @@ -84,11 +80,7 @@ class DistributedGridIO< CopyEntitiesHelper<MeshFunctionType>::Copy(meshFunction,newMeshFunction,localBegin,zeroCoord,localSize); File file; if( ! file.open( fileName+String("-")+distrGrid->printProcessCoords()+String(".tnl"), File::Mode::Out ) ) { std::cerr << "Failed to open file for writing." << std::endl; return false; } file.open( fileName+String("-")+distrGrid->printProcessCoords()+String(".tnl"), File::Mode::Out ); bool ret=newMeshFunction.save(file); file.close(); Loading Loading @@ -126,11 +118,7 @@ class DistributedGridIO< zeroCoord.setValue(0); File file; if( ! file.open( fileName+String("-")+distrGrid->printProcessCoords()+String(".tnl"), File::Mode::In ) ) { std::cerr << "Failed to open file for reading." << std::endl; return false; } file.open( fileName+String("-")+distrGrid->printProcessCoords()+String(".tnl"), File::Mode::In ); bool result=newMeshFunction.boundLoad(file); file.close(); CopyEntitiesHelper<MeshFunctionType>::Copy(newMeshFunction,meshFunction,zeroCoord,localBegin,localSize); Loading src/TNL/Object.hpp +3 −15 Original line number Diff line number Diff line Loading @@ -68,33 +68,21 @@ inline bool Object::boundLoad( File& file ) inline bool Object::save( const String& fileName ) const { File file; if( ! file.open( fileName, File::Mode::Out ) ) { std::cerr << "I am not able to open the file " << fileName << " for writing." << std::endl; return false; } file.open( fileName, File::Mode::Out ); return this->save( file ); } inline bool Object::load( const String& fileName ) { File file; if( ! file.open( fileName, File::Mode::In ) ) { std::cerr << "I am not able to open the file " << fileName << " for reading." << std::endl; return false; } file.open( fileName, File::Mode::In ); return this->load( file ); } inline bool Object::boundLoad( const String& fileName ) { File file; if( ! file.open( fileName, File::Mode::In ) ) { std::cerr << "I am not able to open the file " << fileName << " for reading." << std::endl; return false; } file.open( fileName, File::Mode::In ); return this->boundLoad( file ); } Loading src/UnitTests/FileTest.h +6 −12 Original line number Diff line number Diff line Loading @@ -15,12 +15,6 @@ using namespace TNL; TEST( FileTest, CloseEmpty ) { File file; ASSERT_TRUE( file.close() ); } TEST( FileTest, OpenInvalid ) { File file; Loading @@ -30,7 +24,7 @@ TEST( FileTest, OpenInvalid ) TEST( FileTest, WriteAndRead ) { File file; ASSERT_TRUE( file.open( String( "test-file.tnl" ), File::Mode::Out ) ); file.open( String( "test-file.tnl" ), File::Mode::Out ); int intData( 5 ); double doubleData[ 3 ] = { 1.0, 2.0, 3.0 }; Loading @@ -38,9 +32,9 @@ TEST( FileTest, WriteAndRead ) ASSERT_TRUE( file.write( &intData ) ); ASSERT_TRUE( file.write( doubleData, 3 ) ); ASSERT_TRUE( file.write( &constDoubleData ) ); ASSERT_TRUE( file.close() ); file.close(); ASSERT_TRUE( file.open( String( "test-file.tnl" ), File::Mode::In ) ); file.open( String( "test-file.tnl" ), File::Mode::In ); int newIntData; double newDoubleData[ 3 ]; double newConstDoubleData; Loading Loading @@ -83,7 +77,7 @@ TEST( FileTest, WriteAndReadCUDA ) cudaMemcpyHostToDevice ); File file; ASSERT_TRUE( file.open( String( "test-file.tnl" ), File::Mode::Out ) ); file.open( String( "test-file.tnl" ), File::Mode::Out ); bool status = file.write< int, Devices::Cuda >( cudaIntData ); ASSERT_TRUE( status ); Loading @@ -91,9 +85,9 @@ TEST( FileTest, WriteAndReadCUDA ) ASSERT_TRUE( status ); status = file.write< const double, Devices::Cuda >( cudaConstDoubleData ); ASSERT_TRUE( status ); ASSERT_TRUE( file.close() ); file.close(); ASSERT_TRUE( file.open( String( "test-file.tnl" ), File::Mode::In ) ); file.open( String( "test-file.tnl" ), File::Mode::In ); int newIntData; float newFloatData[ 3 ]; double newDoubleData; Loading Loading
src/TNL/File.h +2 −2 Original line number Diff line number Diff line Loading @@ -64,14 +64,14 @@ class File * \param fileName String which indicates name of the file user wants to open. * \param mode Indicates what user needs to do with opened file. */ bool open( const String& fileName, void open( const String& fileName, Mode mode = static_cast< Mode >( static_cast< int >( Mode::In ) | static_cast< int >( Mode::Out ) ) ); /** * \brief Attempts to close given file and returns \e true when the file is * successfully closed. Otherwise returns \e false. */ bool close(); void close(); /** * \brief Returns name of given file. Loading
src/TNL/File.hpp +2 −4 Original line number Diff line number Diff line Loading @@ -28,7 +28,7 @@ inline File::Mode operator|( File::Mode m1, File::Mode m2 ); inline bool operator&( File::Mode m1, File::Mode m2 ); inline bool File::open( const String& fileName, Mode mode ) inline void File::open( const String& fileName, Mode mode ) { // enable exceptions file.exceptions( std::fstream::failbit | std::fstream::badbit | std::fstream::eofbit ); Loading @@ -51,10 +51,9 @@ inline bool File::open( const String& fileName, Mode mode ) } this->fileName = fileName; return true; } inline bool File::close() inline void File::close() { if( file.is_open() ) { Loading @@ -69,7 +68,6 @@ inline bool File::close() } // reset file name fileName = ""; return true; } template< typename Type, typename Device > Loading
src/TNL/Meshes/DistributedMeshes/DistributedGridIO_MeshFunction.h +3 −15 Original line number Diff line number Diff line Loading @@ -65,11 +65,7 @@ class DistributedGridIO< newMesh->setOrigin(origin+TNL::Containers::Scale(spaceSteps,localBegin)); File meshFile; if( ! meshFile.open( fileName+String("-mesh-")+distrGrid->printProcessCoords()+String(".tnl"),File::Mode::Out ) ) { std::cerr << "Failed to open mesh file for writing." << std::endl; return false; } meshFile.open( fileName+String("-mesh-")+distrGrid->printProcessCoords()+String(".tnl"),File::Mode::Out ); newMesh->save( meshFile ); meshFile.close(); Loading @@ -84,11 +80,7 @@ class DistributedGridIO< CopyEntitiesHelper<MeshFunctionType>::Copy(meshFunction,newMeshFunction,localBegin,zeroCoord,localSize); File file; if( ! file.open( fileName+String("-")+distrGrid->printProcessCoords()+String(".tnl"), File::Mode::Out ) ) { std::cerr << "Failed to open file for writing." << std::endl; return false; } file.open( fileName+String("-")+distrGrid->printProcessCoords()+String(".tnl"), File::Mode::Out ); bool ret=newMeshFunction.save(file); file.close(); Loading Loading @@ -126,11 +118,7 @@ class DistributedGridIO< zeroCoord.setValue(0); File file; if( ! file.open( fileName+String("-")+distrGrid->printProcessCoords()+String(".tnl"), File::Mode::In ) ) { std::cerr << "Failed to open file for reading." << std::endl; return false; } file.open( fileName+String("-")+distrGrid->printProcessCoords()+String(".tnl"), File::Mode::In ); bool result=newMeshFunction.boundLoad(file); file.close(); CopyEntitiesHelper<MeshFunctionType>::Copy(newMeshFunction,meshFunction,zeroCoord,localBegin,localSize); Loading
src/TNL/Object.hpp +3 −15 Original line number Diff line number Diff line Loading @@ -68,33 +68,21 @@ inline bool Object::boundLoad( File& file ) inline bool Object::save( const String& fileName ) const { File file; if( ! file.open( fileName, File::Mode::Out ) ) { std::cerr << "I am not able to open the file " << fileName << " for writing." << std::endl; return false; } file.open( fileName, File::Mode::Out ); return this->save( file ); } inline bool Object::load( const String& fileName ) { File file; if( ! file.open( fileName, File::Mode::In ) ) { std::cerr << "I am not able to open the file " << fileName << " for reading." << std::endl; return false; } file.open( fileName, File::Mode::In ); return this->load( file ); } inline bool Object::boundLoad( const String& fileName ) { File file; if( ! file.open( fileName, File::Mode::In ) ) { std::cerr << "I am not able to open the file " << fileName << " for reading." << std::endl; return false; } file.open( fileName, File::Mode::In ); return this->boundLoad( file ); } Loading
src/UnitTests/FileTest.h +6 −12 Original line number Diff line number Diff line Loading @@ -15,12 +15,6 @@ using namespace TNL; TEST( FileTest, CloseEmpty ) { File file; ASSERT_TRUE( file.close() ); } TEST( FileTest, OpenInvalid ) { File file; Loading @@ -30,7 +24,7 @@ TEST( FileTest, OpenInvalid ) TEST( FileTest, WriteAndRead ) { File file; ASSERT_TRUE( file.open( String( "test-file.tnl" ), File::Mode::Out ) ); file.open( String( "test-file.tnl" ), File::Mode::Out ); int intData( 5 ); double doubleData[ 3 ] = { 1.0, 2.0, 3.0 }; Loading @@ -38,9 +32,9 @@ TEST( FileTest, WriteAndRead ) ASSERT_TRUE( file.write( &intData ) ); ASSERT_TRUE( file.write( doubleData, 3 ) ); ASSERT_TRUE( file.write( &constDoubleData ) ); ASSERT_TRUE( file.close() ); file.close(); ASSERT_TRUE( file.open( String( "test-file.tnl" ), File::Mode::In ) ); file.open( String( "test-file.tnl" ), File::Mode::In ); int newIntData; double newDoubleData[ 3 ]; double newConstDoubleData; Loading Loading @@ -83,7 +77,7 @@ TEST( FileTest, WriteAndReadCUDA ) cudaMemcpyHostToDevice ); File file; ASSERT_TRUE( file.open( String( "test-file.tnl" ), File::Mode::Out ) ); file.open( String( "test-file.tnl" ), File::Mode::Out ); bool status = file.write< int, Devices::Cuda >( cudaIntData ); ASSERT_TRUE( status ); Loading @@ -91,9 +85,9 @@ TEST( FileTest, WriteAndReadCUDA ) ASSERT_TRUE( status ); status = file.write< const double, Devices::Cuda >( cudaConstDoubleData ); ASSERT_TRUE( status ); ASSERT_TRUE( file.close() ); file.close(); ASSERT_TRUE( file.open( String( "test-file.tnl" ), File::Mode::In ) ); file.open( String( "test-file.tnl" ), File::Mode::In ); int newIntData; float newFloatData[ 3 ]; double newDoubleData; Loading