本文整理汇总了C++中StdStrBuf::getData方法的典型用法代码示例。如果您正苦于以下问题:C++ StdStrBuf::getData方法的具体用法?C++ StdStrBuf::getData怎么用?C++ StdStrBuf::getData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StdStrBuf
的用法示例。
在下文中一共展示了StdStrBuf::getData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SSearch
void C4Network2IRCChannel::OnUsers(const char *szUsers, const char *szPrefixes)
{
// Find actual prefixes
szPrefixes = SSearch(szPrefixes, ")");
// Reconstructs the list
if(!fReceivingUsers)
ClearUsers();
while(szUsers && *szUsers)
{
// Get user name
StdStrBuf PrefixedName = ircExtractPar(&szUsers);
// Remove prefix(es)
const char *szName = PrefixedName.getData();
if(szPrefixes)
while(strchr(szPrefixes, *szName))
szName++;
// Copy prefix
StdStrBuf Prefix;
Prefix.Copy(PrefixedName.getData(), szName - PrefixedName.getData());
// Add user
AddUser(szName)->SetPrefix(Prefix.getData());
}
// Set flag the user list won't get cleared again until OnUsersEnd is called
fReceivingUsers = true;
}
示例2: FileLock
bool C4Network2Res::SetByFile(const char *strFilePath, bool fTemp, C4Network2ResType eType, int32_t iResID, const char *szResName, bool fSilent)
{
CStdLock FileLock(&FileCSec);
// default resource name: relative path
if (!szResName) szResName = Config.AtRelativePath(strFilePath);
SCopy(strFilePath, szFile, sizeof(szFile)-1);
// group?
C4Group Grp;
if (Reloc.Open(Grp, strFilePath))
return SetByGroup(&Grp, fTemp, eType, iResID, szResName, fSilent);
// so it needs to be a file
StdStrBuf szFullFile;
if (!Reloc.LocateItem(szFile, szFullFile))
{ if (!fSilent) LogF("SetByFile: file %s not found!", strFilePath); return false; }
// calc checksum
uint32_t iCRC32;
if (!GetFileCRC(szFullFile.getData(), &iCRC32)) return false;
#ifdef C4NET2RES_DEBUG_LOG
// log
LogSilentF("Network: Resource: complete %d:%s is file %s (%s)", iResID, szResName, szFile, fTemp ? "temp" : "static");
#endif
// set core
Core.Set(eType, iResID, Config.AtRelativePath(szFullFile.getData()), iCRC32);
// set own data
fDirty = true;
fTempFile = fTemp;
fStandaloneFailed = false;
fRemoved = false;
iLastReqTime = time(NULL);
fLoading = false;
// ok
return true;
}
示例3: OpenLog
bool OpenLog()
{
// open
sLogFileName = C4CFN_Log; int iLog = 2;
#ifdef _WIN32
while (!(C4LogFile = _fsopen(Config.AtUserDataPath(sLogFileName.getData()), "wt", _SH_DENYWR)))
#elif defined(HAVE_SYS_FILE_H)
int fd = 0;
while (!(fd = open(Config.AtUserDataPath(sLogFileName.getData()), O_WRONLY | O_CREAT, 0644)) || flock(fd, LOCK_EX|LOCK_NB))
#else
while (!(C4LogFile = fopen(Config.AtUserDataPath(sLogFileName.getData()), "wb")))
#endif
{
// Already locked by another instance?
#if !defined(_WIN32) && defined(HAVE_SYS_FILE_H)
if (fd) close(fd);
#else
if (C4LogFile) fclose(C4LogFile);
#endif
// If the file does not yet exist, the directory is r/o
// don't go on then, or we have an infinite loop
if (access(Config.AtUserDataPath(sLogFileName.getData()), 0))
return false;
// try different name
sLogFileName.Format(C4CFN_LogEx, iLog++);
}
#if !defined(_WIN32) && defined(HAVE_SYS_FILE_H)
ftruncate(fd, 0);
C4LogFile = fdopen(fd, "wb");
#endif
// save start time
time(&C4LogStartTime);
return true;
}
示例4:
void C4Console::UpdateNetMenu()
{
// Active & network hosting check
if (!Active) return;
if (!::Network.isHost() || !::Network.isEnabled()) return;
// Clear old
ClearNetMenu();
// Insert menu
C4ConsoleGUI::AddNetMenu();
// Host
StdStrBuf str;
str.Format(LoadResStr("IDS_MNU_NETHOST"),Game.Clients.getLocalName(),Game.Clients.getLocalID());
AddNetMenuItemForPlayer(Game.Clients.getLocalID(), str.getData(), C4ConsoleGUI::CO_None);
// Clients
for (C4Network2Client *pClient=::Network.Clients.GetNextClient(nullptr); pClient; pClient=::Network.Clients.GetNextClient(pClient))
{
if (pClient->isHost()) continue;
str.Format(LoadResStr(pClient->isActivated() ? "IDS_MNU_NETCLIENT_DEACTIVATE" : "IDS_MNU_NETCLIENT_ACTIVATE"),
pClient->getName(), pClient->getID());
AddNetMenuItemForPlayer(pClient->getID(), str.getData(), pClient->isActivated() ? C4ConsoleGUI::CO_Deactivate : C4ConsoleGUI::CO_Activate);
str.Format(LoadResStr("IDS_NET_KICKCLIENTEX"), pClient->getName(), pClient->getID());
AddNetMenuItemForPlayer(pClient->getID(), str.getData(), C4ConsoleGUI::CO_Kick);
}
return;
}
示例5:
bool C4PlayerList::Save(C4Group &hGroup, bool fStoreTiny, const C4PlayerInfoList &rStoreList)
{
StdStrBuf sTempFilename;
bool fSuccess = true;
// Save to external player files and add to group
for (C4Player *pPlr=First; pPlr; pPlr=pPlr->Next)
{
// save only those in the list, and only those with a filename
C4PlayerInfo *pNfo = rStoreList.GetPlayerInfoByID(pPlr->ID);
if (!pNfo) continue;
if (!pNfo->GetFilename() || !*pNfo->GetFilename()) continue;;
// save over original file?
bool fStoreOnOriginal = (!fStoreTiny && pNfo->GetType() == C4PT_User);
// Create temporary file
sTempFilename.Copy(Config.AtTempPath(pNfo->GetFilename()));
if (fStoreOnOriginal)
if (!C4Group_CopyItem(pPlr->Filename, sTempFilename.getData()))
return false;
// Open group
C4Group PlrGroup;
if (!PlrGroup.Open(sTempFilename.getData(), !fStoreOnOriginal))
return false;
// Save player
if (!pPlr->Save(PlrGroup, true, fStoreOnOriginal)) return false;
PlrGroup.Close();
// Add temp file to group
if (!hGroup.Move(sTempFilename.getData(), pNfo->GetFilename())) return false;
}
return fSuccess;
}
示例6: loader
void C4Def::LoadMeshMaterials(C4Group &hGroup, C4DefGraphicsPtrBackup *gfx_backup)
{
// Load all mesh materials from this folder
C4DefAdditionalResourcesLoader loader(hGroup);
hGroup.ResetSearch();
char MaterialFilename[_MAX_PATH + 1]; *MaterialFilename = 0;
for (const auto &mat : mesh_materials)
{
::MeshMaterialManager.Remove(mat, &gfx_backup->GetUpdater());
}
mesh_materials.clear();
while (hGroup.FindNextEntry(C4CFN_DefMaterials, MaterialFilename, NULL, !!*MaterialFilename))
{
StdStrBuf material;
if (hGroup.LoadEntryString(MaterialFilename, &material))
{
try
{
StdStrBuf buf;
buf.Copy(hGroup.GetName());
buf.Append("/"); buf.Append(MaterialFilename);
auto new_materials = ::MeshMaterialManager.Parse(material.getData(), buf.getData(), loader);
mesh_materials.insert(new_materials.begin(), new_materials.end());
}
catch (const StdMeshMaterialError& ex)
{
DebugLogF("Failed to read material script: %s", ex.what());
}
}
}
}
示例7: LogSilent
bool LogSilent(const char *szMessage, bool fConsole) {
if (!Application.AssertMainThread()) return false;
// security
if (!szMessage) return false;
// add timestamp
time_t timenow;
time(&timenow);
StdStrBuf TimeMessage;
TimeMessage.SetLength(11 + SLen(szMessage) + 1);
strftime(TimeMessage.getMData(), 11 + 1, "[%H:%M:%S] ", localtime(&timenow));
// output until all data is written
const char *pSrc = szMessage;
do {
// timestamp will always be that length
char *pDest = TimeMessage.getMData() + 11;
// copy rest of message, skip tags
CMarkup Markup(false);
while (*pSrc) {
Markup.SkipTags(&pSrc);
// break on crlf
while (*pSrc == '\r') pSrc++;
if (*pSrc == '\n') {
pSrc++;
break;
}
// copy otherwise
if (*pSrc) *pDest++ = *pSrc++;
}
*pDest++ = '\n';
*pDest = '\0';
#ifdef HAVE_ICONV
StdStrBuf Line = Languages.IconvSystem(TimeMessage.getData());
#else
StdStrBuf &Line = TimeMessage;
#endif
// Save into log file
if (C4LogFile) {
fputs(Line.getData(), C4LogFile);
fflush(C4LogFile);
}
// Write to console
if (fConsole || Game.Verbose) {
#if defined(_DEBUG) && defined(_WIN32)
// debug: output to VC console
OutputDebugString(Line.getData());
#endif
fputs(Line.getData(), stdout);
fflush(stdout);
}
} while (*pSrc);
return true;
}
示例8: if
void C4Network2ResDlg::ListItem::Update(const C4Network2Res *pByRes)
{
// update progress label
iProgress = pByRes->getPresentPercent();
if (iProgress < 100)
{
StdStrBuf progress;
progress.Format("%d%%", iProgress);
if (pProgress)
pProgress->SetText(progress.getData());
else
{
pProgress = new C4GUI::Label(progress.getData(), GetBounds().Wdt - IconLabelSpacing, 0, ARight);
pProgress->SetToolTip(LoadResStr("IDS_NET_RESPROGRESS_DESC"));
AddElement(pProgress);
}
}
else if (pProgress) { delete pProgress; pProgress=NULL; }
// update disk icon
if (IsSavePossible())
{
if (!pSaveBtn)
{
pSaveBtn = new C4GUI::CallbackButtonEx<C4Network2ResDlg::ListItem, C4GUI::IconButton>(C4GUI::Ico_Save, GetToprightCornerRect(16,16,2,1), 0, this, &ListItem::OnButtonSave);
AddElement(pSaveBtn);
}
}
else if (pSaveBtn)
delete pSaveBtn;
}
示例9:
bool C4Language::Init()
{
// Clear (to allow clean re-init)
Clear();
// Make sure Language.ocg is unpacked (TODO: This won't work properly if Language.ocg is in system data path)
// Assume for now that Language.ocg is either at a writable location or unpacked already.
// TODO: Use all Language.c4gs that we find, and merge them.
// TODO: Use gettext instead?
StdStrBuf langPath;
C4Reloc::iterator iter;
for(iter = Reloc.begin(); iter != Reloc.end(); ++iter)
{
langPath.Copy((*iter).strBuf + DirSep + C4CFN_Languages);
if(ItemExists(langPath.getData()))
{
if(DirectoryExists(langPath.getData()))
break;
if(C4Group_UnpackDirectory(langPath.getData()))
break;
}
}
// Break if no language.ocg found
if(iter != Reloc.end())
{
// Look for available language packs in Language.ocg
C4Group *pPack;
char strPackFilename[_MAX_FNAME + 1], strEntry[_MAX_FNAME + 1];
if (PackDirectory.Open(langPath.getData()))
{
while (PackDirectory.FindNextEntry("*.ocg", strEntry))
{
sprintf(strPackFilename, "%s" DirSep "%s", C4CFN_Languages, strEntry);
pPack = new C4Group();
if (pPack->Open(strPackFilename))
{
Packs.RegisterGroup(*pPack, true, C4GSCnt_Language, false);
}
else
{
delete pPack;
}
}
}
// Now create a pack group for each language pack (these pack groups are child groups
// that browse along each pack to access requested data)
for (int iPack = 0; (pPack = Packs.GetGroup(iPack)); iPack++)
PackGroups.RegisterGroup(*(new C4Group), true, C4GSPrio_Base, C4GSCnt_Language);
}
// Load language infos by scanning string tables (the engine doesn't really need this at the moment)
InitInfos();
// Done
return true;
}
示例10: getChannel
void C4Network2IRCClient::OnMessage(bool fNotice, const char *szSender, const char *szTarget, const char *szText)
{
// Find channel, if not private.
C4Network2IRCChannel *pChan = NULL;
if(!SEqualNoCase(szTarget, Nick.getData()))
pChan = getChannel(szTarget);
// CTCP tagged data?
const char X_DELIM = '\001';
if(szText[0] == X_DELIM)
{
// Process messages (it's very rarely more than one, but the spec allows it)
const char *pMsg = szText + 1;
while(*pMsg)
{
// Find end
const char *pEnd = strchr(pMsg, X_DELIM);
if(!pEnd) pEnd = pMsg + SLen(pMsg);
// Copy CTCP query/reply, get tag
StdStrBuf CTCP; CTCP.Copy(pMsg, pEnd - pMsg);
StdStrBuf Tag; Tag.CopyUntil(CTCP.getData(), ' ');
const char *szData = SSearch(CTCP.getData(), " ");
StdStrBuf Sender; Sender.CopyUntil(szSender, '!');
// Process
if(SEqualNoCase(Tag.getData(), "ACTION"))
PushMessage(MSG_Action, szSender, szTarget, szData ? szData : "");
if(SEqualNoCase(Tag.getData(), "FINGER") && !fNotice)
{
StdStrBuf Answer;
if(Config.Registered())
{
Answer = Config.GetRegistrationData("Cuid");
}
else
{
Answer = LoadResStr("IDS_PRC_UNREGUSER");
}
Send("NOTICE", FormatString("%s :%cFINGER %s%c",
Sender.getData(), X_DELIM,
Answer.getData(),
X_DELIM).getData());
}
if(SEqualNoCase(Tag.getData(), "VERSION") && !fNotice)
Send("NOTICE", FormatString("%s :%cVERSION " C4ENGINECAPTION ":" C4VERSION ":" C4_OS "%c",
Sender.getData(), X_DELIM, X_DELIM).getData());
if(SEqualNoCase(Tag.getData(), "PING") && !fNotice)
Send("NOTICE", FormatString("%s :%cPING %s%c",
Sender.getData(), X_DELIM, szData, X_DELIM).getData());
// Get next message
pMsg = pEnd;
if(*pMsg == X_DELIM) pMsg++;
}
}
// Standard message (not CTCP tagged): Push
else
PushMessage(fNotice ? MSG_Notice : MSG_Message, szSender, szTarget, szText);
}
示例11: GetFilename
bool C4Network2Res::SetByCore(const C4Network2ResCore &nCore, bool fSilent, const char *szAsFilename, int32_t iRecursion) // by main thread
{
StdStrBuf sFilename;
// try open local file
const char *szFilename = szAsFilename ? szAsFilename : GetC4Filename(nCore.getFileName());
if (SetByFile(szFilename, false, nCore.getType(), nCore.getID(), nCore.getFileName(), fSilent))
{
// check contents checksum
if (Core.getContentsCRC() == nCore.getContentsCRC())
{
// set core
fDirty = true;
Core = nCore;
// ok then
return true;
}
}
// get and search for filename without specified folder (e.g., Castle.ocs when the opened game is Easy.ocf\Castle.ocs)
const char *szFilenameOnly = GetFilename(szFilename);
const char *szFilenameC4 = GetC4Filename(szFilename);
if (szFilenameOnly != szFilenameC4)
{
sFilename.Copy(szFilename, SLen(szFilename) - SLen(szFilenameC4));
sFilename.Append(szFilenameOnly);
if (SetByCore(nCore, fSilent, szFilenameOnly, Config.Network.MaxResSearchRecursion)) return true;
}
// if it could still not be set, try within all folders of root (ignoring special folders), and try as file outside the folder
// but do not recurse any deeper than set by config (default: One folder)
if (iRecursion >= Config.Network.MaxResSearchRecursion) return false;
StdStrBuf sSearchPath; const char *szSearchPath;
if (!iRecursion)
szSearchPath = Config.General.ExePath.getData();
else
{
sSearchPath.Copy(szFilename, SLen(szFilename) - SLen(szFilenameC4));
szSearchPath = sSearchPath.getData();
}
StdStrBuf sNetPath; sNetPath.Copy(Config.Network.WorkPath);
char *szNetPath = sNetPath.GrabPointer();
TruncateBackslash(szNetPath);
sNetPath.Take(szNetPath);
for (DirectoryIterator i(szSearchPath); *i; ++i)
if (DirectoryExists(*i))
if (!*GetExtension(*i)) // directories without extension only
if (!szNetPath || !*szNetPath || !ItemIdentical(*i, szNetPath)) // ignore network path
{
// search for complete name at subpath (e.g. MyFolder\Easy.ocf\Castle.ocs)
sFilename.Format("%s%c%s", *i, DirectorySeparator, szFilenameC4);
if (SetByCore(nCore, fSilent, sFilename.getData(), iRecursion + 1))
return true;
}
// file could not be found locally
return false;
}
示例12: defined
bool C4VectorFont::Init(C4Group &hGrp, const char *szFilename, C4Config &rCfg)
{
// name by file
Name.Copy(GetFilenameOnly(szFilename));
#if defined(_WIN32) && !defined(HAVE_FREETYPE)
// check whether group is directory or packed
if (!hGrp.IsPacked())
{
// it's open: use the file directly
SCopy(hGrp.GetFullName().getData(), FileName, _MAX_PATH);
AppendBackslash(FileName);
SAppend(szFilename, FileName);
if (!FileExists(FileName)) { *FileName=0; return false; }
fIsTempFile = false;
}
else
{
// it's packed: extract to temp path
SCopy(rCfg.AtTempPath(szFilename), FileName, _MAX_PATH);
// make sure the filename is not in use, in case multiple instances of the engine are run
if (FileExists(FileName))
{
RemoveExtension(FileName);
StdStrBuf sNewFilename;
for (int i=0; i<1000; ++i)
{
sNewFilename.Format("%s%x", FileName, (int)rand());
if (*GetExtension(szFilename))
{
sNewFilename.AppendChar('.');
sNewFilename.Append(GetExtension(szFilename));
}
if (!FileExists(sNewFilename.getData())) break;
}
SCopy(sNewFilename.getData(), FileName, _MAX_PATH);
}
if (!hGrp.ExtractEntry(szFilename, FileName)) { *FileName=0; return false; }
fIsTempFile = true;
}
// add the font resource
//if (!AddFontResourceEx(FileName, FR_PRIVATE, NULL)) requires win2k
if (!AddFontResource(FileName))
{
if (fIsTempFile) EraseFile(FileName);
*FileName='\0';
return false;
}
#else
if (!hGrp.LoadEntry(szFilename, Data)) return false;
#endif
// success
return true;
}
示例13: sizeof
void C4StartupMainDlg::OnNetJoin(const StdStrBuf &rsHostAddress)
{
// no IP given: No join
if (!rsHostAddress || !*rsHostAddress.getData()) return;
// set default startup parameters
*Game.ScenarioFilename=0;
SCopy("Objects.ocd", Game.DefinitionFilenames);
Game.NetworkActive = true;
Game.fLobby = true;
Game.fObserve = false;
SCopy(rsHostAddress.getData(), Game.DirectJoinAddress, sizeof(Game.DirectJoinAddress)-1);
// start with this set!
Application.OpenGame();
}
示例14: FormatString
GLenum C4Shader::AddTexCoord(const char *szName)
{
// Make sure we have enough space
assert(iTexCoords < C4Shader_MaxTexCoords);
if(iTexCoords >= C4Shader_MaxTexCoords)
return -1;
// Add slices
StdStrBuf Code = FormatString("gl_TexCoord[%d] = gl_MultiTexCoord%d;\n", iTexCoords, iTexCoords);
AddVertexSlice(C4Shader_Vertex_TexCoordPos, Code.getData());
Code.Format("#define %s gl_TexCoord[%d]\n", szName, iTexCoords);
AddFragmentSlice(-1, Code.getData());
return GL_TEXTURE0 + iTexCoords++;
}
示例15:
int C4Shader::ParsePosition(const char *szWhat, const char **ppPos)
{
const char *pPos = *ppPos;
while (isspace(*pPos)) pPos++;
// Expect a name
const char *pStart = pPos;
while (isalnum(*pPos)) pPos++;
StdStrBuf Name; Name.Copy(pStart, pPos - pStart);
// Lookup name
int iPosition = -1;
for (int i = 0; i < sizeof(C4SH_PosNames) / sizeof(*C4SH_PosNames); i++) {
if (SEqual(Name.getData(), C4SH_PosNames[i].Name)) {
iPosition = C4SH_PosNames[i].Position;
break;
}
}
if (iPosition == -1) {
ShaderLogF(" gl: Unknown slice position in %s: %s", szWhat, Name.getData());
return -1;
}
// Add modifier
while (isspace(*pPos)) pPos++;
if (*pPos == '+') {
int iMod, iModLen;
if (!sscanf(pPos+1, "%d%n", &iMod, &iModLen)) {
ShaderLogF(" gl: Invalid slice modifier in %s", szWhat);
return -1;
}
iPosition += iMod;
pPos += 1+iModLen;
}
if (*pPos == '-') {
int iMod, iModLen;
if (!sscanf(pPos+1, "%d%n", &iMod, &iModLen)) {
ShaderLogF(" gl: Invalid slice modifier in %s", szWhat);
return -1;
}
iPosition -= iMod;
pPos += 1+iModLen;
}
// Everything okay!
*ppPos = pPos;
return iPosition;
}