/****************************************************************************** libx42pp - skinned vertex animation library (C++ API) Copyright (C) 2007 HermitWorks Entertainment Corporation This program 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. This program 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. 51 Franklin Street, Fifth Floor Boston, MA 02110-1301, USA. ******************************************************************************/ #include "local.h" namespace x42 { size_t InStream::Read( void *buf, size_t cb ) { size_t cbRead = 0; while( cb ) { size_t rc = ReadFn( buf, cb ); if( !rc ) break; cbRead += rc; cb -= rc; } return cbRead; } size_t InStream::ReadFn( void *buf, size_t cb ) { stm.read( (char*)buf, (std::streamsize)cb ); return (size_t)stm.gcount(); } size_t InStream::imp_read_fn( void *buffer, size_t cb, void *baton ) { InStream *thisobj = static_cast< InStream* >( baton ); return thisobj->ReadFn( buffer, cb ); } size_t OutStream::imp_write_fn( const void *buffer, size_t cb, void *baton ) { OutStream *thisobj = static_cast< OutStream* >( baton ); std::ostream::pos_type startpos = thisobj->stm.tellp(); thisobj->stm.write( (char*)buffer, (std::streamsize)cb ); return (size_t)thisobj->stm.tellp() - startpos; } /***** libx42 tmpMem */ TempMem::TempMem( size_t maxSize ) { innerMem = x42_CreateTempMem( maxSize ); demand( innerMem != NULL, ErrCode::OutOfMemory, "failed to create inner allocator" ); } TempMem::~TempMem( void ) { x42_FreeTempMem( innerMem ); } /***** libx42 CPU fast-path code */ OptData::OptData( void ) { size_t cb = x42_GetOptsSize(); demand( cb != 0, ErrCode::Internal, "couldn't compute opts data size" ); opt_buf.alloc( cb ); opt = x42_InitOpts( opt_buf.ptr() ); demand( opt != NULL, ErrCode::Internal, "failed to init opts" ); } OptBlock::OptBlock( OptData &opt ) : opt( opt ) { did_apply = x42_ApplyOpts( opt.opt ); } OptBlock::~OptBlock( void ) { if( did_apply ) x42_RemoveOpts( opt.opt ); } };