Skip to content
Snippets Groups Projects
Commit 78adf695 authored by Tomáš Oberhuber's avatar Tomáš Oberhuber Committed by Tomáš Oberhuber
Browse files

[WIP] Changing File load and save from bool to void.

parent 62636134
No related branches found
No related tags found
1 merge request!29Revision
...@@ -64,14 +64,14 @@ class File ...@@ -64,14 +64,14 @@ class File
* \param fileName String which indicates name of the file user wants to open. * \param fileName String which indicates name of the file user wants to open.
* \param mode Indicates what user needs to do with opened file. * \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 ) ) ); 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 * \brief Attempts to close given file and returns \e true when the file is
* successfully closed. Otherwise returns \e false. * successfully closed. Otherwise returns \e false.
*/ */
bool close(); void close();
/** /**
* \brief Returns name of given file. * \brief Returns name of given file.
......
...@@ -28,7 +28,7 @@ inline File::Mode operator|( File::Mode m1, File::Mode m2 ); ...@@ -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 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 // enable exceptions
file.exceptions( std::fstream::failbit | std::fstream::badbit | std::fstream::eofbit ); file.exceptions( std::fstream::failbit | std::fstream::badbit | std::fstream::eofbit );
...@@ -51,10 +51,9 @@ inline bool File::open( const String& fileName, Mode mode ) ...@@ -51,10 +51,9 @@ inline bool File::open( const String& fileName, Mode mode )
} }
this->fileName = fileName; this->fileName = fileName;
return true;
} }
inline bool File::close() inline void File::close()
{ {
if( file.is_open() ) if( file.is_open() )
{ {
...@@ -69,7 +68,6 @@ inline bool File::close() ...@@ -69,7 +68,6 @@ inline bool File::close()
} }
// reset file name // reset file name
fileName = ""; fileName = "";
return true;
} }
template< typename Type, typename Device > template< typename Type, typename Device >
......
...@@ -65,11 +65,7 @@ class DistributedGridIO< ...@@ -65,11 +65,7 @@ class DistributedGridIO<
newMesh->setOrigin(origin+TNL::Containers::Scale(spaceSteps,localBegin)); newMesh->setOrigin(origin+TNL::Containers::Scale(spaceSteps,localBegin));
File meshFile; File meshFile;
if( ! meshFile.open( fileName+String("-mesh-")+distrGrid->printProcessCoords()+String(".tnl"),File::Mode::Out ) ) 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;
}
newMesh->save( meshFile ); newMesh->save( meshFile );
meshFile.close(); meshFile.close();
...@@ -84,11 +80,7 @@ class DistributedGridIO< ...@@ -84,11 +80,7 @@ class DistributedGridIO<
CopyEntitiesHelper<MeshFunctionType>::Copy(meshFunction,newMeshFunction,localBegin,zeroCoord,localSize); CopyEntitiesHelper<MeshFunctionType>::Copy(meshFunction,newMeshFunction,localBegin,zeroCoord,localSize);
File file; File file;
if( ! file.open( fileName+String("-")+distrGrid->printProcessCoords()+String(".tnl"), File::Mode::Out ) ) file.open( fileName+String("-")+distrGrid->printProcessCoords()+String(".tnl"), File::Mode::Out );
{
std::cerr << "Failed to open file for writing." << std::endl;
return false;
}
bool ret=newMeshFunction.save(file); bool ret=newMeshFunction.save(file);
file.close(); file.close();
...@@ -126,11 +118,7 @@ class DistributedGridIO< ...@@ -126,11 +118,7 @@ class DistributedGridIO<
zeroCoord.setValue(0); zeroCoord.setValue(0);
File file; File file;
if( ! file.open( fileName+String("-")+distrGrid->printProcessCoords()+String(".tnl"), File::Mode::In ) ) file.open( fileName+String("-")+distrGrid->printProcessCoords()+String(".tnl"), File::Mode::In );
{
std::cerr << "Failed to open file for reading." << std::endl;
return false;
}
bool result=newMeshFunction.boundLoad(file); bool result=newMeshFunction.boundLoad(file);
file.close(); file.close();
CopyEntitiesHelper<MeshFunctionType>::Copy(newMeshFunction,meshFunction,zeroCoord,localBegin,localSize); CopyEntitiesHelper<MeshFunctionType>::Copy(newMeshFunction,meshFunction,zeroCoord,localBegin,localSize);
......
...@@ -68,33 +68,21 @@ inline bool Object::boundLoad( File& file ) ...@@ -68,33 +68,21 @@ inline bool Object::boundLoad( File& file )
inline bool Object::save( const String& fileName ) const inline bool Object::save( const String& fileName ) const
{ {
File file; File file;
if( ! file.open( fileName, File::Mode::Out ) ) file.open( fileName, File::Mode::Out );
{
std::cerr << "I am not able to open the file " << fileName << " for writing." << std::endl;
return false;
}
return this->save( file ); return this->save( file );
} }
inline bool Object::load( const String& fileName ) inline bool Object::load( const String& fileName )
{ {
File file; File file;
if( ! file.open( fileName, File::Mode::In ) ) file.open( fileName, File::Mode::In );
{
std::cerr << "I am not able to open the file " << fileName << " for reading." << std::endl;
return false;
}
return this->load( file ); return this->load( file );
} }
inline bool Object::boundLoad( const String& fileName ) inline bool Object::boundLoad( const String& fileName )
{ {
File file; File file;
if( ! file.open( fileName, File::Mode::In ) ) file.open( fileName, File::Mode::In );
{
std::cerr << "I am not able to open the file " << fileName << " for reading." << std::endl;
return false;
}
return this->boundLoad( file ); return this->boundLoad( file );
} }
......
...@@ -15,12 +15,6 @@ ...@@ -15,12 +15,6 @@
using namespace TNL; using namespace TNL;
TEST( FileTest, CloseEmpty )
{
File file;
ASSERT_TRUE( file.close() );
}
TEST( FileTest, OpenInvalid ) TEST( FileTest, OpenInvalid )
{ {
File file; File file;
...@@ -30,7 +24,7 @@ TEST( FileTest, OpenInvalid ) ...@@ -30,7 +24,7 @@ TEST( FileTest, OpenInvalid )
TEST( FileTest, WriteAndRead ) TEST( FileTest, WriteAndRead )
{ {
File file; 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 ); int intData( 5 );
double doubleData[ 3 ] = { 1.0, 2.0, 3.0 }; double doubleData[ 3 ] = { 1.0, 2.0, 3.0 };
...@@ -38,9 +32,9 @@ TEST( FileTest, WriteAndRead ) ...@@ -38,9 +32,9 @@ TEST( FileTest, WriteAndRead )
ASSERT_TRUE( file.write( &intData ) ); ASSERT_TRUE( file.write( &intData ) );
ASSERT_TRUE( file.write( doubleData, 3 ) ); ASSERT_TRUE( file.write( doubleData, 3 ) );
ASSERT_TRUE( file.write( &constDoubleData ) ); 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; int newIntData;
double newDoubleData[ 3 ]; double newDoubleData[ 3 ];
double newConstDoubleData; double newConstDoubleData;
...@@ -83,7 +77,7 @@ TEST( FileTest, WriteAndReadCUDA ) ...@@ -83,7 +77,7 @@ TEST( FileTest, WriteAndReadCUDA )
cudaMemcpyHostToDevice ); cudaMemcpyHostToDevice );
File file; 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 ); bool status = file.write< int, Devices::Cuda >( cudaIntData );
ASSERT_TRUE( status ); ASSERT_TRUE( status );
...@@ -91,9 +85,9 @@ TEST( FileTest, WriteAndReadCUDA ) ...@@ -91,9 +85,9 @@ TEST( FileTest, WriteAndReadCUDA )
ASSERT_TRUE( status ); ASSERT_TRUE( status );
status = file.write< const double, Devices::Cuda >( cudaConstDoubleData ); status = file.write< const double, Devices::Cuda >( cudaConstDoubleData );
ASSERT_TRUE( status ); 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; int newIntData;
float newFloatData[ 3 ]; float newFloatData[ 3 ];
double newDoubleData; double newDoubleData;
......
...@@ -62,9 +62,9 @@ class TestSaveAndLoadMeshfunction ...@@ -62,9 +62,9 @@ class TestSaveAndLoadMeshfunction
linearFunctionEvaluator.evaluateAllEntities(localMeshFunctionptr , linearFunctionPtr); linearFunctionEvaluator.evaluateAllEntities(localMeshFunctionptr , linearFunctionPtr);
File file; File file;
ASSERT_TRUE( file.open( String( FILENAME), File::Mode::Out )); file.open( String( FILENAME), File::Mode::Out );
ASSERT_TRUE( localMeshFunctionptr->save(file)); localMeshFunctionptr->save(file);
ASSERT_TRUE( file.close() ); file.close();
//load other meshfunction on same localgrid from created file //load other meshfunction on same localgrid from created file
Pointers::SharedPointer<MeshType> loadGridptr; Pointers::SharedPointer<MeshType> loadGridptr;
...@@ -80,9 +80,9 @@ class TestSaveAndLoadMeshfunction ...@@ -80,9 +80,9 @@ class TestSaveAndLoadMeshfunction
loadDof[i]=-1; loadDof[i]=-1;
} }
ASSERT_TRUE( file.open( String( FILENAME ), File::Mode::In )); file.open( String( FILENAME ), File::Mode::In );
ASSERT_TRUE( loadMeshFunctionptr->boundLoad(file)); loadMeshFunctionptr->boundLoad(file);
ASSERT_TRUE( file.close()); file.close();
for(int i=0;i<localDof.getSize();i++) for(int i=0;i<localDof.getSize();i++)
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment