diff --git a/src/TNL/File.h b/src/TNL/File.h index ce4a2ba4cb886e835090caa04543c7ffedaa4818..4a8863b9b64b08c130b30fc18471dfab229f30e3 100644 --- a/src/TNL/File.h +++ b/src/TNL/File.h @@ -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. diff --git a/src/TNL/File.hpp b/src/TNL/File.hpp index 623465bb8839eff29ef5084de454828dc168abe1..5cc7f01aa1ece9f558026dfe01fb97747db010fe 100644 --- a/src/TNL/File.hpp +++ b/src/TNL/File.hpp @@ -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 ); @@ -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() ) { @@ -69,7 +68,6 @@ inline bool File::close() } // reset file name fileName = ""; - return true; } template< typename Type, typename Device > diff --git a/src/TNL/Meshes/DistributedMeshes/DistributedGridIO_MeshFunction.h b/src/TNL/Meshes/DistributedMeshes/DistributedGridIO_MeshFunction.h index faac6d14220037cc08f7455707bc4cb9d6f2b256..c6c7842addbb0dec769b94971eec80497c1204d9 100644 --- a/src/TNL/Meshes/DistributedMeshes/DistributedGridIO_MeshFunction.h +++ b/src/TNL/Meshes/DistributedMeshes/DistributedGridIO_MeshFunction.h @@ -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(); @@ -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(); @@ -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); diff --git a/src/TNL/Object.hpp b/src/TNL/Object.hpp index 120dd72967ce1d154e87b3217a30e3140acaba85..1d3dd31a597e11addcd26b487986498d3548e238 100644 --- a/src/TNL/Object.hpp +++ b/src/TNL/Object.hpp @@ -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 ); } diff --git a/src/UnitTests/FileTest.h b/src/UnitTests/FileTest.h index 08cd5e151482c32c5dd8a9fd4a378e9a04bf876f..4f15d6ac7128f0f716eb454adf49caca3edd1e63 100644 --- a/src/UnitTests/FileTest.h +++ b/src/UnitTests/FileTest.h @@ -15,12 +15,6 @@ using namespace TNL; -TEST( FileTest, CloseEmpty ) -{ - File file; - ASSERT_TRUE( file.close() ); -} - TEST( FileTest, OpenInvalid ) { File file; @@ -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 }; @@ -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; @@ -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 ); @@ -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; diff --git a/src/UnitTests/SaveAndLoadMeshfunctionTest.cpp b/src/UnitTests/SaveAndLoadMeshfunctionTest.cpp index 0bc1bb516284ed332431beb5cb9a66e06237f609..e7079e894b1353c969231c1efcd607e1e8d8e8c3 100644 --- a/src/UnitTests/SaveAndLoadMeshfunctionTest.cpp +++ b/src/UnitTests/SaveAndLoadMeshfunctionTest.cpp @@ -62,9 +62,9 @@ class TestSaveAndLoadMeshfunction linearFunctionEvaluator.evaluateAllEntities(localMeshFunctionptr , linearFunctionPtr); File file; - ASSERT_TRUE( file.open( String( FILENAME), File::Mode::Out )); - ASSERT_TRUE( localMeshFunctionptr->save(file)); - ASSERT_TRUE( file.close() ); + file.open( String( FILENAME), File::Mode::Out ); + localMeshFunctionptr->save(file); + file.close(); //load other meshfunction on same localgrid from created file Pointers::SharedPointer<MeshType> loadGridptr; @@ -80,9 +80,9 @@ class TestSaveAndLoadMeshfunction loadDof[i]=-1; } - ASSERT_TRUE( file.open( String( FILENAME ), File::Mode::In )); - ASSERT_TRUE( loadMeshFunctionptr->boundLoad(file)); - ASSERT_TRUE( file.close()); + file.open( String( FILENAME ), File::Mode::In ); + loadMeshFunctionptr->boundLoad(file); + file.close(); for(int i=0;i<localDof.getSize();i++) {