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


C++ DataItem::getCategory方法代码示例

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


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

示例1: printSample

string XmlPrinter::printSample(const unsigned int instanceId,
                               const unsigned int bufferSize,
                               const uint64_t nextSeq,
                               const uint64_t firstSeq,
                               const uint64_t lastSeq,
                               ComponentEventPtrArray& results
  )
{
  xmlTextWriterPtr writer;
  xmlBufferPtr buf;
  string ret;
  
  try {
    THROW_IF_XML2_NULL(buf = xmlBufferCreate());
    THROW_IF_XML2_NULL(writer = xmlNewTextWriterMemory(buf, 0));
    THROW_IF_XML2_ERROR(xmlTextWriterSetIndent(writer, 1));
    THROW_IF_XML2_ERROR(xmlTextWriterSetIndentString(writer, BAD_CAST "  "));
    
    initXmlDoc(writer, eSTREAMS,
               instanceId,
               bufferSize,
               0, 0,
               nextSeq,
               firstSeq,
               lastSeq);
        
    THROW_IF_XML2_ERROR(xmlTextWriterStartElement(writer, BAD_CAST "Streams"));
    
    // Sort the vector by category.
    if (results.size() > 1)
      dlib::qsort_array<ComponentEventPtrArray,EventComparer>(results, 0, results.size() - 1, EventCompare);

    Device *lastDevice = NULL;
    Component *lastComponent = NULL;
    int lastCategory = -1;
    
    for (unsigned int i = 0; i < results.size(); i++)
    {
      ComponentEventPtr result = results[i];
      DataItem *dataItem = result->getDataItem();
      Component *component = dataItem->getComponent();
      Device *device = component->getDevice();
      
      if (device != lastDevice)
      {
        if (lastDevice != NULL)
          THROW_IF_XML2_ERROR(xmlTextWriterEndElement(writer)); // DeviceStream
        lastDevice = device;
        if (lastComponent != NULL)
          THROW_IF_XML2_ERROR(xmlTextWriterEndElement(writer)); // ComponentStream
        lastComponent = NULL;
        if (lastCategory != -1)
          THROW_IF_XML2_ERROR(xmlTextWriterEndElement(writer)); // Category
        lastCategory = -1;
        addDeviceStream(writer, device);
      }
      
      if (component != lastComponent)
      {
        if (lastComponent != NULL)
          THROW_IF_XML2_ERROR(xmlTextWriterEndElement(writer)); // ComponentStream
        lastComponent = component;
        if (lastCategory != -1)
          THROW_IF_XML2_ERROR(xmlTextWriterEndElement(writer)); // Category
        lastCategory = -1;
        addComponentStream(writer, component);        
      }
      
      if (lastCategory != dataItem->getCategory())
      {
        if (lastCategory != -1)
          THROW_IF_XML2_ERROR(xmlTextWriterEndElement(writer)); // Category
        lastCategory = dataItem->getCategory();
        addCategory(writer, dataItem->getCategory());
      }
      
      addEvent(writer, result);
    }
    
    if (lastCategory != -1)
      THROW_IF_XML2_ERROR(xmlTextWriterEndElement(writer)); // Category
    if (lastDevice != NULL)
      THROW_IF_XML2_ERROR(xmlTextWriterEndElement(writer)); // DeviceStream
    if (lastComponent != NULL)
      THROW_IF_XML2_ERROR(xmlTextWriterEndElement(writer)); // ComponentStream
    
    THROW_IF_XML2_ERROR(xmlTextWriterEndElement(writer)); // Streams    
    THROW_IF_XML2_ERROR(xmlTextWriterEndElement(writer)); // MTConnectStreams
    THROW_IF_XML2_ERROR(xmlTextWriterEndDocument(writer));
    
    xmlFreeTextWriter(writer);
    ret = (string) ((char*) buf->content);
    xmlBufferFree(buf);    
  }
  catch (string error) {
    if (buf != NULL)
      xmlBufferFree(buf);
    if (writer != NULL)
      xmlFreeTextWriter(writer);
    sLogger << dlib::LERROR << "printProbe: " << error;
//.........这里部分代码省略.........
开发者ID:ehrhardttool,项目名称:cppagent-master,代码行数:101,代码来源:xml_printer.cpp


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