⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 memfile.cpp

📁 彩信浏览器
💻 CPP
字号:
// This file is part of Ambulant Player, www.ambulantplayer.org.//// Copyright (C) 2003-2007 Stichting CWI, // Kruislaan 413, 1098 SJ Amsterdam, The Netherlands.//// Ambulant Player is free software; you can redistribute it and/or modify// it under the terms of the GNU Lesser General Public License as published by// the Free Software Foundation; either version 2.1 of the License, or// (at your option) any later version.//// Ambulant Player 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 Lesser General Public License for more details.//// You should have received a copy of the GNU Lesser General Public License// along with Ambulant Player; if not, write to the Free Software// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA/*  * @$Id: memfile.cpp,v 1.2 2007/02/12 14:15:02 jackjansen Exp $  */#include "ambulant/lib/memfile.h"using namespace ambulant;using namespace lib;typedef unsigned char byte;memfile::~memfile() {	if (m_src) m_src->release();	m_src = NULL;}boolmemfile::read() {	if (!m_src) return false;	char *data;	size_t datasize;	if (!net::read_data_from_datasource(m_src, &data, &datasize))		return false;	m_buffer.append((lib::byte*)data, datasize);	free(data);	m_src->release();	m_src = NULL;	return true;}memfile::size_typememfile::size() const { return m_buffer.size();}memfile::size_typememfile::available() const { return m_buffer.size() - m_gptr;}voidmemfile::seekg(size_type pos) { m_gptr = pos;}const lib::byte*memfile::data() const { return  m_buffer.data();}const lib::byte*memfile::begin() const { return  m_buffer.data();}const lib::byte*memfile::end() const { return  m_buffer.data() + size();}const lib::byte*memfile::gdata() { return m_buffer.data() + m_gptr;}lib::bytememfile::get() { 	if(!available()) #ifndef AMBULANT_PLATFORM_WIN32_WCE		throw_range_error();#else		return 0;#endif	byte b = *gdata(); 	m_gptr++; 	return b;}memfile::size_typememfile::read(lib::byte *b, size_type nb) {	size_type nr = available();	size_type nt = (nr>=nb)?nb:nr;	if(nt>0) {		memcpy(b, gdata(), nt);		m_gptr += nt;	}	return nt;}memfile::size_typememfile::skip(size_type nb) {	size_type nr = available();	size_type nt = (nr>=nb)?nb:nr;	if(nt>0) m_gptr += nt;	return nt;}unsigned shortmemfile::get_be_ushort() {	byte b[2];	if(read(b, 2) != 2)#ifndef AMBULANT_PLATFORM_WIN32_WCE		throw_range_error();#else		return 0;#endif	return (b[1]<<8)| b[0];}memfile::size_typememfile::read(char *b, size_type nb) {	return read((byte*)b, nb);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -