当前位置: 首页>>代码示例>>C++>>正文


C++ IODevice::read方法代码示例

本文整理汇总了C++中IODevice::read方法的典型用法代码示例。如果您正苦于以下问题:C++ IODevice::read方法的具体用法?C++ IODevice::read怎么用?C++ IODevice::read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IODevice的用法示例。


在下文中一共展示了IODevice::read方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1:

Error Commander::
readCommand(Command &cmd) {
	Error rc;
	IODevice *dd = d->device;
	assert(dd != 0);

	CommandHeader hdr;
	char *buf = 0;
	// Read header
	{
		size_t read_size;
		rc = dd->read((char *)&hdr,sizeof(hdr), &read_size);
		if (!rc.isSuccess()) {
			return rc;
		}
		if( read_size != sizeof(hdr)) {
			rc.setErrorType(Error::ERR_INVALID, "header corrupted");
			return rc;
		}
	}

	// Read command
	{
		buf = (char *)::malloc(hdr.length);
		int tried_times = 0;
		size_t offset = 0;
		size_t read_size;
		do {
			rc = dd->read( (char *)(buf + offset), hdr.length-offset, &read_size);
			if (!rc.isSuccess()) {
				goto out;
			}
			offset += read_size;
		}while(tried_times++ < 20 && offset < hdr.length);
	}
	{
		String name;
		std::vector<String> args;
		size_t offset = 0;

		name = buf;
		offset += ::strlen(buf)+1;


		while( (unsigned int)offset < (unsigned )hdr.length) {
			args.push_back(buf+offset);
			offset += ::strlen(buf+offset)+1;
		}

		cmd.setName(name);
		cmd.setArguments(args);
	}

	if (buf) ::free(buf);
	return rc;

	out:
	if (buf) ::free(buf);
	return rc;
}
开发者ID:simophin,项目名称:remotevision,代码行数:60,代码来源:Commander.cpp

示例2: load

void ZipFileHeader::load(IODevice &input)
{
	signature = input.read_int32();
	if (signature != 0x02014b50)
	{
		throw Exception("Incorrect File Header signature");
	}
	version_made_by = input.read_int16();
	version_needed_to_extract = input.read_int16();
	general_purpose_bit_flag = input.read_int16();
	compression_method = input.read_int16();
	last_mod_file_time = input.read_int16();
	last_mod_file_date = input.read_int16();
	crc32 = input.read_uint32();
	compressed_size = input.read_int32();
	uncompressed_size = input.read_int32();
	file_name_length = input.read_int16();
	extra_field_length = input.read_int16();
	file_comment_length = input.read_int16();
	disk_number_start = input.read_int16();
	internal_file_attributes = input.read_int16();
	external_file_attributes = input.read_int32();
	relative_offset_of_local_header = input.read_int32();
	filename.resize(file_name_length);

	auto str1 = new char[file_name_length];
	auto str2 = new char[extra_field_length];
	auto str3 = new char[file_comment_length];
	try
	{
		input.read(str1, file_name_length);
		input.read(str2, extra_field_length);
		input.read(str3, file_comment_length);
		if (general_purpose_bit_flag & ZIP_USE_UTF8)
		{
			filename = StringHelp::utf8_to_text(std::string(str1, file_name_length));
			file_comment = StringHelp::utf8_to_text(std::string(str3, file_comment_length));
		}
		else
		{
			filename = StringHelp::cp437_to_text(std::string(str1, file_name_length));
			file_comment = StringHelp::cp437_to_text(std::string(str3, file_comment_length));
		}

		extra_field = DataBuffer(str2, extra_field_length);

		delete[] str1;
		delete[] str2;
		delete[] str3;
	}
	catch (...)
	{
		delete[] str1;
		delete[] str2;
		delete[] str3;
		throw;
	}
}
开发者ID:ARMCoderCHS,项目名称:ClanLib,代码行数:58,代码来源:zip_file_header.cpp

示例3: font_face_load

	void FontFamily_Impl::font_face_load(const FontDescription &desc, const std::string &typeface_name, float pixel_ratio)
	{
#if defined(WIN32)
		std::shared_ptr<FontEngine> engine = std::make_shared<FontEngine_Win32>(desc, typeface_name, pixel_ratio);
		font_cache.push_back(Font_Cache(engine));
		font_cache.back().glyph_cache->set_texture_group(texture_group);
		font_cache.back().pixel_ratio = pixel_ratio;
#elif defined(__APPLE__)
		std::shared_ptr<FontEngine> engine = std::make_shared<FontEngine_Cocoa>(desc, typeface_name, pixel_ratio);
		font_cache.push_back(Font_Cache(engine));
		font_cache.back().glyph_cache->set_texture_group(texture_group);
		font_cache.back().pixel_ratio = pixel_ratio;
#elif defined(__ANDROID__)
		throw Exception("automatic typeface to ttf file selection is not supported on android");
#else

		// Obtain the best matching font file from fontconfig.
		FontConfig &fc = FontConfig::instance();
		std::string font_file_path = fc.match_font(typeface_name, desc);
		std::string path = PathHelp::get_fullpath(font_file_path, PathHelp::path_type_file);
		auto filename = PathHelp::get_filename(font_file_path, PathHelp::path_type_file);
		auto fs = FileSystem(path);
		IODevice file = fs.open_file(filename);
		DataBuffer font_databuffer;
		font_databuffer.set_size(file.get_size());
		file.read(font_databuffer.get_data(), font_databuffer.get_size());
		font_face_load(desc, font_databuffer, pixel_ratio);
#endif
	}
开发者ID:cosim,项目名称:ClanLib,代码行数:29,代码来源:font_family_impl.cpp

示例4: load

void SoundProvider_Vorbis_Impl::load(IODevice &input)
{
    int size = input.get_size();
    buffer = DataBuffer(size);
    int bytes_read = input.read(buffer.get_data(), buffer.get_size());
    buffer.set_size(bytes_read);
}
开发者ID:xubingyue,项目名称:ClanLib,代码行数:7,代码来源:soundprovider_vorbis.cpp

示例5: load

ShaderObject ShaderObject::load(GraphicContext &gc, ShaderType shader_type, IODevice &file)
{
	int size = file.get_size();
	std::string source(size, 0);
	file.read(&source[0], size);

	return ShaderObject(gc, shader_type, StringHelp::local8_to_text(source));
}
开发者ID:ARMCoderCHS,项目名称:ClanLib,代码行数:8,代码来源:shader_object.cpp

示例6: load

	void SoundProvider_Wave_Impl::load(IODevice &source)
	{
		source.set_little_endian_mode();

		char chunk_id[4];
		source.read(chunk_id, 4);
		if (memcmp(chunk_id, "RIFF", 4))
			throw Exception("Expected RIFF header!");
		uint32_t chunk_size = source.read_uint32();

		char format_id[4];
		source.read(format_id, 4);
		if (memcmp(format_id, "WAVE", 4))
			throw Exception("Expected WAVE header!");

		uint32_t subchunk_pos = source.get_position();
		uint32_t subchunk1_size = find_subchunk("fmt ", source, subchunk_pos, chunk_size);

		uint16_t audio_format = source.read_uint16();
		num_channels = source.read_uint16();
		frequency = source.read_uint32();
		uint32_t byte_rate = source.read_uint32();
		uint16_t block_align = source.read_uint16();
		uint16_t bits_per_sample = source.read_uint16();

		if (bits_per_sample == 16)
			format = sf_16bit_signed;
		else if (bits_per_sample == 8)
			format = sf_8bit_unsigned;
		else
			throw Exception("Unsupported wave sample format");

		uint32_t subchunk2_size = find_subchunk("data", source, subchunk_pos, chunk_size);

		data = new char[subchunk2_size];
		source.read(data, subchunk2_size);

		num_samples = subchunk2_size / block_align;
	}
开发者ID:keigen-shu,项目名称:ClanLib,代码行数:39,代码来源:soundprovider_wave.cpp

示例7: find_subchunk

	unsigned int SoundProvider_Wave_Impl::find_subchunk(const char *chunk, IODevice &source, unsigned int file_offset, unsigned int max_offset)
	{
		char subchunk1_id[4];

		max_offset -= 8;	// Each subchunk must contains at least name and size
		while (file_offset < max_offset)
		{
			source.seek(file_offset);
			source.read(subchunk1_id, 4);
			uint32_t subchunk1_size = source.read_uint32();
			if (!memcmp(subchunk1_id, chunk, 4))
			{
				// Found chunk
				return subchunk1_size;
			}
			file_offset += subchunk1_size + 8;
		}

		throw Exception("Block not found!");
	}
开发者ID:keigen-shu,项目名称:ClanLib,代码行数:20,代码来源:soundprovider_wave.cpp

示例8: add_sheet

void CSSDocument::add_sheet(CSSSheetOrigin origin, const std::string &filename, const FileSystem &fs)
{
	// Load the css document:
	IODevice file = fs.open_file(filename);
	DataBuffer file_data(file.get_size());
	file.read(file_data.get_data(), file_data.get_size());
	std::string css_text(file_data.get_data(), file_data.get_size());

	// Find the base URI for this css document:
	std::string base_uri = PathHelp::get_fullpath(filename);

	// Find import directives and load those first:
	std::vector<std::string> import_urls = CSSTokenizer(css_text).read_import_urls();
	for (size_t i = 0; i < import_urls.size(); i++)
	{
		add_sheet(origin, PathHelp::combine(base_uri, import_urls[i]), fs);
	}

	// Add the css sheet:
	CSSTokenizer tokenizer(css_text);
	impl->sheets.push_back(std::shared_ptr<CSSDocumentSheet>(new CSSDocumentSheet(origin, tokenizer, base_uri)));
}
开发者ID:Cassie90,项目名称:ClanLib,代码行数:22,代码来源:css_document.cpp


注:本文中的IODevice::read方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。