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

module_reader.cpp

Go to the documentation of this file.
00001 /*
00002         $Id: module_reader.cpp,v 1.2 2001/03/13 21:43:02 sphair Exp $
00003 
00004         ------------------------------------------------------------------------
00005         ClanLib, the platform independent game SDK.
00006 
00007         This library is distributed under the GNU LIBRARY GENERAL PUBLIC LICENSE
00008         version 2. See COPYING for details.
00009 
00010         For a total list of contributers see CREDITS.
00011 
00012         ------------------------------------------------------------------------
00013 
00014         File purpose:
00015                 Module reader for MikMod
00016 
00017 */
00018 
00019 #include "module_reader.h"
00020 #include "../API/Core/IOData/inputsource.h"
00021 
00022 BOOL clanlib_reader_feof(MREADER* reader)
00023 // eof function, returns TRUE if we are at the end of the file.
00024 // Since CL_InputSource does not have a built-in eof function,
00025 // we compare the current position to the size of the file.
00026 {
00027         return (((CL_InputSource *) (((MCLANLIBREADER *) reader)->input))->tell()
00028                 >= (((CL_InputSource *) (((MCLANLIBREADER *) reader)->input))->size()));
00029 }
00030 
00031 BOOL clanlib_reader_read(MREADER* reader,void* ptr,size_t size)
00032 // read function, puts the data in a buffer.
00033 // Even if the return type is BOOL, the function returns the number
00034 // of bytes read. MikMod does the same internally.
00035 {
00036         return (((CL_InputSource *) (((MCLANLIBREADER *) reader)->input))->read(ptr,size));
00037 }
00038 
00039 int clanlib_reader_get(MREADER* reader)
00040 // get function, returns a single char from the file
00041 {
00042         return (((CL_InputSource *) (((MCLANLIBREADER *) reader)->input))->read_char8());
00043 }
00044 
00045 BOOL clanlib_reader_seek(MREADER* reader,long offset,int whence)
00046 // seek function, goes to a given position. It's important to note that
00047 // this function is truely necessary for MikMod, and it has to be able to
00048 // go back, ie rewind the file. ClanLib's implementation of this "go back"
00049 // feature is really slow because files are compressed. This is a 
00050 // compromise.
00051 {
00052         CL_InputSource::SeekEnum cl_whence;
00053 
00054         switch (whence)
00055         {
00056         case SEEK_SET:
00057                 cl_whence=CL_InputSource::seek_set;
00058                 break;
00059         case SEEK_CUR:
00060                 cl_whence=CL_InputSource::seek_cur;
00061                 break;
00062         case SEEK_END:
00063                 cl_whence=CL_InputSource::seek_end;
00064                 break;
00065         default:
00066                 cl_whence=CL_InputSource::seek_set;
00067         }
00068 
00069         ((CL_InputSource *) (((MCLANLIBREADER *) reader)->input))->seek(offset,cl_whence);
00070 
00071         return 0;
00072 }
00073 
00074 long clanlib_reader_tell(MREADER* reader)
00075 // tell function, returns the current position in the file.
00076 {
00077         return (((CL_InputSource *) (((MCLANLIBREADER *) reader)->input))->tell());
00078 }
00079 
00080 MREADER *new_clanlib_reader(void *input)
00081 // creates a reader. We need this for MCLANLIBREADER is a plain struct
00082 // and not a class, so we have to construct it "manually".
00083 {
00084         MCLANLIBREADER* reader=new MCLANLIBREADER;
00085         if (reader)
00086         {
00087                 reader->core.Eof =&clanlib_reader_feof;
00088                 reader->core.Read=&clanlib_reader_read;
00089                 reader->core.Get =&clanlib_reader_get;
00090                 reader->core.Seek=&clanlib_reader_seek;
00091                 reader->core.Tell=&clanlib_reader_tell;
00092                 reader->input=input;
00093         }
00094         return (MREADER*)reader;
00095 }
00096 
00097 void delete_clanlib_reader (MREADER* reader)
00098 // deletes the reader. Needed since MCLANLIBREADER is a struct and not
00099 // a C++ class.
00100 {
00101         if (reader!=NULL) delete(reader);
00102 }
00103 

Generated at Wed Apr 4 19:54:01 2001 for ClanLib by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001