cFileSource.cpp

00001 // Copyright (c) 2008-2010 Raynaldo (Wildicv) Rivera, Joshua (Dark_Kilauea) Jones
00002 // This file is part of the "cAudio Engine"
00003 // For conditions of distribution and use, see copyright notice in cAudio.h
00004 
00005 #include "../Headers/cFileSource.h"
00006 #include <cstring>
00007 #include "../Headers/cUtils.h"
00008 
00009 namespace cAudio
00010 {
00011 
00012 cFileSource::cFileSource(const char* filename) : pFile(NULL), Valid(false), Filesize(0)
00013 {
00014         std::string safeFilename = safeCStr(filename);
00015     if(safeFilename.length() != 0)
00016     {
00017                 pFile = fopen(safeFilename.c_str(),"rb");
00018                 if(pFile)
00019                         Valid = true;
00020     }
00021 
00022     if(Valid)
00023     {
00024         fseek(pFile, 0, SEEK_END);
00025         Filesize = ftell(pFile);
00026         fseek(pFile, 0, SEEK_SET);
00027     }
00028 }
00029 
00030 cFileSource::~cFileSource()
00031 {
00032         if(pFile)
00033                 fclose(pFile);
00034 }
00035 
00036 bool cFileSource::isValid()
00037 {
00038     return Valid;
00039 }
00040 
00041 int cFileSource::getCurrentPos()
00042 {
00043     return ftell(pFile);
00044 }
00045 
00046 int cFileSource::getSize()
00047 {
00048     return Filesize;
00049 }
00050 
00051 int cFileSource::read(void* output, int size)
00052 {
00053         return fread(output, sizeof(char), size, pFile);
00054 }
00055 
00056 bool cFileSource::seek(int amount, bool relative)
00057 {
00058     if(relative == true)
00059     {
00060         int oldamount = ftell(pFile);
00061         fseek(pFile, amount, SEEK_CUR);
00062 
00063         //check against the absolute position
00064         if(oldamount+amount != ftell(pFile))
00065             return false;
00066     }
00067     else
00068     {
00069         fseek(pFile, amount, SEEK_SET);
00070         if(amount != ftell(pFile))
00071             return false;
00072     }
00073 
00074     return true;
00075 }
00076 
00077 };
 All Classes Namespaces Functions Variables Enumerations

Generated on Sat Feb 20 22:55:08 2010 for cAudio by  doxygen 1.6.2