• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ wxMemoryBuffer类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中wxMemoryBuffer的典型用法代码示例。如果您正苦于以下问题:C++ wxMemoryBuffer类的具体用法?C++ wxMemoryBuffer怎么用?C++ wxMemoryBuffer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: throw

// Read API
int clSocketBase::Read(wxMemoryBuffer& content, long timeout) throw(clSocketException)
{
    content.Clear();

    char buffer[4096];
    timeout = (timeout * 1000); // convert to MS
    while(true && timeout) {
        int rc = SelectReadMS(10);
        timeout -= 10;
        if(rc == kSuccess) {
            memset(buffer, 0x0, sizeof(buffer));
            int bytesRead = recv(m_socket, buffer, sizeof(buffer), 0);
            if(bytesRead < 0) {
                // Error
                throw clSocketException("Read failed: " + error());

            } else if(bytesRead == 0) {
                // connection closed
                return kError;

            } else {
                content.AppendData(buffer, bytesRead);
                continue;
            }
        } else {
            if(content.IsEmpty())
                continue; // keep waiting until time ends
            else
                return kSuccess; // we already read our content
        }
    }
    return kTimeout;
}
开发者ID:292388900,项目名称:codelite,代码行数:34,代码来源:clSocketBase.cpp


示例2: QueryValue

bool wxRegKey::QueryValue(const wxString& szValue, wxMemoryBuffer& buffer) const
{
  if ( CONST_CAST Open(Read) ) {
    // first get the type and size of the data
    DWORD dwType, dwSize;
    m_dwLastError = RegQueryValueEx((HKEY) m_hKey, RegValueStr(szValue),
                                    RESERVED,
                                    &dwType, NULL, &dwSize);

    if ( m_dwLastError == ERROR_SUCCESS ) {
        if ( dwSize ) {
            const RegBinary pBuf = (RegBinary)buffer.GetWriteBuf(dwSize);
            m_dwLastError = RegQueryValueEx((HKEY) m_hKey,
                                            RegValueStr(szValue),
                                            RESERVED,
                                            &dwType,
                                            pBuf,
                                            &dwSize);
            buffer.UngetWriteBuf(dwSize);
        } else {
            buffer.SetDataLen(0);
        }
    }


    if ( m_dwLastError != ERROR_SUCCESS ) {
      wxLogSysError(m_dwLastError, _("Can't read value of key '%s'"),
                    GetName().c_str());
      return false;
    }
    return true;
  }
  return false;
}
开发者ID:,项目名称:,代码行数:34,代码来源:


示例3: throw

void clSFTP::Write(const wxMemoryBuffer& fileContent, const wxString& remotePath) throw(clException)
{
    if(!m_sftp) {
        throw clException("SFTP is not initialized");
    }

    int access_type = O_WRONLY | O_CREAT | O_TRUNC;
    sftp_file file;
    wxString tmpRemoteFile = remotePath;
    tmpRemoteFile << ".codelitesftp";

    file = sftp_open(m_sftp, tmpRemoteFile.mb_str(wxConvUTF8).data(), access_type, 0644);
    if(file == NULL) {
        throw clException(wxString() << _("Can't open file: ") << tmpRemoteFile << ". "
                                     << ssh_get_error(m_ssh->GetSession()),
                          sftp_get_error(m_sftp));
    }

    char* p = (char*)fileContent.GetData();
    const int maxChunkSize = 65536;
    wxInt64 bytesLeft = fileContent.GetDataLen();

    while(bytesLeft > 0) {
        wxInt64 chunkSize = bytesLeft > maxChunkSize ? maxChunkSize : bytesLeft;
        wxInt64 bytesWritten = sftp_write(file, p, chunkSize);
        if(bytesWritten < 0) {
            sftp_close(file);
            throw clException(wxString() << _("Can't write data to file: ") << tmpRemoteFile << ". "
                                         << ssh_get_error(m_ssh->GetSession()),
                              sftp_get_error(m_sftp));
        }
        bytesLeft -= bytesWritten;
        p += bytesWritten;
    }
    sftp_close(file);

    // Unlink the original file if it exists
    bool needUnlink = false;
    {
        // Check if the file exists
        sftp_attributes attr = sftp_stat(m_sftp, remotePath.mb_str(wxConvISO8859_1).data());
        if(attr) {
            needUnlink = true;
            sftp_attributes_free(attr);
        }
    }

    if(needUnlink && sftp_unlink(m_sftp, remotePath.mb_str(wxConvUTF8).data()) < 0) {
        throw clException(wxString() << _("Failed to unlink file: ") << remotePath << ". "
                                     << ssh_get_error(m_ssh->GetSession()),
                          sftp_get_error(m_sftp));
    }

    // Rename the file
    if(sftp_rename(m_sftp, tmpRemoteFile.mb_str(wxConvUTF8).data(), remotePath.mb_str(wxConvUTF8).data()) < 0) {
        throw clException(wxString() << _("Failed to rename file: ") << tmpRemoteFile << " -> " << remotePath << ". "
                                     << ssh_get_error(m_ssh->GetSession()),
                          sftp_get_error(m_sftp));
    }
}
开发者ID:292388900,项目名称:codelite,代码行数:60,代码来源:cl_sftp.cpp


示例4: wxLogDebug

bool 
hoxChesscapePlayer::_ParseIncomingCommand( const wxMemoryBuffer& data,
										   wxString&       command,
										   wxString&       paramsStr ) const
{
    /* TODO: Force to convert the buffer to a string. */

    const wxString contentStr =
        wxString::FromUTF8( (const char*) data.GetData(), data.GetDataLen() );
    if ( data.GetDataLen() > 0 && contentStr.empty() ) // failed?
    {
        wxLogDebug("%s: *WARN* Fail to convert [%d] data to string.", 
            __FUNCTION__, data.GetDataLen());
        return false;
    }

	/* CHECK: The first character must be 0x10 */
	if ( contentStr.empty() || contentStr[0] != 0x10 )
	{
		wxLogDebug("%s: *WARN* Invalid command = [%s].", __FUNCTION__, contentStr.c_str());
		return false;
	}

	/* Chop off the 1st character */
	const wxString actualContent = contentStr.Mid(1);

	/* Extract the command and its parameters-string */
	command = actualContent.BeforeFirst( '=' );
	paramsStr = actualContent.AfterFirst('=');

	return true;  // success
}
开发者ID:DoBuiThao,项目名称:hoxchess,代码行数:32,代码来源:hoxChesscapePlayer.cpp


示例5: SetValue

bool wxRegKey::SetValue(const wxString& szValue, const wxMemoryBuffer& buffer)
{
#ifdef __TWIN32__
  wxFAIL_MSG("RegSetValueEx not implemented by TWIN32");
  return false;
#else
  if ( CONST_CAST Open() ) {
    m_dwLastError = RegSetValueEx((HKEY) m_hKey, RegValueStr(szValue),
                                  (DWORD) RESERVED, REG_BINARY,
                                  (RegBinary)buffer.GetData(),buffer.GetDataLen());
    if ( m_dwLastError == ERROR_SUCCESS )
      return true;
  }

  wxLogSysError(m_dwLastError, _("Can't set value of '%s'"),
                GetFullName(this, szValue));
  return false;
#endif
}
开发者ID:,项目名称:,代码行数:19,代码来源:


示例6: ReadAdmini

void Exword::ReadAdmini(wxMemoryBuffer& buffer)
{
    int rsp, length;
    char *data;
    exword_setpath(m_device, (uint8_t*)GetStoragePath().utf8_str().data(), 0);
    for (int i = 0; admini_list[i] != NULL; i++) {
        rsp = exword_get_file(m_device, (char*)admini_list[i], &data, &length);
        if (rsp == EXWORD_SUCCESS && length > 0) {
            buffer.AppendData(data, length);
            free(data);
            break;
        }
        free(data);
    }
}
开发者ID:brijohn,项目名称:exword_tools,代码行数:15,代码来源:ExwordDevice.cpp


示例7: Authenticate

bool Exword::Authenticate(wxString user, wxMemoryBuffer& key)
{
    bool success = false;
    int rsp;
    uint16_t count;
    exword_dirent_t *entries;
    exword_authchallenge_t c;
    exword_authinfo_t ai;
    exword_userid_t u;

    if (!IsConnected())
        return success;

    memcpy(c.challenge, key.GetData(), 20);
    memcpy(ai.blk1, "FFFFFFFFFFFFFFFF", 16);
    strncpy((char*)ai.blk2, user.utf8_str().data(), 24);
    strncpy(u.name, user.utf8_str().data(), 16);
    exword_setpath(m_device, (uint8_t*)"\\_INTERNAL_00", 0);
    rsp = exword_authchallenge(m_device, c);
    if (rsp == EXWORD_SUCCESS) {
        exword_setpath(m_device, (uint8_t*)"", 0);
        exword_list(m_device, &entries, &count);
        for (int i = 0; i < count; i++) {
            if (strcmp((const char*)entries[i].name, "_SD_00") == 0) {
                exword_setpath(m_device, (uint8_t*)"\\_SD_00", 0);
                rsp = exword_authchallenge(m_device, c);
                if (rsp != EXWORD_SUCCESS)
                    exword_authinfo(m_device, &ai);
             }
        }
        exword_free_list(entries);
        exword_userid(m_device, u);
        success = true;
    }
    return success;
}
开发者ID:brijohn,项目名称:exword_tools,代码行数:36,代码来源:ExwordDevice.cpp


示例8: wxASSERT

/*!
 The type wxJSONTYPE_MEMORYBUFF is a \b wxJSON extension that is not correctly read by
 other JSON implementations.
 By default, the function writes such a type as an array of INTs as follows:
 \code
   [ 0,32,45,255,6,...]
 \endcode
 If the writer object was constructed using the \c wxJSONWRITER_MEMORYBUFF flag, then
 the output is much more compact and recognized by the \b wxJSON reader as a memory buffer
 type:
 \code
   '00203FFF06..'
 \endcode

*/
int
wxJSONWriter::WriteMemoryBuff( wxOutputStream& os, const wxMemoryBuffer& buff )
{
#define MAX_BYTES_PER_ROW	20
    char str[16];

    // if STYLED and SPLIT_STRING flags are set, the function writes 20 bytes on every row
    // the following is the counter of bytes written.
    // the string is splitted only for the special meory buffer type, not for array of INTs
    int bytesWritten = 0;
    bool splitString = false;
    if ( (m_style & wxJSONWRITER_STYLED) && 
               (m_style & wxJSONWRITER_SPLIT_STRING))   {
        splitString = true;
    }

    size_t buffLen = buff.GetDataLen();
    unsigned char* ptr = (unsigned char*) buff.GetData();
    wxASSERT( ptr );
    char openChar = '\'';
    char closeChar = '\'';
    bool asArray = false;

    if ( (m_style & wxJSONWRITER_MEMORYBUFF ) == 0 )  {
        // if the special flag is not specified, write as an array of INTs
        openChar = '[';
        closeChar = ']';
        asArray = true;
    }
    // write the open character
    os.PutC( openChar );

    for ( size_t i = 0; i < buffLen; i++ )  {
        unsigned char c = *ptr;
        ++ptr;

        if ( asArray )  {
            snprintf( str, 14, "%d", c );
            size_t len = strlen( str );
            wxASSERT( len <= 3 );
            wxASSERT( len >= 1 );
            str[len] = ',';
            // do not write the comma char for the last element
            if ( i < buffLen - 1 )    {
                ++len;
            }
            os.Write( str, len );
            if ( os.GetLastError() != wxSTREAM_NO_ERROR )    {
                return -1;
            }
        }
        else {
            // now convert the byte in two hex digits
            char c1 = c / 16;
            char c2 = c % 16;
            c1 += '0';
            c2 += '0';
            if ( c1 > '9' )  {
                c1 += 7;
            }
            if ( c2 > '9' )  {
                c2 += 7;
            }
            os.PutC( c1 );
            os.PutC( c2 );
            if ( os.GetLastError() != wxSTREAM_NO_ERROR )    {
                return -1;
            }
            if ( splitString )  {
                ++bytesWritten;
            }

            if (( bytesWritten >= MAX_BYTES_PER_ROW ) && ((buffLen - i ) >= 5 ))   {
                // split the string if we wrote 20 bytes, but only is we have to
                // write at least 5 bytes
                os.Write( "\'\n", 2 );
                int lastChar = WriteIndent( os, m_level + 2 );     // write indentation
                os.PutC( '\'' );               // reopen quotes
                if ( lastChar < 0 )  {
                    return lastChar;
                }
                bytesWritten = 0;
            }
        }
    }
//.........这里部分代码省略.........
开发者ID:CarCode,项目名称:Cocoa-OCPN,代码行数:101,代码来源:jsonwriter.cpp


示例9: ODTCreateContentFile

void ODTExporter::ODTCreateContentFile(wxZipOutputStream &zout, const wxMemoryBuffer &styled_text, int lineCount, int tabWidth)
{
  const char *buffer = reinterpret_cast<char *>(styled_text.GetData());
  const size_t buffer_size = styled_text.GetDataLen();
  int lineno = 1;
  int width = calcWidth(lineCount);

  zout.PutNextEntry(_T("content.xml"));
  zout.Write(ODTContentFileBEG, strlen(ODTContentFileBEG));

  if (buffer_size)
  {
    char current_style = buffer[1];
    string content("<text:h text:style-name=\"Default\">");

    if (lineCount != -1)
    {
      int difWidth = width - calcWidth(lineno);

      if (difWidth > 0)
      {
        content += string("<text:s text:c=\"") + to_string(difWidth) + string("\"/>");
      }

      content += to_string(lineno);
      ++lineno;
      content += "<text:s text:c=\"2\"/>";
    }

    size_t first = 0;

    if (buffer_size > 0 && buffer[0] == ' ')
    {
      content += fix_spaces(buffer, &first, buffer_size, true);
    }

    if (current_style != 0)
    {
      content += string("<text:span text:style-name=\"style") + to_string(current_style) + string("\">");
    }

    int charLinePos = 0;

    for (size_t i = first; i < buffer_size; i += 2, ++charLinePos)
    {
      if (buffer[i + 1] != current_style)
      {
        if (!isspace(buffer[i]))
        {
          if (current_style != 0)
          {
            content += string("</text:span>");
          }

          current_style = buffer[i + 1];

          if (current_style != 0)
          {
            content += string("<text:span text:style-name=\"style") + to_string(current_style) + string("\">");
          }
        }
      }

      switch (buffer[i])
      {
        case '<':
          content += "&lt;";
          break;

        case '>':
          content += "&gt;";
          break;

        case '&':
          content += "&amp;";
          break;

        case '\'':
          content += "&apos;";
          break;

        case '"':
          content += "&quot;";
          break;

        case ' ':
          content += fix_spaces(buffer, &i, buffer_size);
          break;

        case '\t':
          {
            const int extraSpaces = tabWidth - charLinePos % tabWidth;
            size_t dummy = 0;
            const std::string extraSpacesStr(extraSpaces * 2, ' '); // imitates buffer (char + style)
            content += fix_spaces(extraSpacesStr.c_str(), &dummy, extraSpacesStr.size());
            charLinePos += extraSpaces - 1; // account for auto-increment
          }
          break;

        case '\r':
//.........这里部分代码省略.........
开发者ID:stahta01,项目名称:EmBlocks,代码行数:101,代码来源:ODTExporter.cpp


示例10: SetDictionary

bool wxZlibInputStream::SetDictionary(const wxMemoryBuffer &buf)
{
    return SetDictionary((char*)buf.GetData(), buf.GetDataLen());
}
开发者ID:vdm113,项目名称:wxWidgets-ICC-patch,代码行数:4,代码来源:zstream.cpp


示例11: wxCustomDataObject

Emfout::EMFDataObject::EMFDataObject(wxMemoryBuffer data) : wxCustomDataObject(m_emfFormat)
{
  SetData(data.GetBufSize(), data.GetData());
}
开发者ID:yurchor,项目名称:wxmaxima,代码行数:4,代码来源:EMFout.cpp


示例12: SetParamBlob

void PreparedStatement::SetParamBlob(int nPosition, const wxMemoryBuffer& buffer)
{
  SetParamBlob(nPosition, buffer.GetData(), buffer.GetBufSize());
}
开发者ID:05storm26,项目名称:codelite,代码行数:4,代码来源:PreparedStatement.cpp


示例13:

WebSocketMessage::WebSocketMessage(const wxMemoryBuffer &buffer)
{
	_type = WebSocketMessage::Binary;

	_content.AppendData(buffer.GetData(), buffer.GetDataLen());
}
开发者ID:,项目名称:,代码行数:6,代码来源:



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ wxMemoryDC类代码示例发布时间:2022-05-31
下一篇:
C++ wxMatrix2D类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap