-
TestProcessStateModelOperations Dev/Testing Timer 2010. 12. 10. 16:49
// No3_TestTwoStateModel.cpp : 콘솔 응용 프로그램에 대한 진입점을 정의합니다.
//
#include "stdafx.h"
#include <queue>
#include <string>
#include <iostream>
using namespace std;
#include "Timer\Timer.h"
#include "Process.h"int const INTERLEAVING_TIME = 2000;
int _tmain(int argc, _TCHAR* argv[])
{
queue< Process > shortermQueue;
shortermQueue.push(Process( L"AAAAAAAA", 10));
shortermQueue.push(Process( L"BBBBBBBB", 5));
shortermQueue.push(Process( L"CCCCCCCC", 9));Timer interleavingTimer;
while( !shortermQueue.empty())
{
wcout << L"**********************************interleaving******************************"<<endl;
Process currentProcess = shortermQueue.front();
shortermQueue.pop();
bool isFinished = false;interleavingTimer.start();
while( interleavingTimer.elapsedMilliseconds() < INTERLEAVING_TIME)
{
wcout << L"Execute" << currentProcess.getName()
<<endl;
wcout << L"Result" << currentProcess.getCount()
<<endl;
if(!currentProcess.excute())
{
wcout<<L"Discard"<< currentProcess.getName()
<<endl;
isFinished = true;
break;
}
}
interleavingTimer.stop();if(!isFinished)
{
wcout<<L"Push "<<currentProcess.getName()
<<L" to a queue"
<<endl;
shortermQueue.push(currentProcess);}
wcout << L"********************************************************************"<<endl<<endl;}
return 0;
}--- Process.cpp
#include "stdafx.h"#include "Process.h"
Process::Process(std::wstring const & processName,
int startingCount)
:name(processName),
count(startingCount)
{}
Process::Process(Process const & rhs):name(rhs.name), count(rhs.count)
{
}bool Process::excute()
{
bool result = false;
--count;if( 0 < count)
{
result = true;
}timer.start();
while(timer.elapsedMilliseconds() < 2000);
timer.stop();return result;
}
---Process.h
#pragma once#include <string>
#include "Timer\Timer.h"
class Process
{
public:
Process(std::wstring const & processName,
int startingCount );
Process( Process const & rhs);public:
bool excute();
public:
Process &
operator=( Process const & rhs);public :
std::wstring const &
getName();
int
getCount();private:
std::wstring name;
int count;
Timer timer;
};inline Process &
Process::operator=( Process const & rhs)
{
name = rhs.name;
count = rhs.count;
}inline std::wstring const &
Process::getName()
{
return name;
}inline int Process::getCount()
{
return count;
}
'Operations Dev > Testing Timer' 카테고리의 다른 글
Timer 파일들 (0) 2010.12.10 TestingSTL (0) 2010.12.10 TwoStatemodel (0) 2010.12.10