K3dFile.h

Go to the documentation of this file.
00001 
00013 /***************************************************************************
00014  *   Copyright (C) 2007 by Jan Koci   *
00015  *   honza.koci@email.cz   *
00016  *   http://kengine.sourceforge.net/tutorial/
00017  *                                                                         *
00018  *   This program is free software; you can redistribute it and/or modify  *
00019  *   it under the terms of the GNU General Public License as published by  *
00020  *   the Free Software Foundation; either version 2 of the License, or     *
00021  *   (at your option) any later version.                                   *
00022  *                                                                         *
00023  *   This program is distributed in the hope that it will be useful,       *
00024  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00025  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00026  *   GNU General Public License for more details.                          *
00027  *                                                                         *
00028  *   You should have received a copy of the GNU General Public License     *
00029  *   along with this program; if not, write to the                         *
00030  *   Free Software Foundation, Inc.,                                       *
00031  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00032  ***************************************************************************/
00033 
00034 #pragma once
00035 
00036 class K3dFile
00037 {
00038                 FILE*   m_pFile;        
00039         protected:
00043                 bool OpenForRead ( const std::string& _rFileName )
00044                 {
00045                         m_pFile = fopen ( _rFileName.c_str(), "rb" );
00046                         return Good();
00047                 }
00051                 bool OpenForWriteTrunc ( const std::string& _rFileName )
00052                 {
00053                         m_pFile = fopen ( _rFileName.c_str(), "wb" );
00054                         return Good();
00055                 }
00059                 bool OpenForWriteAppend ( const std::string& _rFileName )
00060                 {
00061                         m_pFile = fopen ( _rFileName.c_str(), "ab" );
00062                         return Good();
00063                 }
00067                 bool OpenForReadText ( const std::string& _rFileName )
00068                 {
00069                         m_pFile = fopen ( _rFileName.c_str(), "rt" );
00070                         return Good();
00071                 }
00075                 bool OpenForWriteTextTrunc ( const std::string& _rFileName )
00076                 {
00077                         m_pFile = fopen ( _rFileName.c_str(), "wt" );
00078                         return Good();
00079                 }
00083                 bool OpenForWriteTextAppend ( const std::string& _rFileName )
00084                 {
00085                         m_pFile = fopen ( _rFileName.c_str(), "at" );
00086                         return Good();
00087                 }
00088 
00089         public:
00090                 K3dFile() : m_pFile ( 0 )       {}
00091                 ~K3dFile()
00092                 {
00093                         if ( m_pFile ) fclose ( m_pFile );
00094                 }
00095 
00097                 FILE* GetFile()
00098                 {
00099                         return m_pFile;
00100                 }
00103                 bool Close()
00104                 {
00105                         return ( fclose ( m_pFile ) == 0 );
00106                 }
00109                 bool Flush()
00110                 {
00111                         return ( fflush ( m_pFile ) == 0 );
00112                 }
00115                 bool Good() const
00116                 {
00117                         return ( m_pFile != 0 );
00118                 }
00121                 bool Bad() const
00122                 {
00123                         return ( m_pFile == 0 );
00124                 }
00127                 bool Exists ( const std::string& _rFileName )
00128                 {
00129                         FILE* pFile;
00130                         bool exists = ( ( pFile = fopen ( _rFileName.c_str(), "rb" ) ) != 0 );
00131                         if ( pFile ) fclose ( pFile );
00132                         return exists;
00133                 }
00136                 long Length()
00137                 {
00138                         fseek ( m_pFile, 0, SEEK_END );
00139                         long lLen = ftell ( m_pFile );
00140                         fseek ( m_pFile, 0, SEEK_SET );
00141                         return lLen;
00142                 }
00143 };

Generated on Thu Aug 16 23:53:28 2007 for K3dEngine by  doxygen 1.5.0