本文整理汇总了C++中qstring::clearOrCreate方法的典型用法代码示例。如果您正苦于以下问题:C++ qstring::clearOrCreate方法的具体用法?C++ qstring::clearOrCreate怎么用?C++ qstring::clearOrCreate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qstring
的用法示例。
在下文中一共展示了qstring::clearOrCreate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getZoneSize
//
// MetaObject::toString
//
// Virtual method for conversion of metaobjects into strings. As with the prior
// C implementation, the returned string pointer is a static buffer and should
// not be cached. The default toString method creates a hex dump representation
// of the object. This should be pretty interesting in C++...
// 04/03/11: Altered to use new ZoneObject functionality so that the entire
// object, including all subclasses, are dumped properly. Really cool ;)
//
const char *MetaObject::toString() const
{
static qstring qstr;
size_t bytestoprint = getZoneSize();
const byte *data = reinterpret_cast<const byte *>(getBlockPtr());
qstr.clearOrCreate(128);
if(!bytestoprint) // Not a zone object? Can only dump the base class.
{
bytestoprint = sizeof(*this);
data = reinterpret_cast<const byte *>(this); // Not evil, I swear :P
}
while(bytestoprint)
{
int i;
// print up to 12 bytes on each line
for(i = 0; i < 12 && bytestoprint; ++i, --bytestoprint)
{
byte val = *data++;
char bytes[4] = { 0 };
sprintf(bytes, "%02x ", val);
qstr += bytes;
}
qstr += '\n';
}
return qstr.constPtr();
}
示例2: WriteCenteredText
//
// WriteCenteredText
//
// Local routine to draw centered messages. Candidate for
// absorption into future generalized font code. Rewritten
// 02/22/04 to use qstring module.
//
static void WriteCenteredText(char *message)
{
static qstring qstr;
char *rover;
const char *buffer;
int x, y;
int w, h;
qstr.clearOrCreate(128);
// rather than reallocate memory every time we draw it,
// use one buffer and increase the size as neccesary
// haleyjd 02/22/04: qstring handles this for us now
w = V_FontStringWidth(menu_font_normal, popup_message);
h = V_FontStringHeight(menu_font_normal, popup_message);
x = (SCREENWIDTH - w) / 2;
y = (SCREENHEIGHT - h) / 2;
qstr.clear();
rover = message;
if(popup_widget.prev) // up over another widget?
V_DrawBox(x - 8, y - 8, w + 16, h + 16);
while(*rover)
{
if(*rover == '\n')
{
buffer = qstr.constPtr();
x = (SCREENWIDTH - V_FontStringWidth(menu_font_normal, buffer)) / 2;
V_FontWriteText(menu_font_normal, buffer, x, y, &subscreen43);
qstr.clear(); // clear buffer
y += menu_font_normal->absh; // next line
}
else // add next char
qstr += *rover;
++rover;
}
// dont forget the last line.. prob. not \n terminated
buffer = qstr.constPtr();
x = (SCREENWIDTH - V_FontStringWidth(menu_font_normal, buffer)) / 2;
V_FontWriteText(menu_font_normal, buffer, x, y, &subscreen43);
}