Example #1
0
int main()
{
  StopWatch myWatch;
  myWatch.initiate();
  std::cout << myWatch.ElapsedTime() << "\n";
  myWatch.process_event( EvStartStop() );
  std::cout << myWatch.ElapsedTime() << "\n";
  myWatch.process_event( EvStartStop() );
  std::cout << myWatch.ElapsedTime() << "\n";
  myWatch.process_event( EvStartStop() );
  std::cout << myWatch.ElapsedTime() << "\n";
  myWatch.process_event( EvReset() );
  std::cout << myWatch.ElapsedTime() << "\n";


  return 0;
}
Example #2
0
int main()
{
	std::cout << "Boost.Statechart StopWatch example\n\n";
	std::cout << "s<CR>: Starts/Stops stop watch\n";
	std::cout << "r<CR>: Resets stop watch\n";
	std::cout << "d<CR>: Displays the elapsed time in seconds\n";
	std::cout << "e<CR>: Exits the program\n\n";
	std::cout << "You may chain commands, e.g. rs<CR> resets and starts stop watch\n\n";

	StopWatch stopWatch;
	stopWatch.initiate();

	char key = GetKey();

	while ( key != 'e' )
	{
		switch( key )
		{
			case 'r':
				{
					stopWatch.process_event( EvReset() );
				}
				break;

			case 's':
				{
					stopWatch.process_event( EvStartStop() );
				}
				break;

			case 'd':
				{
					double elapsedTime = 0.0;
					stopWatch.process_event( EvGetElapsedTime( elapsedTime ) );
					std::cout << "Elapsed time: " << elapsedTime << "\n";
				}
				break;

			default:
				{
					std::cout << "Invalid key!\n";
				}
				break;
		}

		key = GetKey();
	}

	return 0;
}