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


C++ qstring::clearOrCreate方法代码示例

本文整理汇总了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();
}
开发者ID:camgunz,项目名称:eternity,代码行数:43,代码来源:metaapi.cpp

示例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);   
}
开发者ID:doomtech,项目名称:eternity,代码行数:53,代码来源:mn_misc.cpp


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