本文整理汇总了C++中queue::dequeue方法的典型用法代码示例。如果您正苦于以下问题:C++ queue::dequeue方法的具体用法?C++ queue::dequeue怎么用?C++ queue::dequeue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类queue
的用法示例。
在下文中一共展示了queue::dequeue方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: filter
void filter( queue<message> &in, queue<filtered_message> &out) {
while (true) {
try {
message msg = in.dequeue();
filtered_message filt_msg = filtered_message();
string filtered_text = msg.text;
for (size_t i=0; i < ( sizeof(words)/sizeof(words[0])); i++) {
size_t index = 0;
while (true) {
index = filtered_text.find(words[i], index);
if (index == std::string::npos) {
break;
}
filt_msg.ok = false;
filtered_text.replace( index, words[i].size(), string(words[i].size(), '*') );
}
}
filt_msg.text = filtered_text;
out.enqueue(filt_msg);
}
catch (queue_empty_exception) {
break;
}
}
}
示例2: while
/* return a pointer to three plateauType structures, starting at
location i,j. caller should check valid field in returned
structs. */
nodataType *
detectEdgeNodata::getNodataForward(dimension_type i, dimension_type j,
dimension_type nr, dimension_type nc) {
bool ok;
static nodataType ptarr[3]; /* return value */
nodataType pt;
ok = nodataQueue->peek(0, &pt);
while(ok && (pt.i < i || (pt.i==i && pt.j<j))) {
nodataQueue->dequeue(&pt); /* past needing this, so remove */
ok = nodataQueue->peek(0, &pt);
}
if(ok && pt.i == i && pt.j == j) {
nodataQueue->dequeue(&pt); /* found it, so remove */
ptarr[0] = pt;
} else {
ptarr[0].invalidate();
}
/* locate next two, if possible */
for(int kk=0,k=1; k<3; k++) {
ok = nodataQueue->peek(kk, &pt);
if(ok && pt.i == i && pt.j == j+k) {
ptarr[k] = pt;
kk++; /* found something, so need to peek further forward */
} else {
ptarr[k].invalidate();
}
}
#if(0)
cout << "request at " << i << "," << j << " returns: " <<
ptarr[0] << ptarr[1] << ptarr[2] << endl;
nodataQueue->peek(0, &pt);
cout << "queue length = " << nodataQueue->length()
<< "; head=" << pt << endl;
#endif
return ptarr;
}
示例3: prime
// Fill the staging area with a minimal chunk of input ranges.
int mergestream::prime()
{
if (dbg & 4)
printf("#entering mergestream::prime()\n");
if (!empty())
return 1;
int brkok = 1; // is it OK to break after the last
// VBOX that was added to the stage?
int needheight = -1; // minimum acceptable height of the
// chunk being constructed on stage
// If the range at the head of any queue is breaking,
// deal with it first.
if (squeue.more() && squeue.current()->breaking())
enqueue(squeue.dequeue());
else if (bfqueue.more() && (bfqueue.current()->breaking() ||
(bfqueue.serialno() < squeue.serialno())))
enqueue(bfqueue.dequeue());
else if (ufqueue.more() && (ufqueue.current()->breaking() ||
(ufqueue.serialno() < squeue.serialno())))
enqueue(ufqueue.dequeue());
else while (squeue.more()) {
// Fill the stage with enough ranges to be a valid chunk.
range *r = squeue.dequeue();
if (r->isvbox()) { // VBOX
if (dbg & 16)
printf("#VBOX: !empty: %d; brkok: %d; vsince: %d\n",
!empty(), brkok, currpage->vsince);
if (!empty() // there's something there
&& brkok
// it's OK to break here
&& currpage->vsince >= 2
// enough stream has gone onto this page
&& rawht() >= needheight
// current need has been satisfied
) {
// the stage already contains enough
// ranges, so this one can wait
r->enqueue();
break;
} else {
if (r->rawht() > 0) {
++currpage->vsince;
brkok = r->brkafter();
}
enqueue(r);
}
} else if (r->isnested() || r->issp()) { // US, SP
if (!empty() && rawht() >= needheight) {
// enough already, wait
r->enqueue();
break;
}
currpage->vsince = 0;
enqueue(r);
if (height() >= needheight)
break;
} else if (r->isneed()) { // NE
if (!empty() && rawht() >= needheight) {
// not currently working on an unsatisfied NEed
r->enqueue();
break;
}
// deal with overlapping NEeds
needheight = rawht() + max(needheight - rawht(), r->needht());
enqueue(r);
} else if (r->forceflush() == NO) {
enqueue(r);
} else if (r->forceflush() == YES) {
currpage->vsince = 0;
if (!empty()) {
// ready or not, r must wait
r->enqueue();
break;
}
enqueue(r);
break;
} else
ERROR "unexpected %s[%s] in prime(), line %d\n",
r->type_name(), r->headstr(), r->lineno() FATAL;
}
return more(); // 0 if nothing was staged
}
示例4: if
void *operators(void *threadid)
{
long tid;
tid = (long)threadid;
printf("Hello World! It's me, operator_thread #%ld!\n", tid);
queue require;
queue tools;
while(true)//for (int i=0; i<10; i++)//change to while(true)
{
pthread_mutex_lock(&mutex_pause);
while (isPaused == 1)
{
pthread_cond_wait(&cond_pause, &mutex_pause);
}
//else
//{
pthread_mutex_unlock(&mutex_pause);
int rand_time=rand() % 10000;
usleep(rand_time);
pthread_mutex_lock(&M);//lock mutex
//critical section
if (fix_buffer.size()==0)
{
cout<<"Empty"<<endl;
dead_count++;
cout<<"Deadlock due to Empty!!!"<<endl;
cout<<"Number of deadlock happened is "<<dead_count<<endl;
}
while(fix_buffer.size()==0)//wait if fixed size buffer is 0
if (pthread_cond_wait (&C1, &M))
{
fprintf (stdout, "pthread_cond_wait: consumer\n");
exit (-1);
}
if (require.size()==0)//get 1st material
{
int temp=fix_buffer.dequeue();
pthread_cond_signal (&C);
require.enqueue(temp);
cout<<"get "<<temp<<"by "<<tid<<endl;
cout<<"require: "<<endl;
require.show();
}
else if (require.size()==1)//get 2nd material
{
int temp1=fix_buffer.dequeue();
pthread_cond_signal(&C);
if (temp1 != require.front())
{
require.enqueue(temp1);
cout<<"get "<<temp1<<"by "<<tid<<endl;
cout<<"require: "<<endl;
require.show();
int check_product=require.check_p();
if (output_Q.size()==0) //starting queue no need to check for previous product
{
int random_tool1;
int random_tool2;
if(pthread_mutex_trylock(&M1)==0)
{
while(tools.size()<2)
{
if (tools.size()==0)
{
random_tool1=rand() % tool_num + 1;
tools.enqueue(random_tool1);
cout<<"get tools"<<random_tool1<<" by operator "<<tid<<endl;
tools.show();
}
else if (tools.size()==1)
{
random_tool1=rand() % tool_num + 1;
if (!(random_tool1==random_tool2))
{
tools.enqueue(random_tool1);
cout<<"get tools"<<random_tool1<<" by operator "<<tid<<endl;
tools.show();
}
}
}
}
int product=require.dequeue();
product=product+require.dequeue();
output_Q.enqueue(product);
cout<<"output_Q: "<<endl;
output_Q.show();
//.........这里部分代码省略.........