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
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -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.
+2 −4
Original line number Diff line number Diff line
@@ -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 >
+3 −15
Original line number Diff line number Diff line
@@ -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);
+3 −15
Original line number Diff line number Diff line
@@ -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 );
}

+6 −12
Original line number Diff line number Diff line
@@ -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;
Loading