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


C++ MessageQueue::append方法代码示例

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


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

示例1: MessageQueue

int
main(int argc, char **argv)
{

  unsigned int id;
  MessageQueue *mq = new MessageQueue();

  cout << "Message queue initialized, now appending three test messages" << endl;

  TestInterface::SetTestIntMessage *m1 = new TestInterface::SetTestIntMessage(1);
  TestInterface::SetTestIntMessage *m2 = new TestInterface::SetTestIntMessage(2);
  TestInterface::SetTestIntMessage *m3 = new TestInterface::SetTestIntMessage(3);
  TestInterface::SetTestStringMessage *m4 = new TestInterface::SetTestStringMessage();
  id = mq->append(m1);
  cout << "m1 added with id " << id << endl;
  id = mq->append(m1);
  cout << "m1 added with id " << id << endl;
  id = mq->append(m2);
  cout << "m2 added with id " << id << endl;
  id = mq->append(m3);
  cout << "m3 added with id " << id << endl;
  id = mq->append(m4);
  cout << "m4 (of different type!) added with id " << id << endl;

  cout << "Size is now " << mq->size() << endl;

  cout << "Unreferencing messages" << endl;
  m1->unref();
  m2->unref();
  m3->unref();
  m4->unref();

  cout << "Appending m1 again" << endl;
  id = mq->append(m1);
  cout << "m1 added with id " << id << endl;
  cout << "Size is now " << mq->size() << endl;
  cout << "m1 refcount is now " << m1->refcount() << endl;

  printMessages(mq);

  cout << "Now removing message m1 once" << endl;
  mq->remove(m1);
  printMessages(mq);


  cout << "m1 has refcount " << m1->refcount() << endl;

  cout << "Now removing message m2" << endl;
  mq->remove(m2);
  printMessages(mq);

  cout << "Now removing message m4" << endl;
  mq->remove(m4);
  printMessages(mq);

  cout << "Size is now " << mq->size() << endl;

  printMessages(mq);

  delete mq;
  // messages will be erased when enqueued in mq!

}
开发者ID:fuxiang90,项目名称:fawkes,代码行数:63,代码来源:qa_interface_msgq.cpp


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