Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

file.hpp

Go to the documentation of this file.
00001 /*
00002 PeRdr - PE file disassembler
00003 Copyright (C) 1999-2002 Frediano Ziglio
00004 -----
00005 
00006 This program is free software; you can redistribute it and/or modify
00007 it under the terms of the GNU General Public License as published by
00008 the Free Software Foundation; either version 2 of the License, or
00009 (at your option) any later version.
00010 
00011 This program is distributed in the hope that it will be useful,
00012 but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 GNU General Public License for more details.
00015 
00016 You should have received a copy of the GNU General Public License
00017 along with this program; if not, write to the Free Software
00018 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019 -----
00020 
00021 INFORMATION
00022   www: https://freddy77.tripod.com/perdr/
00023   e-mail: freddy77@angelfire.com
00024 */
00025 #ifndef FILE_FILE_HPP
00026 #define FILE_FILE_HPP
00027 
00028 #ifndef __STDIO_H
00029 #  include <stdio.h>
00030 #endif
00031 
00032 // !!! please use standard iostream is faster and cleaner
00033 class ICFile
00034 {
00035 public:
00036   enum StringFlag
00037   {
00038     strUcs2=32,
00039     strLen8 = 1, strLen16 = 2, strLen32 = 3, strLenMask =3
00040   };
00041   virtual ~ICFile() {};
00042   virtual void Seek(long offset,int whence=SEEK_SET) const=0;
00043   // !!! this two members should not exist
00044   // use ReadString (ICFile) !!!
00045   virtual char *ReadString() const=0;
00046   virtual char *ReadStringFlag(unsigned flag) const=0;
00047   virtual long Tell() const =0;
00048   virtual void RawRead(void *ptr,size_t size) const=0;
00049   virtual void RawWrite(const void *ptr,size_t size)=0;
00050 };
00051 
00052 // semplice incapsulamento C con eccezioni
00053 class CFile:public ICFile
00054 {
00055 public:
00056   CFile(const char* filename,const char* mode);
00057   ~CFile();
00058   void Seek(long offset,int whence=SEEK_SET) const;
00059   char *ReadString() const;
00060   char *ReadStringFlag(unsigned flag) const;
00061   long Tell() const;
00062   void RawRead(void *ptr,size_t size) const;
00063   void RawWrite(const void *ptr,size_t size);
00064   FILE *GetFile() { return file; };
00065 private:
00066   void Close();
00067   FILE* file;
00068 };
00069 
00070 template <class T>
00071 inline void RawRead(ICFile& file,T& x)
00072 {
00073   file.RawRead(&x,sizeof(T));
00074 }
00075 
00076 template <class T>
00077 inline void RawWrite(ICFile& file,const T& x)
00078 {
00079   file.RawWrite(&x,sizeof(T));
00080 }
00081 
00082 #endif // FILE_FILE_HPP

Generated on Mon Jan 13 22:20:34 2003 for perdr by doxygen1.2.15