cmtkCompressedStreamFile.cxx

Go to the documentation of this file.
00001 /*
00002 //
00003 //  Copyright 1997-2009 Torsten Rohlfing
00004 //
00005 //  Copyright 2004-2011 SRI International
00006 //
00007 //  This file is part of the Computational Morphometry Toolkit.
00008 //
00009 //  http://www.nitrc.org/projects/cmtk/
00010 //
00011 //  The Computational Morphometry Toolkit is free software: you can
00012 //  redistribute it and/or modify it under the terms of the GNU General Public
00013 //  License as published by the Free Software Foundation, either version 3 of
00014 //  the License, or (at your option) any later version.
00015 //
00016 //  The Computational Morphometry Toolkit is distributed in the hope that it
00017 //  will be useful, but WITHOUT ANY WARRANTY; without even the implied
00018 //  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019 //  GNU General Public License for more details.
00020 //
00021 //  You should have received a copy of the GNU General Public License along
00022 //  with the Computational Morphometry Toolkit.  If not, see
00023 //  <http://www.gnu.org/licenses/>.
00024 //
00025 //  $Revision: 2728 $
00026 //
00027 //  $LastChangedDate: 2011-01-13 15:03:21 -0800 (Thu, 13 Jan 2011) $
00028 //
00029 //  $LastChangedBy: torstenrohlfing $
00030 //
00031 */
00032 
00033 #include <System/cmtkCompressedStream.h>
00034 
00035 #include <stdlib.h>
00036 #include <stdio.h>
00037 #include <errno.h>
00038 
00039 namespace
00040 cmtk
00041 {
00042 
00045 
00046 CompressedStream::File::File( const char* filename )
00047 {
00048   this->m_File = fopen( filename, CMTK_FILE_MODE );
00049   if ( !this->m_File ) 
00050     {
00051     throw 0;
00052     }
00053 }
00054 
00055 void 
00056 CompressedStream::File::Close()
00057 {
00058   fclose( this->m_File );
00059 }
00060 
00061 void
00062 CompressedStream::File::Rewind () 
00063 {
00064   rewind( this->m_File );
00065   this->CompressedStream::ReaderBase::Rewind();
00066 }
00067 
00068 int
00069 CompressedStream::File::Seek ( const long int offset, int whence ) 
00070 {
00071   return fseek( this->m_File, offset, whence );
00072 }
00073 
00074 size_t
00075 CompressedStream::File::Read( void *data, size_t size, size_t count ) 
00076 {
00077   const size_t result = fread( data, size, count, this->m_File );
00078   this->m_BytesRead += result;
00079   return result / size;  
00080 }
00081 
00082 bool
00083 CompressedStream::File::Get ( char &c)
00084 {
00085   const int data = fgetc( this->m_File );
00086   if ( data != EOF ) 
00087     {
00088     c=(char) data;
00089     ++this->m_BytesRead;
00090     return true;
00091     }
00092 
00093   return false;
00094 }
00095 
00096 int
00097 CompressedStream::File::Tell () const 
00098 {
00099   return ftell( this->m_File );
00100 }
00101 
00102 bool
00103 CompressedStream::File::Feof () const 
00104 {
00105   return (feof( this->m_File ) != 0);
00106 }
00107 
00108 } // namespace cmtk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines