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


C++ StdBuf类代码示例

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


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

示例1: excNotFound

StdStrBuf StdCompilerConfigRead::ReadString()
{
	// Virtual key?
	if (pKey->Virtual)
		{ excNotFound("Could not read value %s! Parent key doesn't exist!", pKey->Name.getData()); return StdStrBuf(); }
	// Wrong type?
	if (pKey->Type != REG_SZ)
		{ excNotFound("Wrong value type!"); return StdStrBuf(); }
	// Get size of string
	DWORD iSize;
	if (RegQueryValueExW(pKey->Parent->Handle, pKey->Name.GetWideChar(),
	                    0, NULL,
	                    NULL,
	                    &iSize) != ERROR_SUCCESS)
		{ excNotFound("Could not read value %s!", pKey->Name.getData()); return StdStrBuf(); }
	// Allocate string
	StdBuf Result; Result.SetSize(iSize);
	// Read
	if (RegQueryValueExW(pKey->Parent->Handle, pKey->Name.GetWideChar(),
	                    0, NULL,
	                    reinterpret_cast<BYTE *>(Result.getMData()),
	                    &iSize) != ERROR_SUCCESS)
		{ excNotFound("Could not read value %s!", pKey->Name.getData()); return StdStrBuf(); }
	// Check size
	if (wcslen(getBufPtr<wchar_t>(Result)) + 1 != iSize / sizeof(wchar_t))
		{ excCorrupt("Wrong size of a string!"); return StdStrBuf(); }
	return StdStrBuf(getBufPtr<wchar_t>(Result));
}
开发者ID:sarah-russell12,项目名称:openclonk,代码行数:28,代码来源:StdRegistry.cpp

示例2: if

size_t C4AulDebug::UnpackPacket(const StdBuf &rInBuf, const C4NetIO::addr_t &addr)
{
	// Find line separation
	const char *pSep = reinterpret_cast<const char *>(memchr(rInBuf.getData(), '\n', rInBuf.getSize()));
	if (!pSep)
		return 0;
	// Check if it's windows-style separation
	int iSize = pSep - getBufPtr<char>(rInBuf) + 1,
	            iLength = iSize - 1;
	if (iLength && *(pSep - 1) == '\r')
		iLength--;
	// Copy the line
	StdStrBuf Buf; Buf.Copy(getBufPtr<char>(rInBuf), iLength);
	// Password line?
	if (fConnected)
	{
		ProcessLineResult result = ProcessLine(Buf);
		// Send answer
		SendLine(result.okay ? "OK" : "ERR", result.answer.length() > 0 ? result.answer.c_str() : NULL);
	}
	else if (!Password.getSize() || Password == Buf)
	{
		fConnected = true;
		SendLine("HLO", "This is " C4ENGINECAPTION ", " C4VERSION);
		Log("C4Aul debugger connected successfully!");
	}
	else
		C4NetIOTCP::Close(PeerAddr);
	// Consume line
	return iSize;
}
开发者ID:sarah-russell12,项目名称:openclonk,代码行数:31,代码来源:C4AulDebug.cpp

示例3: GetID

StdBuf C4NetpuncherPacketID<TYPE>::PackInto() const {
	StdBuf buf;
	auto id = GetID();
	buf.New(sizeof(id));
	buf.Write(&id, sizeof(id));
	return buf;
}
开发者ID:Fulgen301,项目名称:openclonk,代码行数:7,代码来源:C4PuncherPacket.cpp

示例4: SSearch

size_t C4Network2IRCClient::UnpackPacket(const StdBuf &rInBuf, const C4NetIO::addr_t &addr)
	{
	// Find line seperation
 	const char *pSep = reinterpret_cast<const char *>(memchr(rInBuf.getData(), '\n', rInBuf.getSize()));
	if(!pSep)
		return 0;
	// Check if it's actually correct seperation (rarely the case)
	int iSize = pSep - getBufPtr<char>(rInBuf) + 1,
			iLength = iSize - 1;
	if(iLength && *(pSep - 1) == '\r')
		iLength--;
	// Copy the line
	StdStrBuf Buf; Buf.Copy(getBufPtr<char>(rInBuf), iLength);
	// Ignore prefix
	const char *pMsg = Buf.getData();
	StdStrBuf Prefix;
	if(*pMsg == ':')
		{
		Prefix.CopyUntil(pMsg + 1, ' ');
		pMsg += Prefix.getLength() + 1;
		}
	// Strip whitespace
	while(*pMsg == ' ')
		pMsg++;
	// Ignore empty message
	if(!*pMsg)
		return iSize;
	// Get command
	StdStrBuf Cmd; Cmd.CopyUntil(pMsg, ' ');
	// Precess command
	const char *szParameters = SSearch(pMsg, " ");
	OnCommand(Prefix.getData(), Cmd.getData(), szParameters ? szParameters : "");
	// Consume the line
	return iSize;
	}
开发者ID:Marko10-000,项目名称:clonk-rage,代码行数:35,代码来源:C4Network2IRC.cpp

示例5: GetStringLength

void StdCompilerINIRead::String(char **pszString, RawCompileType eType)
{
	// Get length
	size_t iLength = GetStringLength(eType);
	// Read data
	StdBuf Buf = ReadString(iLength, eType, true);
	// Set
	*pszString = reinterpret_cast<char *>(Buf.GrabPointer());
}
开发者ID:notprathap,项目名称:openclonk-5.4.1-src,代码行数:9,代码来源:StdCompiler.cpp

示例6:

BOOL C4Scenario::Save(C4Group &hGroup, bool fSaveSection)
	{
	char *Buffer; int32_t BufferSize;
	if (!Decompile(&Buffer,&BufferSize, fSaveSection)) 
		return FALSE;
	if (!hGroup.Add(C4CFN_ScenarioCore,Buffer,BufferSize,FALSE,TRUE))
		{ StdBuf Buf; Buf.Take(Buffer, BufferSize); return FALSE; }
	return TRUE;
	}
开发者ID:lluchs,项目名称:clonk-rage,代码行数:9,代码来源:C4Scenario.cpp

示例7: WriteString

void StdCompilerConfigWrite::WriteString(const char *szString)
{
	// Append or set the value
	if (LastString.getLength()) LastString.Append(szString); else LastString.Copy(szString);
	StdBuf v = LastString.GetWideCharBuf();
	if (RegSetValueExW(pKey->Parent->Handle, pKey->Name.GetWideChar(),
	                  0, REG_SZ, getBufPtr<BYTE>(v), v.getSize()) != ERROR_SUCCESS)
		excCorrupt("Could not write key %s!", pKey->Name.getData());
}
开发者ID:sarah-russell12,项目名称:openclonk,代码行数:9,代码来源:StdRegistry.cpp

示例8: ReadString

void StdCompilerINIRead::Raw(void *pData, size_t iSize, RawCompileType eType)
{
	// Read data
	StdBuf Buf = ReadString(iSize, eType, false);
	// Correct size?
	if (Buf.getSize() != iSize)
		Warn("got %u bytes raw data, but %u bytes expected!", Buf.getSize(), iSize);
	// Copy
	MemCopy(Buf.getData(), pData, iSize);
}
开发者ID:notprathap,项目名称:openclonk-5.4.1-src,代码行数:10,代码来源:StdCompiler.cpp

示例9: sizeof

StdBuf C4NetpuncherPacketCReq::PackInto() const {
	StdBuf buf;
	auto sin6 = static_cast<sockaddr_in6>(addr.AsIPv6());
	auto port = addr.GetPort();
	buf.New(sizeof(port) + sizeof(sin6.sin6_addr));
	size_t offset = 0;
	buf.Write(&port, sizeof(port), offset);
	offset += sizeof(port);
	buf.Write(&sin6.sin6_addr, sizeof(sin6.sin6_addr), offset);
	static_assert(sizeof(sin6.sin6_addr) == 16, "expected sin6_addr to be 16 bytes");
	return buf;
}
开发者ID:Fulgen301,项目名称:openclonk,代码行数:12,代码来源:C4PuncherPacket.cpp

示例10:

void C4Network2IRCClient::PackPacket(const C4NetIOPacket &rPacket, StdBuf &rOutBuf)
	{
	// Enlarge buffer
	int iSize = rPacket.getSize(),
			iPos = rOutBuf.getSize();
	rOutBuf.Grow(iSize + 2);
	// Write packet
	rOutBuf.Write(rPacket, iPos);
	// Terminate
	uint8_t *pPos = getMBufPtr<uint8_t>(rOutBuf, iPos + iSize);
	*pPos = '\r'; *(pPos + 1) = '\n';
	}
开发者ID:Marko10-000,项目名称:clonk-rage,代码行数:12,代码来源:C4Network2IRC.cpp

示例11: sFileContentsString

bool C4KeyboardInput::LoadCustomConfig()
{
    // load from INI file (2do: load from registry)
    C4Group GrpExtra;
    if (!GrpExtra.Open(C4CFN_Extra)) return false;
    StdBuf sFileContents;
    if (!GrpExtra.LoadEntry(C4CFN_KeyConfig, &sFileContents)) return false;
    StdStrBuf sFileContentsString((const char *) sFileContents.getData());
    if (!CompileFromBuf_LogWarn<StdCompilerINIRead>(*this, sFileContentsString, "Custom keys from" C4CFN_Extra DirSep C4CFN_KeyConfig))
        return false;
    LogF(LoadResStr("IDS_PRC_LOADEDKEYCONF"), C4CFN_Extra DirSep C4CFN_KeyConfig);
    return true;
}
开发者ID:Rocket-Fish,项目名称:openclonk,代码行数:13,代码来源:C4KeyboardInput.cpp

示例12: SCopy

BOOL C4SoundEffect::Load(const char *szFileName, C4Group &hGroup,
                         BOOL fStatic) {
  // Sound check
  if (!Config.Sound.RXSound) return FALSE;
  // Locate sound in file
  StdBuf WaveBuffer;
  if (!hGroup.LoadEntry(szFileName, WaveBuffer)) return FALSE;
  // load it from mem
  if (!Load((BYTE *)WaveBuffer.getData(), WaveBuffer.getSize(), fStatic))
    return FALSE;
  // Set name
  SCopy(szFileName, Name, C4MaxSoundName);
  return TRUE;
}
开发者ID:ev1313,项目名称:yaC,代码行数:14,代码来源:C4SoundSystem.cpp

示例13: notFound

StdBuf StdCompilerINIRead::ReadString(size_t iLength, RawCompileType eRawType, bool fAppendNull)
{
	// Excpect valid position
	if (!pPos)
		{ notFound("String"); return StdBuf(); }
	// Skip whitespace
	SkipWhitespace();
	// Escaped? Go over '"'
	if (eRawType == RCT_Escaped && *pPos++ != '"')
		{ notFound("Escaped string"); return StdBuf(); }
	// Create buffer
	StdBuf OutBuf; OutBuf.New(iLength + (fAppendNull ? sizeof('\0') : 0));
	// Read
	char *pOut = getMBufPtr<char>(OutBuf);
	while (iLength && !TestStringEnd(eRawType))
	{
		// Read a character
		if (eRawType == RCT_Escaped)
			*pOut++ = ReadEscapedChar();
		else
			*pOut++ = *pPos++;
		// Count it
		iLength--;
	}
	// Escaped: Go over '"'
	if (eRawType == RCT_Escaped)
	{
		while (*pPos != '"')
		{
			if (!*pPos || *pPos == '\n' || *pPos == '\r')
			{
				Warn("string not terminated!");
				pPos--;
				break;
			}
			pPos++;
		}
		pPos++;
	}
	// Nothing read? Identifiers need to be non-empty
	if (pOut == OutBuf.getData() && (eRawType == RCT_Idtf || eRawType == RCT_ID))
		{ notFound("String"); return StdBuf(); }
	// Append null
	if (fAppendNull)
		*pOut = '\0';
	// Shrink, if less characters were read
	OutBuf.Shrink(iLength);
	// Done
	return OutBuf;
}
开发者ID:notprathap,项目名称:openclonk-5.4.1-src,代码行数:50,代码来源:StdCompiler.cpp

示例14: GetDbgRecPktData

StdStrBuf GetDbgRecPktData(C4RecordChunkType eType, const StdBuf &RawData) {
  StdStrBuf r;
  switch (eType) {
    case RCT_AulFunc:
      r.Ref(reinterpret_cast<const char *>(RawData.getData()),
            RawData.getSize() - 1);
      break;
    default:
      for (int i = 0; i < RawData.getSize(); ++i)
        r.AppendFormat("%02x ", (uint32_t)((uint8_t *)RawData.getData())[i]);
      break;
  }
  return r;
}
开发者ID:ev1313,项目名称:clonk-rage,代码行数:14,代码来源:C4Record.cpp

示例15: mkInsertAdapt

bool C4Record::StreamFile(const char *szLocalFilename, const char *szAddAs) {
  // Load file into memory
  StdBuf FileData;
  if (!FileData.LoadFromFile(szLocalFilename)) return false;

  // Prepend name
  StdBuf Packed = DecompileToBuf<StdCompilerBinWrite>(
      mkInsertAdapt(StdStrBuf(szAddAs), FileData, false));

  // Add to stream
  C4RecordChunkHead Head = {0, RCT_File};
  Stream(Head, Packed);
  return true;
}
开发者ID:ev1313,项目名称:clonk-rage,代码行数:14,代码来源:C4Record.cpp


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