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


C++ FIFO::push方法代码示例

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


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

示例1: main

int main()
{
	FIFO stack;
	DataItem* arr[20] = {0};
	
	for(int i = 0; i < 20; i++)
		stack.push(arr[i] = new DataItem(i));

	for(int i = 0; i < 25; i++)
		cout << stack.pop() << endl;

	for(int i = 0; i < 20; i++)
		delete arr[i];

	return 0;
}
开发者ID:NazarDemchuck,项目名称:cpp-lessons,代码行数:16,代码来源:FIFO_main.cpp

示例2: main

int main() {

	ifstream printdata("printdata.txt"); //make a stream
	List<job> printQueue;//this queue is going to be used for FIFO processing

	//create a whole bunch of dummy variables to put in the list
	int eyeD, tstamp, numP;
	char auth;
	job temp;




	while (printdata >> eyeD) {
		//read in data
		temp.id = eyeD;
		printdata >> tstamp;
		temp.timestamp = tstamp;
		printdata >> auth;
		temp.user = auth;
		printdata >> numP;
		temp.pages = numP;
		printQueue.push_back(temp); // callthe lists pushback method to add it to the back of the FIFO queue.
	}

	//create a dummy front job
	job frontJob;
	frontJob = printQueue.pop_front(); //get the first element in the fifo queue.
	int clock = frontJob.timestamp;
	//begin FIFO processing
	FIFO<job> feefo; //create a fifo list type
	feefo.push(frontJob); //place it at the beginning of the queue
	int stoptime = 0;
	zachresults << "Processing and calculating FIFO queue." << endl;
	job printing; //printing will hold the current job that is printing
	//initialize all of our stats
	int minwait = 0, maxwait = 0, totalwait = 0, jobsprocessed = 0;
	double avgwait;

	bool busyPrinter = false; // the printer isn't busy, so tell the truth, you goon
	do {
		if (!busyPrinter) { //if the printer isn't busy, begin printing the next job in the fifo queue
			printing = feefo.pop(clock);
			zachresults << "Starting print id " << printing.id << " at " << clock << endl;
			stoptime = clock + printing.length();
			zachresults << "This job will end at " << stoptime << endl;
			zachresults << "This job waited " << printing.waittime << " seconds." << endl;
			if (printing.id != 165896) { //don't collect wait time stats on the first print job. it doesn't wait.
				if(minwait == 0)	{
					minwait = printing.waittime;
					maxwait = printing.waittime;
					jobsprocessed++;
					totalwait += printing.waittime;
					avgwait = totalwait / jobsprocessed;
				}
				else {
					totalwait += printing.waittime;
					avgwait = totalwait / jobsprocessed;
				}
				if (printing.waittime < minwait) {
					minwait = printing.waittime;
				}
				if (printing.waittime > maxwait) {
					maxwait = printing.waittime;
				}
				
			}
			busyPrinter = true; //the printer is now busy
		}
		if (!printQueue.is_empty()) { //as long as we're still pulling jobs off the queue as they arrive, run this block of code
			frontJob = printQueue.pop_front(); //get the next job and put it in our frontjob variable
			while (busyPrinter && clock < frontJob.timestamp) { //while the printr is busy and the next job hasn't arrived yet, increment the clock
				clock++;
				if (clock == frontJob.timestamp) { //add a job to the queue once our clock hits its timestamp
					feefo.push(frontJob);
					zachresults << "Job " << frontJob.id << " arrived at " << clock << endl;
				}
				if (stoptime == clock) { //the print job is done once this stoptime is satisfied
					busyPrinter = false;
				}
			}
		}
		else {
			while (busyPrinter) {//run this once all of the jobs from printdata.txt are in our queue
				clock++;
				if (stoptime == clock) {
					busyPrinter = false;
				}
			}
		}
	} while (!feefo.isempty()); //bail once all of our jobs are done

	zachresults << "The minimum wait time was " << minwait << " seconds." << endl;
	zachresults << "The maximum wait time was " << maxwait << " seconds." << endl;
	zachresults << "The average wait time was " << avgwait << " seconds" << endl;
	zachresults << "The total wait time was " << totalwait << " seconds." << endl;
	//tidy everything up before we move on to SJF
	printdata.close();
	feefo.clear();
	printQueue.clear();
//.........这里部分代码省略.........
开发者ID:zfleeman,项目名称:program7,代码行数:101,代码来源:main.cpp

示例3: update

		//-----------------------------------------------------------------//
		void update()
		{
			gui::widget_director& wd = director_.at().widget_director_;

			// シリアルポートの更新
			if(serial_list_.empty() || !serial_.compare(serial_list_)) {
				serial_.create_list();
				serial_list_ = serial_.get_list();
				utils::strings list;
				for(const auto& t : serial_list_) {
					list.push_back(t.port);
					terminal_core_->output(t.port + " (" + t.info + ")\n");
				}
				ports_->get_menu()->build(list);
				ports_->select(0);
			}

			// RAWデータの取得と変換
			if(serial_.probe()) {
				char tmp[256];
				auto len = serial_.read(tmp, sizeof(tmp));
				for(uint32_t i = 0; i < len; ++i) {
					fifo_.push(tmp[i]);
				}
			}

			while(1)  {
				auto line = get_line_();
				if(line.empty()) {
					break;
				}
				int x, y, z;
				if((utils::input("%d,%d,%d", line.c_str()) % x % y % z).num() == 3) {
					raw_.x = x;
					raw_.y = y;
					raw_.z = z;
//					char tmp[256];
//					utils::sformat("%d, %d, %d\n", tmp, sizeof(tmp)) % x % y % z;
//					terminal_core_->output(tmp);
					if(ref_count_ > 0) {  // キャリブレーション
						if(ref_min_.x > raw_.x) ref_min_.x = raw_.x;
						if(ref_max_.x < raw_.x) ref_max_.x = raw_.x;
						if(ref_min_.y > raw_.y) ref_min_.y = raw_.y;
						if(ref_max_.y < raw_.y) ref_max_.y = raw_.y;
						if(ref_min_.z > raw_.z) ref_min_.z = raw_.z;
						if(ref_max_.z < raw_.z) ref_max_.z = raw_.z;
						--ref_count_;
						if(ref_count_ == 0) {
							gv_.set(0.0f);
						}
					} else {
						vtx::ivtx d(0);
						if(ref_min_.x > raw_.x || ref_max_.x < raw_.x) d.x = raw_.x;
						if(ref_min_.y > raw_.y || ref_max_.y < raw_.y) d.y = raw_.y;
						if(ref_min_.z > raw_.z || ref_max_.z < raw_.z) d.z = raw_.z;
						float g = 0.07f;
						gv_.x += static_cast<float>(d.x) * g;
						gv_.y += static_cast<float>(d.y) * g;
						gv_.z += static_cast<float>(d.z) * g;
					}
				} else {
					std::string s = "NG: ";
					s += line;
					terminal_core_->output(s);
				}
			}

			if(serial_.probe()) {
				++count_;
				if(count_ >= 30) {
					count_ = 0;
					char tmp[256];
					utils::sformat("%3.2f, %3.2f, %3.2f\n", tmp, sizeof(tmp))
						% gv_.x % gv_.y % gv_.z;
					terminal_core_->output(tmp);				
				}
			}

			if(!wd.update()) {
				camera_.update();
			}
		}
开发者ID:hirakuni45,项目名称:glfw3_app,代码行数:83,代码来源:cnc_main.hpp


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