本文整理汇总了C++中Shared::size方法的典型用法代码示例。如果您正苦于以下问题:C++ Shared::size方法的具体用法?C++ Shared::size怎么用?C++ Shared::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Shared
的用法示例。
在下文中一共展示了Shared::size方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: deserialize
void Dictionary::deserialize (Ref<IData> data)
{
Shared<Buffer> buffer = data->buffer();
std::size_t offset = 0;
while (offset < buffer->size()) {
KeyT key = TypeSerialization<TI_STRING>::read_from_buffer(*buffer, offset);
_values[key] = Value::read_from_buffer(*buffer, offset);
}
}
示例2: sizeof
static Ref<Image> load_jpeg_image (const Ptr<IData> data) {
jpeg_decompress_struct cinfo;
jpeg_error_mgr jerr;
Ref<Image> result_image;
DataType data_type = DataType::BYTE;
Shared<Buffer> buffer = data->buffer();
unsigned width, height;
try {
//memset (&cinfo, 0, sizeof (cinfo));
memset (&jerr, 0, sizeof (jerr));
cinfo.err = jpeg_std_error(&jerr);
jpeg_create_decompress(&cinfo);
jpeg_memory_src(&cinfo, buffer->begin(), buffer->size());
jpeg_read_header(&cinfo, TRUE);
width = cinfo.image_width;
height = cinfo.image_height;
unsigned row_width = 0;
PixelFormat pixel_format;
if (cinfo.jpeg_color_space == JCS_GRAYSCALE) {
row_width = width;
pixel_format = PixelFormat::L;
} else {
row_width = 3 * width;
pixel_format = PixelFormat::RGB;
}
result_image = new Image(Vec2u(width, height), pixel_format, data_type);
ByteT *line = result_image->data();
jpeg_start_decompress(&cinfo);
// read jpeg image
while (cinfo.output_scanline < cinfo.output_height) {
jpeg_read_scanlines(&cinfo, &line, 1);
line += row_width;
}
jpeg_finish_decompress(&cinfo);
jpeg_destroy_decompress(&cinfo);
} catch (std::exception &e) {
}
return result_image;
};
示例3: compile
GLenum ShaderManager::compile(GLenum type, const Buffer * buffer)
{
GLuint shader = glCreateShader(type);
const GLchar * source = (GLchar*)buffer->begin();
GLint length = (GLint)buffer->size();
glShaderSource(shader, 1, &source, &length);
check_graphics_error();
glCompileShader(shader);
check_graphics_error();
GLint log_length;
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &log_length);
if (log_length > 0) {
Shared<MutableBuffer> buffer = PackedBuffer::new_buffer(log_length);
glGetShaderInfoLog(shader, (GLsizei)buffer->size(), (GLsizei*)&log_length, (GLchar*)buffer->begin());
LogBuffer log_buffer;
log_buffer << "Error compiling shader:" << std::endl;
log_buffer << buffer->begin() << std::endl;
logger()->log(LOG_ERROR, log_buffer);
}
GLint status;
glGetShaderiv(shader, GL_COMPILE_STATUS, &status);
if (status == 0) {
logger()->log(LOG_ERROR, "Shader compilation failed!");
glDeleteShader(shader);
return 0;
}
check_graphics_error();
return shader;
}
示例4: LoadError
static Ref<Sound> load_wave_data (const Ptr<IData> data)
{
DecoderT decoder = NULL;
Shared<Buffer> buffer = data->buffer();
std::size_t i = 4;
uint32_t chunk_length;
int32_t magic;
i += buffer->read(i, chunk_length, LITTLE);
i += buffer->read(i, magic, BIG);
if (magic != 'WAVE')
throw LoadError("Could not load WAV data");
bool found_header;
uint16_t audio_format, channel_count, block_align, bits_per_sample;
uint32_t sample_frequency, byte_rate;
while (i < buffer->size()) {
i += buffer->read(i, magic, BIG);
i += buffer->read(i, chunk_length, LITTLE);
if (magic == 'fmt ') {
// Decode header
found_header = true;
i += buffer->read(i, audio_format, LITTLE);
i += buffer->read(i, channel_count, LITTLE);
i += buffer->read(i, sample_frequency, LITTLE);
i += buffer->read(i, byte_rate, LITTLE);
i += buffer->read(i, block_align, LITTLE);
i += buffer->read(i, bits_per_sample, LITTLE);
i += chunk_length - 16;
if (audio_format == 1) {
if (bits_per_sample == 8)
// Copy samples verbatim.
decoder = decode_linear_codec;
else
// Use PCM16 decoder - will pass through if endian doesn't need to be converted.
decoder = decode_pcm16_codec;
} else if (audio_format == 7) {
//bits_per_sample *= 2;
//decoder = decode_ulaw_codec;
throw LoadError("Unsupported WAV encoding (ULaw)");
} else {
throw LoadError("Unsupported WAV encoding (Unknown)");
}
} else if (magic == 'data') {
if (!found_header)
throw LoadError("Corrupt or truncated data");
StaticBuffer sample_data(&(*buffer)[i], chunk_length);
DREAM_ASSERT(decoder != NULL);
return decoder(&sample_data, channel_count, bits_per_sample, sample_frequency);
} else {
// Unknown header
i += chunk_length;
}
}
throw LoadError("Corrupt or truncated data");
}