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