Loading src/TNL/CMakeLists.txt +0 −1 Original line number Diff line number Diff line Loading @@ -37,7 +37,6 @@ set( headers StaticVectorFor.h ) set( common_SOURCES File.cpp FileName.cpp Object.cpp Logger.cpp Loading src/TNL/File.cppdeleted 100644 → 0 +0 −77 Original line number Diff line number Diff line /*************************************************************************** File.cpp - description ------------------- begin : Oct 22, 2010 copyright : (C) 2010 by Tomas Oberhuber email : tomas.oberhuber@fjfi.cvut.cz ***************************************************************************/ /* See Copyright Notice in tnl/Copyright */ #include <TNL/File.h> namespace TNL { File :: File() : mode( IOMode::undefined ), file( NULL ), fileOK( false ), writtenElements( 0 ), readElements( 0 ) { } File :: ~File() { // destroying a file without closing is a memory leak // (an open file descriptor is left behind, on Linux there is typically // only a limited number of descriptors available to each process) close(); } bool File :: open( const String& fileName, const IOMode mode ) { // close the existing file to avoid memory leaks this->close(); this->fileName = fileName; if( mode == IOMode::read ) file = std::fopen( fileName.getString(), "rb" ); if( mode == IOMode::write ) file = std::fopen( fileName.getString(), "wb" ); if( file == NULL ) { std::cerr << "I am not able to open the file " << fileName << ". "; std::perror( "" ); return false; } this->fileOK = true; this->mode = mode; return true; } bool File :: close() { if( file && std::fclose( file ) != 0 ) { std::cerr << "I was not able to close the file " << fileName << " properly!" << std::endl; return false; } // reset all attributes mode = IOMode::undefined; file = NULL; fileOK = false; fileName = ""; readElements = writtenElements = 0; return true; } bool fileExists( const String& fileName ) { std::fstream file; file.open( fileName.getString(), std::ios::in ); return ! file.fail(); } } // namespace TNL src/TNL/File.h +6 −6 Original line number Diff line number Diff line Loading @@ -45,22 +45,22 @@ const size_t FileGPUvsCPUTransferBufferSize = 5 * 2<<20; // \include FileExample.out class File { IOMode mode; IOMode mode = IOMode::undefined; std::FILE* file; std::FILE* file = nullptr; bool fileOK; bool fileOK = false; String fileName; std::size_t writtenElements; std::size_t writtenElements = 0; std::size_t readElements; std::size_t readElements = 0; public: /// \brief Basic constructor. File(); File() = default; /// \brief Destructor. ~File(); Loading src/TNL/File_impl.h +52 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,51 @@ namespace TNL { inline File::~File() { // destroying a file without closing is a memory leak // (an open file descriptor is left behind, on Linux there is typically // only a limited number of descriptors available to each process) close(); } inline bool File::open( const String& fileName, const IOMode mode ) { // close the existing file to avoid memory leaks this->close(); this->fileName = fileName; if( mode == IOMode::read ) file = std::fopen( fileName.getString(), "rb" ); if( mode == IOMode::write ) file = std::fopen( fileName.getString(), "wb" ); if( file == NULL ) { std::cerr << "I am not able to open the file " << fileName << ". "; std::perror( "" ); return false; } this->fileOK = true; this->mode = mode; return true; } inline bool File::close() { if( file && std::fclose( file ) != 0 ) { std::cerr << "I was not able to close the file " << fileName << " properly!" << std::endl; return false; } // reset all attributes mode = IOMode::undefined; file = NULL; fileOK = false; fileName = ""; readElements = writtenElements = 0; return true; } template< typename Type, typename Device > bool File::read( Type* buffer ) Loading Loading @@ -306,4 +351,11 @@ bool File::write_impl( const Type* buffer, #endif } inline bool fileExists( const String& fileName ) { std::fstream file; file.open( fileName.getString(), std::ios::in ); return ! file.fail(); } } // namespace TNL Loading
src/TNL/CMakeLists.txt +0 −1 Original line number Diff line number Diff line Loading @@ -37,7 +37,6 @@ set( headers StaticVectorFor.h ) set( common_SOURCES File.cpp FileName.cpp Object.cpp Logger.cpp Loading
src/TNL/File.cppdeleted 100644 → 0 +0 −77 Original line number Diff line number Diff line /*************************************************************************** File.cpp - description ------------------- begin : Oct 22, 2010 copyright : (C) 2010 by Tomas Oberhuber email : tomas.oberhuber@fjfi.cvut.cz ***************************************************************************/ /* See Copyright Notice in tnl/Copyright */ #include <TNL/File.h> namespace TNL { File :: File() : mode( IOMode::undefined ), file( NULL ), fileOK( false ), writtenElements( 0 ), readElements( 0 ) { } File :: ~File() { // destroying a file without closing is a memory leak // (an open file descriptor is left behind, on Linux there is typically // only a limited number of descriptors available to each process) close(); } bool File :: open( const String& fileName, const IOMode mode ) { // close the existing file to avoid memory leaks this->close(); this->fileName = fileName; if( mode == IOMode::read ) file = std::fopen( fileName.getString(), "rb" ); if( mode == IOMode::write ) file = std::fopen( fileName.getString(), "wb" ); if( file == NULL ) { std::cerr << "I am not able to open the file " << fileName << ". "; std::perror( "" ); return false; } this->fileOK = true; this->mode = mode; return true; } bool File :: close() { if( file && std::fclose( file ) != 0 ) { std::cerr << "I was not able to close the file " << fileName << " properly!" << std::endl; return false; } // reset all attributes mode = IOMode::undefined; file = NULL; fileOK = false; fileName = ""; readElements = writtenElements = 0; return true; } bool fileExists( const String& fileName ) { std::fstream file; file.open( fileName.getString(), std::ios::in ); return ! file.fail(); } } // namespace TNL
src/TNL/File.h +6 −6 Original line number Diff line number Diff line Loading @@ -45,22 +45,22 @@ const size_t FileGPUvsCPUTransferBufferSize = 5 * 2<<20; // \include FileExample.out class File { IOMode mode; IOMode mode = IOMode::undefined; std::FILE* file; std::FILE* file = nullptr; bool fileOK; bool fileOK = false; String fileName; std::size_t writtenElements; std::size_t writtenElements = 0; std::size_t readElements; std::size_t readElements = 0; public: /// \brief Basic constructor. File(); File() = default; /// \brief Destructor. ~File(); Loading
src/TNL/File_impl.h +52 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,51 @@ namespace TNL { inline File::~File() { // destroying a file without closing is a memory leak // (an open file descriptor is left behind, on Linux there is typically // only a limited number of descriptors available to each process) close(); } inline bool File::open( const String& fileName, const IOMode mode ) { // close the existing file to avoid memory leaks this->close(); this->fileName = fileName; if( mode == IOMode::read ) file = std::fopen( fileName.getString(), "rb" ); if( mode == IOMode::write ) file = std::fopen( fileName.getString(), "wb" ); if( file == NULL ) { std::cerr << "I am not able to open the file " << fileName << ". "; std::perror( "" ); return false; } this->fileOK = true; this->mode = mode; return true; } inline bool File::close() { if( file && std::fclose( file ) != 0 ) { std::cerr << "I was not able to close the file " << fileName << " properly!" << std::endl; return false; } // reset all attributes mode = IOMode::undefined; file = NULL; fileOK = false; fileName = ""; readElements = writtenElements = 0; return true; } template< typename Type, typename Device > bool File::read( Type* buffer ) Loading Loading @@ -306,4 +351,11 @@ bool File::write_impl( const Type* buffer, #endif } inline bool fileExists( const String& fileName ) { std::fstream file; file.open( fileName.getString(), std::ios::in ); return ! file.fail(); } } // namespace TNL