File: test.cpp

package info (click to toggle)
mrpt 1%3A2.5.8%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 87,448 kB
  • sloc: cpp: 551,662; ansic: 38,702; xml: 3,914; python: 2,547; sh: 404; makefile: 237
file content (52 lines) | stat: -rw-r--r-- 1,412 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/* +------------------------------------------------------------------------+
   |                     Mobile Robot Programming Toolkit (MRPT)            |
   |                          https://www.mrpt.org/                         |
   |                                                                        |
   | Copyright (c) 2005-2023, Individual contributors, see AUTHORS file     |
   | See: https://www.mrpt.org/Authors - All rights reserved.               |
   | Released under BSD License. See: https://www.mrpt.org/License          |
   +------------------------------------------------------------------------+ */

/** \example system_progress_bar/test.cpp */

//! [example-system-progress-bar]

#include <mrpt/core/exceptions.h>
#include <mrpt/system/progress.h>

#include <chrono>
#include <iostream>
#include <thread>

void TestProgressBar()
{
	const int end = 400;
	const size_t barWidth = 30;

	for (int i = 0; i <= end; i++)
	{
		double p = double(i) / end;

		std::cout << "Progress: " << mrpt::system::progress(p, barWidth)
				  << mrpt::format(" %5.02f%%", 100 * p) << "\r";
		std::cout.flush();
		std::this_thread::sleep_for(std::chrono::milliseconds(5));
	}
	std::cout << std::endl;
}

//! [example-system-progress-bar]

int main()
{
	try
	{
		TestProgressBar();
		return 0;
	}
	catch (const std::exception& e)
	{
		std::cerr << mrpt::exception_to_str(e) << std::endl;
		return -1;
	}
}