D:/Projects/CEGUI/Silly/src/SILLYFileDataSource.cpp

00001 /***********************************************************************
00002     filename:   SILLYFileDataSource.cpp
00003     created:    20 Jul 2006
00004     author:     Olivier Delannoy 
00005 
00006     purpose:    Implementation of the FileDataSource methods  
00007 *************************************************************************/
00008 /***************************************************************************
00009  *   Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team
00010  *
00011  *   Permission is hereby granted, free of charge, to any person obtaining
00012  *   a copy of this software and associated documentation files (the
00013  *   "Software"), to deal in the Software without restriction, including
00014  *   without limitation the rights to use, copy, modify, merge, publish,
00015  *   distribute, sublicense, and/or sell copies of the Software, and to
00016  *   permit persons to whom the Software is furnished to do so, subject to
00017  *   the following conditions:
00018  *
00019  *   The above copyright notice and this permission notice shall be
00020  *   included in all copies or substantial portions of the Software.
00021  *
00022  *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00023  *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00024  *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00025  *   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
00026  *   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
00027  *   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00028  *   OTHER DEALINGS IN THE SOFTWARE.
00029  ***************************************************************************/
00030 #ifdef HAVE_CONFIG_H
00031 #include <config.h>
00032 #endif
00033 
00034 #include "SILLYFileDataSource.h"
00035 
00036 #ifndef SILLY_OPT_INLINE
00037 #define inline 
00038 #include "SILLYFileDataSource.icpp"
00039 #undef inline
00040 #endif 
00041 #include <stdio.h> 
00042 // Start section of namespace SILLY
00043 namespace SILLY
00044 {
00045 
00046 FileDataSource::FileDataSource(const char* filename)
00047     : d_error(true), d_bytes(0), d_size(0)
00048 {
00049     FILE* data = fopen(filename, "rb");
00050     if (data)
00051     {
00052         long status = fseek(data, 0, SEEK_END);
00053         if (status == -1)
00054         {
00055             fclose(data);
00056             return;
00057         }
00058         status  = ftell(data);
00059         if (status == -1)
00060         {
00061             fclose(data);
00062             return;
00063         }
00064         d_size = status;
00065         if (d_size)
00066             d_bytes = new byte[d_size];
00067         if (! d_bytes)
00068         {
00069             fclose(data);
00070             return;
00071         }
00072         rewind(data);
00073         status = fread(reinterpret_cast<void*>(d_bytes), 1, d_size, data);
00074         if (status != d_size)
00075         {
00076             delete [] d_bytes;
00077             d_bytes = 0;
00078             fclose(data);
00079         }
00080         fclose(data);
00081         d_error = false;        
00082     }
00083 }
00084 
00085 
00086 FileDataSource::~FileDataSource()
00087 {
00088     delete [] d_bytes;
00089 }
00090 
00091 
00092 } // End section of namespace SILLY 

Generated on Sun Apr 6 14:47:06 2008 for Simple Image Loading LibrarY by  doxygen 1.5.2