/* * Copyright (C) 2002 - David W. Durham * * This file is part of ReZound, an audio editing application, but * could be used for other applications which could use the PoolFile * class's functionality. * * PoolFile is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published * by the Free Software Foundation; either version 2 of the License, * or (at your option) any later version. * * PoolFile is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #ifndef __TStaticPoolAccesser_H__ #error This file must be included through TStaticPoolAccesser.h NOT compiled with a project file or a makefile. #endif #ifndef __TStaticPoolAccesser_CPP__ #define __TStaticPoolAccesser_CPP__ #include #include template TStaticPoolAccesser::TStaticPoolAccesser(pool_file_t * const _poolFile,const poolId_t _poolId) : poolFile(_poolFile), poolId(_poolId), position(0) { init(); poolFile->addAccesser(this); } template TStaticPoolAccesser::TStaticPoolAccesser(const TStaticPoolAccesser &src) : poolFile(src.poolFile), poolId(src.poolId), position(0) { init(); poolFile->addAccesser(this); } template void TStaticPoolAccesser::init() const { startAddress=1; endAddress=0; cacheBuffer=NULL; dirty=false; cachedBlock=NULL; } template TStaticPoolAccesser::~TStaticPoolAccesser() { if(poolFile!=NULL) { try { CMutexLocker lock(poolFile->accesserInfoMutex); poolFile->unreferenceCachedBlock(this); } catch(...) { // ignore } poolFile->removeAccesser(this); } } template TStaticPoolAccesser &TStaticPoolAccesser::operator=(const TStaticPoolAccesser &rhs) { throw(runtime_error(string(__func__)+" -- it is invalid to assign TStaticPoolAccesser objects; the copy constructor must be used")); } template void TStaticPoolAccesser::seek(const l_addr_t where) { if(where>getSize()) throw(runtime_error(string(__func__)+" -- out of bounds: "+istring(where))); position=where; } template const typename TStaticPoolAccesser::l_addr_t TStaticPoolAccesser::tell() const { return(position); } template void TStaticPoolAccesser::read(pool_element_t buffer[],l_addr_t count) const { // there could be a problem here because the size could change AFTER the bounds have been checked if(count==0) return; if(position>getSize() || (getSize()-position)endAddress || position void TStaticPoolAccesser::write(const pool_element_t buffer[],const l_addr_t count) { overflowWrite(buffer,count,false); } template void TStaticPoolAccesser::overflowWrite(const pool_element_t buffer[],l_addr_t count,const bool append) { if(count==0) return; if(position>getSize()) throw(runtime_error(string(__func__)+" -- position parameter is out of bounds: "+istring(position))); if((getSize()-position)insertSpace(poolId,getSize(),overflow); } for(l_addr_t i=0;;) { if(position>endAddress || position void TStaticPoolAccesser::copyData(const l_addr_t destWhere,const TStaticPoolAccesser &src,const l_addr_t srcWhere,l_addr_t const length) { if(srcWhere>src.getSize()) throw(runtime_error(string(__func__)+" -- invalid srcWhere parameter: "+istring(srcWhere))); if((src.getSize()-srcWhere)getSize()) throw(runtime_error(string(__func__)+" -- invalid destWhere parameter: "+istring(destWhere))); if((getSize()-destWhere) void TStaticPoolAccesser::zeroData(const l_addr_t where,const l_addr_t length) { if((getSize()-where) void TStaticPoolAccesser::cacheBlock(const l_addr_t where) const { poolFile->cacheBlock(where,this); } #endif