本文整理汇总了C++中AutoBuffer类的典型用法代码示例。如果您正苦于以下问题:C++ AutoBuffer类的具体用法?C++ AutoBuffer怎么用?C++ AutoBuffer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AutoBuffer类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: EnsureWriter
bool File::AddFile( const BString & ZipName, const BString & LocalFileName )
{
EnsureWriter();
AutoBuffer file;
if ( !Bootil::File::Read( LocalFileName, file ) )
{ return false; }
if ( ZR_OK != XZip::ZipAdd( ( XZip::HZIP )m_Write, ZipName.c_str(), file.GetBase(), file.GetWritten() ) )
{ return false; }
return true;
}
示例2: MakeMsgReq
bool NewSendCGITask::Req2Buf(uint32_t _taskid, void* const _user_context, AutoBuffer& _outbuffer, AutoBuffer& _extend, int& _error_code, const int _channel_select)
{
string reqProtobuf = MakeMsgReq();
DWORD dwCompressed = 0;
string body = nocompress_aes(pAuthInfo->m_Session, reqProtobuf);
if (!body.size()) return FALSE;
string header = MakeHeader(BaseHeader::s_cookie, m_nCgiType, reqProtobuf.size(), reqProtobuf.size());
string req = header + body;
_outbuffer.AllocWrite(req.size());
_outbuffer.Write(req.c_str(), req.size());
return TRUE;
}
示例3: Msg
void PackFile::Load( const Bootil::BString& strName )
{
Msg( "LoadinG File!! %s\n", strName.c_str() );
AutoBuffer buffer;
if ( !Bootil::File::Read( strName, buffer ) )
{
Warning( "C0ouldn;t oipen!\n" );
return;
}
buffer.SetPos( 0 );
// Check file signature
{
Bootil::BString strSig = buffer.ReadString();
Msg( "Signature [%s]\n", strSig.c_str() );
if ( strSig != "FILEPACK001" ) return;
}
unsigned int iOffset = 0;
while ( true )
{
if ( buffer.ReadType<unsigned char>() != 1 ) break;
unsigned int iSize = buffer.ReadType<unsigned int>();
Bootil::BString strName = buffer.ReadString();
Msg( "%s %i\n", strName.c_str(), iSize );
FileEntry fe;
fe.iLength = iSize;
fe.iStartPos = iOffset;
m_FileMap[ strName ] = fe;
iOffset+= iSize;
}
Msg( "End Pos Files: %i\n", iOffset );
Msg( "End Pos Actual: %i\n", buffer.GetWritten() - buffer.GetPos() );
// The left over data goes into m_Buffer
m_Buffer.Clear();
m_Buffer.Write( buffer.GetCurrent(), buffer.GetWritten() - buffer.GetPos() );
}
示例4:
template<typename _Tp, size_t fixed_size> inline
AutoBuffer<_Tp, fixed_size>::AutoBuffer(const AutoBuffer<_Tp, fixed_size>& abuf)
{
ptr = buf;
sz = fixed_size;
allocate(abuf.size());
for (size_t i = 0; i < sz; i++) {
ptr[i] = abuf.ptr[i];
}
}
示例5: png_create_write_struct
bool PngEncoder::write( const Mat& img, const vector<int>& params )
{
png_structp png_ptr = png_create_write_struct( PNG_LIBPNG_VER_STRING, 0, 0, 0 );
png_infop info_ptr = 0;
FILE* f = 0;
int y, width = img.cols, height = img.rows;
int depth = img.depth(), channels = img.channels();
bool result = false;
AutoBuffer<uchar*> buffer;
if( depth != CV_8U && depth != CV_16U )
return false;
if( png_ptr )
{
info_ptr = png_create_info_struct( png_ptr );
if( info_ptr )
{
if( setjmp( png_jmpbuf ( png_ptr ) ) == 0 )
{
if( m_buf )
{
png_set_write_fn(png_ptr, this,
(png_rw_ptr)writeDataToBuf, (png_flush_ptr)flushBuf);
}
else
{
f = fopen( m_filename.c_str(), "wb" );
if( f )
png_init_io( png_ptr, f );
}
int compression_level = -1; // Invalid value to allow setting 0-9 as valid
int compression_strategy = Z_RLE; // Default strategy
bool isBilevel = false;
for( size_t i = 0; i < params.size(); i += 2 )
{
if( params[i] == CV_IMWRITE_PNG_COMPRESSION )
{
compression_level = params[i+1];
compression_level = MIN(MAX(compression_level, 0), Z_BEST_COMPRESSION);
}
if( params[i] == CV_IMWRITE_PNG_STRATEGY )
{
compression_strategy = params[i+1];
compression_strategy = MIN(MAX(compression_strategy, 0), Z_FIXED);
}
if( params[i] == CV_IMWRITE_PNG_BILEVEL )
{
isBilevel = params[i+1] != 0;
}
}
if( m_buf || f )
{
if( compression_level >= 0 )
{
png_set_compression_level( png_ptr, compression_level );
}
else
{
// tune parameters for speed
// (see http://wiki.linuxquestions.org/wiki/Libpng)
png_set_filter(png_ptr, PNG_FILTER_TYPE_BASE, PNG_FILTER_SUB);
png_set_compression_level(png_ptr, Z_BEST_SPEED);
}
png_set_compression_strategy(png_ptr, compression_strategy);
png_set_IHDR( png_ptr, info_ptr, width, height, depth == CV_8U ? isBilevel?1:8 : 16,
channels == 1 ? PNG_COLOR_TYPE_GRAY :
channels == 3 ? PNG_COLOR_TYPE_RGB : PNG_COLOR_TYPE_RGBA,
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT,
PNG_FILTER_TYPE_DEFAULT );
png_write_info( png_ptr, info_ptr );
if (isBilevel)
png_set_packing(png_ptr);
png_set_bgr( png_ptr );
if( !isBigEndian() )
png_set_swap( png_ptr );
buffer.allocate(height);
for( y = 0; y < height; y++ )
buffer[y] = img.data + y*img.step;
png_write_image( png_ptr, buffer );
png_write_end( png_ptr, info_ptr );
result = true;
}
}
}
}
png_destroy_write_struct( &png_ptr, &info_ptr );
if(f) fclose( f );
//.........这里部分代码省略.........
示例6: skip_special_symbols
const char *string_to_attribute(const char *cfg,
AttributeType *out) {
const char *pcur = skip_special_symbols(cfg);
if (pcur[0] == '\'' || pcur[0] == '"') {
AutoBuffer buf;
uint8_t t1 = pcur[0];
int str_sz = 0;
pcur++;
while (*pcur != t1 && *pcur != '\0') {
pcur++;
str_sz++;
}
buf.write_bin(&cfg[1], str_sz);
pcur++;
out->make_string(buf.getBuffer());
} else if (pcur[0] == '[') {
pcur++;
pcur = skip_special_symbols(pcur);
AttributeType new_item;
out->make_list(0);
while (*pcur != ']' && *pcur != '\0') {
pcur = string_to_attribute(pcur, &new_item);
out->realloc_list(out->size() + 1);
(*out)[out->size() - 1] = new_item;
pcur = skip_special_symbols(pcur);
if (*pcur == ',') {
pcur++;
pcur = skip_special_symbols(pcur);
}
}
pcur++;
pcur = skip_special_symbols(pcur);
} else if (pcur[0] == '{') {
AttributeType new_key;
AttributeType new_value;
out->make_dict();
pcur++;
pcur = skip_special_symbols(pcur);
while (*pcur != '}' && *pcur != '\0') {
pcur = string_to_attribute(pcur, &new_key);
pcur = skip_special_symbols(pcur);
if (*pcur == ':') {
pcur++;
}
pcur = skip_special_symbols(pcur);
pcur = string_to_attribute(pcur, &new_value);
(*out)[new_key.to_string()] = new_value;
pcur = skip_special_symbols(pcur);
if (*pcur == ',') {
pcur++;
pcur = skip_special_symbols(pcur);
}
}
pcur++;
pcur = skip_special_symbols(pcur);
if (out->has_key("Type")) {
if (strcmp((*out)["Type"].to_string(), IFACE_SERVICE) == 0) {
IService *iserv;
iserv = static_cast<IService *>(
RISCV_get_service((*out)["ModuleName"].to_string()));
out->attr_free();
*out = AttributeType(iserv);
} else {
RISCV_printf(NULL, LOG_ERROR,
"Not implemented string to dict. attribute");
}
}
} else if (pcur[0] == '(') {
AutoBuffer buf;
char byte_value;
pcur++;
pcur = skip_special_symbols(pcur);
while (*pcur != ')' && *pcur != '\0') {
byte_value = 0;
for (int n = 0; n < 2; n++) {
if (*pcur >= 'A' && *pcur <= 'F') {
byte_value = (byte_value << 4) | ((*pcur - 'A') + 10);
} else {
byte_value = (byte_value << 4) | (*pcur - '0');
}
pcur++;
}
buf.write_bin(&byte_value, 1);
pcur = skip_special_symbols(pcur);
if (*pcur == ',') {
pcur++;
pcur = skip_special_symbols(pcur);
}
}
out->make_data(buf.size(), buf.getBuffer());
pcur++;
pcur = skip_special_symbols(pcur);
} else {
//.........这里部分代码省略.........
示例7: if
char *attribute_to_string(const AttributeType *attr) {
IService *iserv;
AutoBuffer *buf = &strBuffer;
if (attr->is_nil()) {
buf->write_string("None");
} else if (attr->is_int64() || attr->is_uint64()) {
buf->write_uint64(attr->to_uint64());
} else if (attr->is_string()) {
buf->write_string('\'');
buf->write_string(attr->to_string());
buf->write_string('\'');
} else if (attr->is_bool()) {
if (attr->to_bool()) {
buf->write_string("true");
} else {
buf->write_string("false");
}
} else if (attr->is_list()) {
AttributeType list_item;
unsigned list_sz = attr->size();
buf->write_string('[');
for (unsigned i = 0; i < list_sz; i++) {
list_item = (*attr)[i];
attribute_to_string(&list_item);
if (i < (list_sz - 1)) {
buf->write_string(',');
}
}
buf->write_string(']');
} else if (attr->is_dict()) {
AttributeType dict_item;
unsigned dict_sz = attr->size();;
buf->write_string('{');
for (unsigned i = 0; i < dict_sz; i++) {
buf->write_string('\'');
buf->write_string(attr->u_.dict[i].key_.to_string());
buf->write_string('\'');
buf->write_string(':');
const AttributeType &dict_value = (*attr)[i];
attribute_to_string(&dict_value);
if (i < (dict_sz - 1)) {
buf->write_string(',');
}
}
buf->write_string('}');
} else if (attr->is_data()) {
buf->write_string('(');
if (attr->size() > 0) {
for (unsigned n = 0; n < attr->size()-1; n++) {
buf->write_byte((*attr)(n));
buf->write_string(',');
}
buf->write_byte((*attr)(attr->size()-1));
}
buf->write_string(')');
} else if (attr->is_iface()) {
IFace *iface = attr->to_iface();
if (strcmp(iface->getFaceName(), IFACE_SERVICE) == 0) {
iserv = static_cast<IService *>(iface);
buf->write_string('{');
buf->write_string("'Type':'");
buf->write_string(iface->getFaceName());
buf->write_string("','ModuleName':'");
buf->write_string(iserv->getObjName());
buf->write_string("'}");
} else {
RISCV_printf(NULL, LOG_ERROR,
"Not implemented interface to dict. method");
}
}
return buf->getBuffer();
}
示例8:
char *AttributeType::to_config() {
strBuffer.clear();
attribute_to_string(this);
return strBuffer.getBuffer();
}