// skip lots of string stuff, move to platform! bool Directx::IsOkay(HRESULT Error,const std::function<void(std::stringstream&)>& Context,bool ThrowException) { if ( Error == S_OK ) return true; std::stringstream ContextStr; Context( ContextStr ); return IsOkay( Error, ContextStr.str(), ThrowException ); }
int CCompressionStreambuf::sync() { if ( !IsOkay() ) { return -1; } int status = 0; // Sync write processor buffers CSP* sp = GetStreamProcessor(CCompressionStream::eWrite); if ( sp && sp->m_State != CSP::eDone && !(sp->m_State == CSP::eFinalize && sp->m_LastStatus == CP::eStatus_EndOfData) ) { if ( Sync(CCompressionStream::eWrite) != 0 ) { status = -1; } } // Sync the underlying stream status += m_Stream->rdbuf()->PUBSYNC(); return (status < 0 ? -1 : 0); }
streamsize CCompressionStreambuf::xsgetn(CT_CHAR_TYPE* buf, streamsize count) { // We don't doing here a check for the streambuf finalization because // underflow() can be called after Finalize() to read a rest of // produced data. if ( !IsOkay() || !m_Reader->m_Processor ) { return 0; } // Check parameters if ( !buf || count <= 0 ) { return 0; } // The number of chars copied streamsize done = 0; // Loop until all data are not read yet for (;;) { // Get the number of chars to write in this iteration size_t block_size = min(size_t(count-done), size_t(egptr()-gptr())); // Copy them if ( block_size ) { memcpy(buf + done, gptr(), block_size); done += block_size; // Update get pointers. // Satisfy "usual backup condition", see standard: 27.5.2.4.3.13 if ( block_size == size_t(egptr() - gptr()) ) { *m_Reader->m_OutBuf = buf[done - 1]; setg(m_Reader->m_OutBuf, m_Reader->m_OutBuf + 1, m_Reader->m_OutBuf + 1); } else { // Update the read pointer gbump((int)block_size); } } // Process block if necessary if ( done == count || !ProcessStreamRead() ) { break; } } return done; }
bool Platform::IsOkay(const std::string& Context,bool ThrowException) { return IsOkay( GetLastError(), Context, ThrowException ); }