'Operations Dev > Testing Timer' 카테고리의 다른 글
TestingSTL (0) | 2010.12.10 |
---|---|
TestProcessStateModel (0) | 2010.12.10 |
TwoStatemodel (0) | 2010.12.10 |
TestingSTL (0) | 2010.12.10 |
---|---|
TestProcessStateModel (0) | 2010.12.10 |
TwoStatemodel (0) | 2010.12.10 |
// TestingSTL.cpp : 콘솔 응용 프로그램에 대한 진입점을 정의합니다.
// 구조체는 디폴트는 public 클래스는 프라이빗, 구조체는 자료형의 집합, 클래스는 자료형과 그것을 사용하는 멤버함수의 집합
#include "stdafx.h"
#include <iostream>
#include <vector>
#include <list>
#include <map>
#include <algorithm>
using namespace std;
class TestClass
{
public:
TestClass(int x)
:_x( x )
{
}
TestClass(TestClass const & rhs)//클래스의 인스턴스가 생성될때 호출된다.
:_x(rhs._x)
{
}
TestClass operator+(TestClass const & rhs) //TestClass를 리턴하는 이유는 z= x+y일때 =연산자도 오버로딩을 해야하기때문에
{
//return this->_x + rhs._x;
return TestClass(_x + rhs._x);
}
TestClass & operator=(TestClass const & rhs) //TestClass를 리턴하는 이유는 z= x+y일때 =연산자도 오버로딩을 해야하기때문에
{//primitive 타입을 제외하고는 사칙연산및 비교연산은 불가능함, 단 연산자 재정의 가능함
this->_x = rhs._x;
return *this;
}
template<typename E, typename U>
friend std::basic_ostream<E, U>& operator<<(std::basic_ostream<E, U>& os, TestClass const & rhs)
{
os << L"(" << rhs._x<< L")";
return os;
}
bool operator==( TestClass const & rhs) const
{
return _x == rhs._x;
}
bool operator!=( TestClass const & rhs) const
{
return _x != rhs._x;
}
private:
int _x;
};
template <typename Type>
Type sum( Type t1, Type t2)
{
return t1+t2;
}
int _tmain(int argc, _TCHAR* argv[])
{
vector< int > intVector;
for( int i =0; i < 100; ++i)
{
intVector.push_back( i );
}
//wcout<<intVector.size()<<endl; //벡터에서 차례대로 하나씩 꺼내서 출력!
//wcout<<intVector[50]<<endl;
//intVector[50]=99999;
//wcout<<intVector[50];
//for ( int i = 0; i < intVector.size(); ++i )
//{
// wcout<<intVector[i]<<endl;
//}
//vector< int >::iterator iter;
//for( iter = intVector.begin();
// iter != intVector.end();
// ++iter)
//{
// cout<<(*iter)<<endl;
//};
//
vector< int >::iterator iter;
//iter = find( intVector.begin(), // 찾아서 포인터로 전달한다.
// intVector.end(),
// 10);
//intVector.erase(iter); // 포인터로 아예 삭제
//cout<<endl<<intVector.size()<<endl;
//for(iter = intVector.begin(); iter != intVector.end(); iter++) // 출력해보면 오류없이 중간만 빠져서 출력된다.
// cout<< (*iter) <<endl;
//cout<< intVector.size() <<endl;
// iter = find( intVector.begin(),
// intVector.end(),
// 70);
//intVector.insert(iter, 9999); // 찾은 위치에 새로운값넣기
//cout<<intVector[70]<<endl;
//iter = find( intVector.begin(),
//intVector.end(),
//70);
//if(iter == intVector.end()) // 포인터가 벡터의 끝이면 출력
//{
// cout<< "END" <<endl;
//}
//for_each( intVector.begin(), // foreach사용하여 출력
// intVector.end(),
// [](int element)
//{
// wcout<<element<<endl;
//});
//
TestClass t1(5), t2(2);
TestClass t3(3);
//TestClass t3= t1 + t2;
cout<<sum<TestClass>(t1, t2)<<endl;
cout<<sum< int >(5, 10)<<endl;
cout<<sum<double>(1.0, 2.5)<<endl;
return 0;
}
Timer 파일들 (0) | 2010.12.10 |
---|---|
TestProcessStateModel (0) | 2010.12.10 |
TwoStatemodel (0) | 2010.12.10 |
// 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;
}
Timer 파일들 (0) | 2010.12.10 |
---|---|
TestingSTL (0) | 2010.12.10 |
TwoStatemodel (0) | 2010.12.10 |
// No2_TestingFiveStateModel.cpp : 콘솔 응용 프로그램에 대한 진입점을 정의합니다.
//
#include "stdafx.h"
#include <Windows.h>
#include <iostream>
using namespace std;
#include "Timer\Timer.h"
int _tmain(int argc, _TCHAR* argv[])
{
Timer timer;
//timer.start(); // 슬립으로 준비와 수행 왔다갔다하기
//while(10>timer.elapsedSeconds());
//cout<<"Time Over"<<endl;
//timer.stop();
//::Sleep( 10000 );
//cout<<"Timer Over"<<endl;
//while(true) // 수행! 점유하여 키입력을 수행
//{
// if(::GetAsyncKeyState(VkKeyScan('x')))
// {
// break;
// }
//}
//
while(true) // 블록상태 보기
{
char key;
cin>>key;
if(key == 'x')
{
break;
}
}
return 0;
}
Timer 파일들 (0) | 2010.12.10 |
---|---|
TestingSTL (0) | 2010.12.10 |
TestProcessStateModel (0) | 2010.12.10 |